private static void GetMinCards(int[] max, List <Karta> zw) { for (int i = 0; i < zw.Count; i++) { Karta car = zw[i]; BasicTools.SetMin(ref max[(int)car.Kolor()], (int)car); } }
/// <inheritdoc/> public override Equator GetEquatorCoordinate(DateTime time, bool isApparent = false) { double T = (Julian.ToJulianDay(time) - 2451545.0) / 36525.0; double L0 = 280.46645 + 36000.76983 * T + 0.0003030 * T * T; double M = 357.52910 + 35999.05030 * T - 0.0001559 * T * T - 0.00000048 * T * T * T; double e = 0.016708617 - 0.000042037 * T - 0.0000001236 * T * T; L0 = BasicTools.SimplifyAngle(L0); M = BasicTools.SimplifyAngle(M); e = BasicTools.SimplifyAngle(e); double C = Math.Abs((1.914600 - 0.004817 * T - 0.000014 * T * T)) * Math.Sin(M * (Math.PI / 180.0)) + (0.019993 - 0.000101 * T) * Math.Sin(2 * M * (Math.PI / 180.0)) + 0.000290 * Math.Sin(3 * M * (Math.PI / 180.0)); C = BasicTools.SimplifyAngle(C); double theta = L0 + C; double theta2000 = theta - 0.01397 * (time.Year - 2000); double omega = 125.04 - 1934.136 * T; omega = BasicTools.SimplifyAngle(omega); double lambda = theta - 0.00569 - 0.00478 * Math.Sin(omega * (Math.PI / 180.0)); double sinDelta, delta, alpha; if (isApparent) { sinDelta = Math.Sin((CoordinateSystem.GetEclipticObliquity(time, false) + 0.00256 * Math.Cos(omega) * (Math.PI / 180.0)) * (Math.PI / 180.0)) * Math.Sin(lambda * (Math.PI / 180.0)); delta = Math.Asin(sinDelta) * (180.0 / Math.PI); alpha = Math.Atan2(Math.Cos((CoordinateSystem.GetEclipticObliquity(time, false) + 0.00256 * Math.Cos(omega) * (Math.PI / 180.0)) * (Math.PI / 180.0)) * Math.Sin(lambda * (Math.PI / 180.0)), Math.Cos(lambda * (Math.PI / 180.0))) * (180.0 / Math.PI); } else { sinDelta = Math.Sin(CoordinateSystem.GetEclipticObliquity(time, false) * (Math.PI / 180.0)) * Math.Sin(theta2000 * (Math.PI / 180.0)); delta = Math.Asin(sinDelta) * (180.0 / Math.PI); alpha = Math.Atan2(Math.Cos(CoordinateSystem.GetEclipticObliquity(time, false) * (Math.PI / 180.0)) * Math.Sin(theta2000 * (Math.PI / 180.0)), Math.Cos(theta2000 * (Math.PI / 180.0))) * (180.0 / Math.PI); } if (alpha <= 0) { while (!(alpha >= 0 && alpha <= 360)) { alpha += 360; } } Equator c = new Equator { RA = alpha, Dec = delta }; return(c); }
public List <Karta> GetValidCards(List <Karta> ls, StateGame1000 s) { int[] max = BasicTools.InitializeTable(4, ValueIfCardsDontExist); List <Karta> zw = new List <Karta>(ls.Count); GetMinCards(max, ls); zw.AddRange(IntToCard(max)); return(zw); }
public static int[] GetHightCards(IEnumerable <Karta> cards) { int[] zw = BasicTools.InitializeTable <int>(4, -1); foreach (var item in cards) { int IndexColor = (int)item.Kolor(); BasicTools.SetMax(ref zw[IndexColor], (int)item); } return(zw); }
static void Main(string[] args) { #region db //try //{ Console.WriteLine(Serialization.Load <Person>(Directory.GetCurrentDirectory() + @"\People.db", "unknown")); Console.WriteLine(Serialization.Load <Person>(Directory.GetCurrentDirectory() + @"\People.db", "Sarah Jones")); try { Console.WriteLine(Serialization.Load <Person>(Directory.GetCurrentDirectory() + @"\People.db", "stupid")); } catch (Exception ex) { BasicTools.LogErr(ex); } //} //catch (Exception) { } // Call the constructor that has no parameters. var person1 = new Person(); Serialization.Save(person1, Directory.GetCurrentDirectory() + @"\People.db", person1.Name); Console.WriteLine(person1.Name); // Call the constructor that has one parameter. var person2 = new Person("Sarah Jones"); Serialization.Save(person2, Directory.GetCurrentDirectory() + @"\people.db", person2.Name); Console.WriteLine(person2.Name); // Get the string representation of the person2 instance. Console.WriteLine(person2); string[] tmp = BasicTools.StrSplit("11001001001101100101", 8); Console.WriteLine($"[{tmp[0]}, {tmp[1]}, {tmp[2]}]"); //Console.WriteLine(BasicTools.StrSplit("11001001001101100101", 8)); Console.WriteLine("Press any key to exit."); Console.ReadKey(); //try //{ // Compression.Compress("test.txt", "test_OpenG32.txt", Compression.CompressionTypes.OpenG32); //} //catch (Exception) //{ // Console.WriteLine("Not yet existant."); //} #endregion }
/// <inheritdoc/> public override double GetToEarthDistance(DateTime time) { double T = (Julian.ToJulianDay(time) - 2451545.0) / 36525.0; double M = 357.52910 + 35999.05030 * T - 0.0001559 * T * T - 0.00000048 * T * T * T; double e = 0.016708617 - 0.000042037 * T - 0.0000001236 * T * T; M = BasicTools.SimplifyAngle(M); e = BasicTools.SimplifyAngle(e); double C = Math.Abs((1.914600 - 0.004817 * T - 0.000014 * T * T)) * Math.Sin(M * (Math.PI / 180.0)) + (0.019993 - 0.000101 * T) * Math.Sin(2 * M * (Math.PI / 180.0)) + 0.000290 * Math.Sin(3 * M * (Math.PI / 180.0)); C = BasicTools.SimplifyAngle(C); double v = M + C; v = BasicTools.SimplifyAngle(v); double distance = 1.0000011018 * (1 - e * e) / (1 + e * Math.Cos(v * (Math.PI / 180.0))); return(distance); }
private void btnSubmit_Click(object sender, EventArgs e) { Customer c = new Customer(); c.FName = txtFName.Text; c.MName = txtMName.Text; c.LName = txtLName.Text; c.StreetOne = txtStreetOne.Text; c.StreetTwo = txtStreetTwo.Text; c.City = txtCity.Text; c.StateCode = txtStateCode.Text; c.ZipCode = txtZipCode.Text; c.PhoneNum = txtPhoneNum.Text; c.EmailAddress = txtEmailAddress.Text; //New c.CellNum = txtCellPhoneNum.Text; c.InstagramURL = txtInstagramURL.Text; //Part 3 c.CustomerSince = txtDateTime.Value; c.DiscountMember = checkBoxDiscountMember.Checked; //Ensuring correct data types if (BasicTools.isValidDouble(txtTotalPurchases.Text)) { double temp; Double.TryParse(txtTotalPurchases.Text, out temp); c.TotalPurchases = temp; } else { c.Feedback += "\n Error: Total Purchases not double"; c.TotalPurchases = 1; } if (BasicTools.isValidInt(txtRewardsEarned.Text)) { int temp; Int32.TryParse(txtRewardsEarned.Text, out temp); c.RewardsEarned = temp; } else { c.Feedback += "\n Error: Rewards Earned not int"; c.RewardsEarned = 0; } //This code vastly shortened by moving error feedback to object if (c.Feedback.Contains("Error")) { lblErrorMsg.Text = c.Feedback; c.Feedback = ""; } //Successful submission code else { lblErrorMsg.Text = "Input Errors: NONE"; txtFName.Text = ""; txtMName.Text = ""; txtLName.Text = ""; txtStreetOne.Text = ""; txtStreetTwo.Text = ""; txtCity.Text = ""; txtStateCode.Text = ""; txtZipCode.Text = ""; txtPhoneNum.Text = ""; txtEmailAddress.Text = ""; txtCellPhoneNum.Text = ""; txtInstagramURL.Text = ""; checkBoxDiscountMember.Checked = false; txtRewardsEarned.Text = ""; txtTotalPurchases.Text = ""; setFeedbackVCust(c); people.Add(c); } }
public uint Dimmer(int brightness, byte voxel) { return(Values[voxel % Count][BasicTools.Clamp(brightness, 0, 3)]); }
public Colorizer(uint[] palette) { Count = palette.Length; Reducer = new PaletteReducer(palette); Primary = new byte[] { Reducer.ReduceIndex(0xFF0000FF), Reducer.ReduceIndex(0xFFFF00FF), Reducer.ReduceIndex(0x00FF00FF), Reducer.ReduceIndex(0x00FFFFFF), Reducer.ReduceIndex(0x0000FFFF), Reducer.ReduceIndex(0xFF00FFFF) }; Grays = new byte[] { Reducer.ReduceIndex(0xFF000000), Reducer.ReduceIndex(0xFF444444), Reducer.ReduceIndex(0xFF888888), Reducer.ReduceIndex(0xFFCCCCCC), Reducer.ReduceIndex(0xFFFFFFFF) }; //int THRESHOLD = 64;//0.011; // threshold controls the "stark-ness" of color changes; must not be negative. byte[] paletteMapping = new byte[1 << 16]; uint[] reverse = new uint[Count]; Ramps = BasicTools.Fill((byte)0, Count, 4); Values = BasicTools.Fill(0u, Count, 4); uint[] lumas = new uint[Count], cws = new uint[Count], cms = new uint[Count]; uint yLim = 63, cwLim = 31, cmLim = 31; int shift1 = 6, shift2 = 11; uint color; int r, g, b; int cw, cm; for (int i = 1; i < Count; i++) { color = palette[i]; if ((color & 0x80000000) == 0) { color |= 0xFF000000; } r = (int)(color & 0xFF); g = (int)(color >> 8 & 0xFF); b = (int)(color >> 16 & 0xFF); cw = r - b; cm = g - b; paletteMapping[ reverse[i] = (lumas[i] = (uint)(r * 3 + g * 4 + b) >> 5) | (cws[i] = (uint)cw + 255 >> 4) << shift1 | (cms[i] = (uint)cm + 255 >> 4) << shift2] = (byte)i; } for (int icm = 0; icm <= cmLim; icm++) { for (int icw = 0; icw <= cwLim; icw++) { for (int iy = 0; iy <= yLim; iy++) { int c2 = icm << shift2 | icw << shift1 | iy; if (paletteMapping[c2] == 0) { double dist = double.PositiveInfinity; for (int i = 1; i < Count; i++) { if (Math.Abs(lumas[i] - (int)iy) < 28 && dist > (dist = Math.Min(dist, DifferenceWarmMild((int)lumas[i], (int)cws[i], (int)cms[i], iy, icw, icm)))) { paletteMapping[c2] = (byte)i; } } } } } } //float adj; float cwf, cmf; //int idx2; for (int i = 1; i < Count; i++) { uint rev = reverse[i]; int y = (int)(rev & yLim), match = i, yBright = y * 9 / 2, yDim = y * 3, yDark = y, luma, warm, mild; cwf = (cw = (int)cws[i] - 16) / 30f; cmf = (cm = (int)cms[i] - 16) / 30f; //Console.WriteLine("i={0:D3}: y={1:D3}, cw={2:D3}, cm={3:D3}", i, y, cw, cm); //values[i][0] = values[i][1] = values[i][3] = Values[i][2] = palette[i]; luma = yDim; //warm = ((cw * 395 + 31) / 32 - 192) / 16; //mild = ((cm * 395 + 31) / 32 - 192) / 16; warm = cw * 5 / 3; mild = cm * 5 / 3; r = (luma + warm * 5 - mild * 4); g = (luma - warm * 3 + mild * 4); b = (luma - warm * 3 - mild * 4); Values[i][1] = (uint)( BasicTools.Clamp(r, 0, 255) | BasicTools.Clamp(g, 0, 255) << 8 | BasicTools.Clamp(b, 0, 255) << 16) | 0xFF000000U; luma = yBright; //warm = ((cw * 333 + 31) / 32 - 162) / 16; //mild = ((cm * 333 + 31) / 32 - 162) / 16; warm = cw * 5 / 3; mild = cm * 5 / 3; r = (luma + warm * 5 - mild * 4); g = (luma - warm * 3 + mild * 4); b = (luma - warm * 3 - mild * 4); Values[i][3] = (uint)( BasicTools.Clamp(r, 0, 255) | BasicTools.Clamp(g, 0, 255) << 8 | BasicTools.Clamp(b, 0, 255) << 16) | 0xFF000000U; luma = yDark; //warm = ((cw * 215) / 16 - 208) / 16; //mild = ((cm * 215) / 16 - 208) / 16; warm = cw * 3 / 2; mild = cm * 3 / 2; r = (luma + warm * 5 - mild * 4); g = (luma - warm * 3 + mild * 4); b = (luma - warm * 3 - mild * 4); Values[i][0] = (uint)( BasicTools.Clamp(r, 0, 255) | BasicTools.Clamp(g, 0, 255) << 8 | BasicTools.Clamp(b, 0, 255) << 16) | 0xFF000000U; //Console.WriteLine("{0:D}:{1:X8},{2:X8},{3:X8},{4:X8}", i, Values[i][0], Values[i][1], Values[i][2], Values[i][3]); //// This seems like a much simpler approach than the large comment below it. //// The downside is that in some small palettes, the lighter or darker variants may be the same as the original, or both //// darker variants could be the same. Ramps[i][0] = Reducer.ReduceIndex(Values[i][0]); Ramps[i][1] = Reducer.ReduceIndex(Values[i][1]); Ramps[i][2] = (byte)i; Ramps[i][3] = Reducer.ReduceIndex(Values[i][3]); //Ramps[i][2] = (byte)i; //Ramps[i][3] = Grays[4];//15; //0xFFFFFFFF, white //Ramps[i][1] = Grays[0];//0x010101FF, black //Ramps[i][0] = Grays[0];//0x010101FF, black //for (int yy = y + 2, rr = (int)rev + 2; yy <= yLim; yy++, rr++) //{ // if ((idx2 = paletteMapping[rr] & 255) != i && DifferenceWarmMild((int)lumas[idx2], (int)cws[idx2], (int)cms[idx2], y, cw, cm) > THRESHOLD) // { // Ramps[i][3] = paletteMapping[rr]; // break; // } // adj = 1f + ((yLim + 1) * 0.5f - yy) / 1024f; // cwf = BasicTools.Clamp(cwf * adj, -0.5f, 0.5f); // cmf = BasicTools.Clamp(cmf * adj, -0.5f, 0.5f); // rr = yy // | (cw = (int)((cwf + 0.5f) * cwLim)) << shift1 // | (cm = (int)((cmf + 0.5f) * cmLim)) << shift2; //} //cwf = ((cw = (int)cws[i]) - 16) * 11f / 32f; //cmf = ((cm = (int)cms[i]) - 16) * 11f / 32f; //for (int yy = y - 2, rr = (int)rev - 2; yy > 0; rr--) //{ // if ((idx2 = paletteMapping[rr] & 255) != i && DifferenceWarmMild((int)lumas[idx2], (int)cws[idx2], (int)cms[idx2], y, cw, cm) > THRESHOLD) // { // Ramps[i][1] = paletteMapping[rr]; // rev = (uint)rr; // y = yy; // match = paletteMapping[rr] & 255; // break; // } // adj = 1f + (yy - (yLim + 1) * 0.5f) / 1024f; // cwf = BasicTools.Clamp(cwf * adj, -0.5f, 0.5f); // cmf = BasicTools.Clamp(cmf * adj, -0.5f, 0.5f); // rr = yy // | (cw = (int)((cwf + 0.5f) * cwLim)) << shift1 // | (cm = (int)((cmf + 0.5f) * cmLim)) << shift2; // if (--yy == 0) // { // match = -1; // } //} //if (match >= 0) //{ // cwf = ((cw = (int)cws[match]) - 16) / 30f; // cmf = ((cm = (int)cms[match]) - 16) / 30f; // for (int yy = y - 3, rr = (int)rev - 3; yy > 0; yy--, rr--) // { // if ((idx2 = paletteMapping[rr] & 255) != match && DifferenceWarmMild((int)lumas[idx2], (int)cws[idx2], (int)cms[idx2], y, cw, cm) > THRESHOLD) // { // Ramps[i][0] = paletteMapping[rr]; // break; // } // adj = 1f + (yy - (yLim + 1) * 0.5f) / 1024f; // cwf = BasicTools.Clamp(cwf * adj, -0.5f, 0.5f); // cmf = BasicTools.Clamp(cmf * adj, -0.5f, 0.5f); // rr = yy // | (cw = (int)((cwf + 0.5f) * cwLim)) << shift1 // | (cm = (int)((cmf + 0.5f) * cmLim)) << shift2; // } //} } }
static void Main(string[] args) { bool blnResult = false; EBook temp = new EBook(); Console.Write("\nPlease enter the title: "); temp.Title = Console.ReadLine(); Console.Write("\nPlease enter the Author's First Name: "); temp.AuthorFirst = Console.ReadLine(); Console.Write("\nPlease enter the Author's Last Name: "); temp.AuthorLast = Console.ReadLine(); Console.Write("\nPlease enter the Author's Email: "); temp.Email = Console.ReadLine(); do { Console.Write("\nPlease enter the Date Published: "); DateTime dtTempDate; blnResult = DateTime.TryParse(Console.ReadLine(), out dtTempDate); if (blnResult == false) { Console.Write("\nSorry incorrect date format. Please try again. (Ex: 10/31/2000) "); } else { temp.DatePublished = dtTempDate; } } while (blnResult == false); do { Console.Write("\nPlease enter the # of pages: "); int intTempPages; blnResult = Int32.TryParse(Console.ReadLine(), out intTempPages); if (blnResult == false) { Console.Write("\nSorry incorrect page #. Please try again. (Ex: 214) "); } else { temp.Pages = intTempPages; } } while (blnResult == false); do { Console.Write("\nPlease enter the Cost of the book : $"); double dblTempPrice; blnResult = Double.TryParse(Console.ReadLine(), out dblTempPrice); if (blnResult == false) { Console.Write("\nSorry incorrect price. Please try again. (Ex: 19.50) "); } else { temp.Price = dblTempPrice; } } while (blnResult == false); //***************************************************************** //Set Rental Expiration to two weeks from today temp.DateRentalExpires = DateTime.Today.AddDays(14); //Get the page # to bookmark do { Console.Write("\nPlease enter the page # we want to bookmark: "); //Prompt for info int intTempBookMark; blnResult = Int32.TryParse(Console.ReadLine(), out intTempBookMark); //Get input and try to convert to Int if (blnResult == false) { Console.Write("\nSorry incorrect page #. Please try again. (Ex: 214) "); //if error, display error msg } else { temp.BookmarkPage = intTempBookMark; // else...set bookmark } } while (blnResult == false); //***************************************************************** //NEW...Look for Errors listed in Feedback...If none found, SAVE THE DATA IN DB if (!temp.Feedback.Contains("ERROR:")) { string strFeedback = temp.AddARecord(); //Attempt to add a record Console.WriteLine(strFeedback); //Display results of this attempt //Console.Write("\n\nWe now have the following book:"); //Console.Write($"\n Title: {temp.Title}"); //Console.Write($"\n Written by {temp.AuthorFirst} {temp.AuthorLast}"); //Console.Write($"\n Email: {temp.Email}"); //Console.Write($"\n Published: {temp.DatePublished.ToShortDateString()}"); //Console.Write($"\n Pages: {temp.Pages}"); //Console.Write($"\n Price: ${temp.Price}"); //Console.Write($"\n Return by: {temp.DateRentalExpires.ToShortDateString()}"); //Console.Write($"\n Last Page Read: {temp.BookmarkPage}"); } else { //Else...Display Error Messages Console.WriteLine(temp.Feedback); } BasicTools.Pause(); }