public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Address")] Lab lab) { if (id != lab.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(lab); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LabExists(lab.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(lab)); }
private Lab GetColorModeColor(uint i, uint j, IReadOnlyList <Lab> labs) { var total = 0u; var length = labs.Count; var colorHits = new uint[length]; for (var k = 0; k < length; k++) { colorHits[k] = _display[i, j, k]; total += colorHits[k]; } var mix = new Lab(); if (total == 0) { return(mix); } var coefficient = new double[length]; for (var k = 0; k < length; k++) { coefficient[k] = Algebra.Map(colorHits[k], 0.0, total, 0.0, 1.0); } for (var k = 0; k < length; k++) { mix.L += labs[k].L * coefficient[k]; mix.A += labs[k].A * coefficient[k]; mix.B += labs[k].B * coefficient[k]; } return(mix); }
// Converts LCh (lightness, chroma, hue) to Lab private static LCh OklabToLCh(Lab lab) { float C = (float)Math.Sqrt((lab.a * lab.a) + (lab.b * lab.b)); float h = (float)Math.Atan2(lab.b, lab.a); return(new LCh(lab.L, C, h)); }
public async Task <IActionResult> OnGetAsync(int?id, int?studentId) { if (id == null) { return(NotFound()); } //Show the LabEnrollments (Students) for the selected Lab. Lab = await _context.Lab .Include(c => c.LabEnrollments) .ThenInclude(s => s.Student) .AsNoTracking() .FirstOrDefaultAsync(m => m.LabID == id); if (Lab == null) { return(NotFound()); } //Remove the LabEnrollment from the database if (studentId != null) { LabEnrollment studentEnrollment = Lab.LabEnrollments.Where(x => x.LabID == id.Value && x.StudentID == studentId).First(); _context.LabEnrollment.Remove(studentEnrollment); await _context.SaveChangesAsync(); Response.Redirect("/Labs/Details/" + id.ToString()); } return(Page()); }
internal static Color InvertLightness(Color color) { // We unfortunately still need janky tuning of lightness and desaturation for good visibility, but // Oklab does give us a beautiful perceptual lightness scale (dark blue goes to light blue!) unlike // HSL, so awesome! Lab lab = ColorToOklab(color); #region Invert and global lightness boost float newL = lab.L < 0.5f ? ((1.0f - lab.L) + 0.10f).Clamp(0.0f, 1.0f) : (lab.L + 0.025f).Clamp(0.5f, 1.0f); lab = new Lab(newL, lab.a, lab.b); #endregion LCh lch = OklabToLCh(lab); #region Tweaks for specific hue ranges bool redDesaturated = false; switch (lch.h) { // Blue range case >= -1.901099f and <= -1.448842f: // Green range case >= 2.382358f and <= 2.880215f: lch = new LCh(lch.L.Clamp(0.7f, 1.0f), lch.C, lch.h); break; // Red range case >= -0.1025453f and <= 0.8673203f: lch = new LCh(lch.L.Clamp(0.6f, 1.0f), lch.C, lch.h); if (lch.L is >= 0.5f and <= 0.7f) { lch = new LCh(lch.L, (lch.C - 0.025f).Clamp(0, 1.0f), lch.h); redDesaturated = true; } break; } #endregion // Slight global desaturation lab = LChToOklab(new LCh(lch.L, (lch.C - (redDesaturated ? 0.015f : 0.04f)).Clamp(0, 1.0f), lch.h)); Color retColor = OklabToColor(lab); // For some reason RTF doesn't accept a \cfN if the color is 255 all around, it has to be 254 or // less... don't ask me if (retColor.R == 255 && retColor.G == 255 && retColor.B == 255) { retColor = Color.FromArgb(254, 254, 254); } return(retColor); }
public IActionResult Delete(Lab lab) { //TODO: Implement me context.Labs.Remove(lab); context.SaveChanges(); return(RedirectToAction(nameof(Index))); }
public void LabTest1() { for (int x = 0; x < 2; x++) { int lineNumber = 0; using (Lab lab = new Lab(x == 0 ? _legacySourcePath : _modernSourcePath)) { var labList = lab.LabList(); var lines = File.ReadLines(Path.Combine(Directory.GetCurrentDirectory(), "lab.csv")); foreach (var line in lines) { TextFieldParser parser = new TextFieldParser(new StringReader(line)); parser.HasFieldsEnclosedInQuotes = true; parser.SetDelimiters(","); string[] fields = parser.ReadFields(); if (!LabRecordCompare(labList, fields, lineNumber)) { Assert.Fail("Match failed on line: " + (lineNumber + 1).ToString()); } lineNumber++; } } } Assert.IsFalse(false, "LabTest1 Passed!!"); }
public async Task <IActionResult> CreateLabAsync(Lab labData) { // Check input if (!ModelState.IsValid) { AddStatusMessage(_localizer["CreateLabAsync:InvalidInput"], StatusMessageTypes.Error); return(await ShowCreateLabFormAsync(labData)); } try { // Create lab var lab = new Lab { Name = labData.Name, ApiCode = labData.ApiCode, ServerBaseUrl = labData.ServerBaseUrl, MaxPoints = labData.MaxPoints, MaxFlagPoints = labData.MaxFlagPoints }; await _labService.CreateLabAsync(lab, HttpContext.RequestAborted); AddStatusMessage(_localizer["CreateLabAsync:Success"], StatusMessageTypes.Success); } catch (InvalidOperationException ex) { _logger.LogError(ex, "Create lab"); AddStatusMessage(_localizer["CreateLabAsync:UnknownError"], StatusMessageTypes.Error); return(await ShowCreateLabFormAsync(labData)); } return(await RenderLabListAsync()); }
public IActionResult Edit(Lab lab) { //TODO: Implement me context.Update(lab); context.SaveChanges(); return(RedirectToAction(nameof(Index))); }
private void CreateLabLayout() { Hide4Elements(); Lab Lab_color = new Lab(current_color); label1.Text = "L"; label2.Text = "a"; label3.Text = "b"; setting_tb_and_nup = true; numericUpDown1.Maximum = 100; numericUpDown2.Maximum = 98; numericUpDown3.Maximum = 94; numericUpDown1.Minimum = 0; numericUpDown2.Minimum = -86; numericUpDown3.Minimum = -107; numericUpDown1.Increment = 1; numericUpDown2.Increment = 1; numericUpDown3.Increment = 1; trackBar1.Value = (int)(Lab_color.L / 100 * 255); trackBar2.Value = (int)((Lab_color.A + 86) / (98.0 + 86) * 255); trackBar3.Value = (int)((Lab_color.B + 107) / (107.0 + 94) * 255); numericUpDown1.Value = (decimal)Lab_color.L; numericUpDown2.Value = (decimal)Lab_color.A; numericUpDown3.Value = (decimal)Lab_color.B; setting_tb_and_nup = false; SetDecimalPlaces(2); SetLabLabels(); }
public static void savePrefs() { PlayerPrefs.SetInt("areasUnlocked.Length", GameCore.areasUnlocked.Length); for (int i = 0; i < GameCore.areasUnlocked.Length; i++) { PlayerPrefs.SetString("areasUnlocked" + i, GameCore.areasUnlocked[i].ToString()); } PlayerPrefs.SetInt("upgradesDone.Length", Research.upgradesDone.Length); for (int i = 0; i < Research.upgradesDone.Length; i++) { PlayerPrefs.SetString("upgradesDone" + i, Research.upgradesDone[i].ToString()); } PlayerPrefs.SetInt("buttonUnlocked.Length", Research.buttonUnlocked.Length); for (int i = 0; i < Research.buttonUnlocked.Length; i++) { PlayerPrefs.SetString("buttonUnlocked" + i, Research.buttonUnlocked[i].ToString()); } PlayerPrefs.SetString("storyStarted", GameCore.storyStarted.ToString()); PlayerPrefs.SetString("storyEnded", GameCore.storyEnded.ToString()); PlayerPrefs.SetString("money", GameCore.getRpMoney(1).ToString()); PlayerPrefs.SetString("rp", GameCore.getRpMoney(0).ToString()); PlayerPrefs.SetString("area", GameCore.getArea().ToString()); PlayerPrefs.SetFloat("energy", Lab.getEnergy(0)); PlayerPrefs.SetFloat("sensorEnergy", Lab.getEnergy(1)); PlayerPrefs.SetFloat("maxSpeedEnergy", Lab.getEnergy(2)); PlayerPrefs.SetFloat("accelEnergy", Lab.getEnergy(3)); PlayerPrefs.SetFloat("sideSpeedEnergy", Lab.getEnergy(4)); PlayerPrefs.SetString("area", GameCore.getArea().ToString()); PlayerPrefs.SetString("rpPerSec", Research.getRpPerSec().ToString()); PlayerPrefs.SetString("startMoneyTimer", GameCore.startMoneyTimer.ToString()); PlayerPrefs.SetString("averageMoneyPerSec", GameCore.averageMoneyPerSec.ToString()); PlayerPrefs.SetFloat("profitsMulti", GameCore.getProfitsMulti()); PlayerPrefs.Save(); }
public void SendXMLAsSerialization(Lab Lab, bool AutoReflect = true) { UseAutomaticReflection = AutoReflect; // Speed up processing if (StartSession(true)) { if (ForwardOpen()) { try { if (Lab.Message != null) { SendMessage(Lab.Message[0]); } if (Lab.Printer != null) { SendPrinterSettings(Lab.Printer[0]); // Must be done last } } catch (EIPIOException e1) { // In case of an EIP I/O error string name = $"{GetAttributeName(e1.ClassCode, e1.Attribute)}"; string msg = $"EIP I/O Error on {e1.AccessCode}/{e1.ClassCode}/{name}"; MessageBox.Show(msg, "EIP I/O Error", MessageBoxButtons.OK); } catch (Exception e2) { LogIt(e2.Message); } } ForwardClose(); } EndSession(); UseAutomaticReflection = false; }
public void Parse(Context context) { string starters = "LTME"; if (context.Input.Length > 0 && starters.IndexOf(context.Input[0]) >= 0) { switch (context.Input[0]) { case 'L': Next = new Lab(); break; case 'T': Next = new Test(); break; case 'M': Next = new Midterm(); break; case 'E': Next = new Exam(); break; } Next.Weight = GetNumber(context); if (context.Input.Length > 0 && context.Input[0] == '(') { context.Input = context.Input.Substring(1); Next.Part = new Element(); Next.Part.Parse(context); Element e = Next.Part; while (e != null) { e.Weight = e.Weight * Next.Weight / 100; e = e.Next; } context.Input = context.Input.Substring(2); } Next.Parse(context); } }
// post action method to add new phone in records public async Task <IActionResult> New(Lab l) { try { if (ModelState.IsValid) { if (l.LabId > 0) { _DbContext.Update(l); await _DbContext.SaveChangesAsync(); } else { _DbContext.Add(l); await _DbContext.SaveChangesAsync(); } return(RedirectToAction("Labs")); } } catch (Exception) { return(RedirectToAction("Labs")); } return(View(l)); }
public void TestInsert3ClassData() { Place p = new Place() { Address = "place", Description = "this is a place", Size = 100 }; Session.SaveOrUpdate(p); Classroom c = new Classroom() { Address = "place", Description = "this is a place", Size = 100, RoomNumber = "301" }; Session.SaveOrUpdate(c); Lab l = new Lab() { Address = "place", Description = "this is a place", Size = 100, LabSubject = "Physical" }; Session.SaveOrUpdate(l); Session.Flush(); var list = NewSession.QueryOver <Place>().List(); Assert.Greater(list.Count, 0); foreach (var place in list) { Debug.WriteLine(place.GetType().ToString()); } }
public static LabEquipment getLabEquipmentFromNode(ConfigNode node, Lab lab) { if (node.name != CONFIG_NODE_NAME) { NE_Helper.logError("getLabEquipmentFromNode: invalid Node: " + node.name); return getNullObject(); } string abb = node.GetValue(ABB_VALUE); string name = node.GetValue(NAME_VALUE); float mass = float.Parse(node.GetValue(MASS_VALUE)); string product = node.GetValue(PRODUCT_VALUE); float productPerHour = float.Parse(node.GetValue(PRODUCT_PER_HOUR_VALUE)); string reactant = node.GetValue(REACTANT_VALUE); float reactantPerProduct = float.Parse(node.GetValue(REACTANT_PER_PRODUCT_VALUE)); EquipmentRacks type = EquipmentRacksFactory.getType(node.GetValue(TYPE_VALUE)); LabEquipment eq = new LabEquipment(abb, name, type, mass, productPerHour, product, reactantPerProduct, reactant); eq.lab = lab; ConfigNode expNode = node.GetNode(ExperimentData.CONFIG_NODE_NAME); if (expNode != null) { eq.loadExperiment(ExperimentData.getExperimentDataFromNode(expNode)); } return eq; }
private static void AddLab(Lab lab, Dictionary <Item, int> demandsList) { foreach (Research.RequiredItem reqItem in lab.Research.GetItemsPerDay().ToList()) { RecipeHelper.AddItem(demandsList, reqItem.Item, Mathf.RoundToInt(reqItem.Count * lab.SharedData.Efficiency * 30)); } }
public void reset() { SaveToFile.saves = 0; GameCore.addMoney(-GameCore.getRpMoney(1)); GameCore.addRp(-GameCore.getRpMoney(0)); GameCore.setArea(1); GameCore.areasUnlocked = new bool[areasUnlocked.Length]; GameCore.areasUnlocked [0] = true; Lab.setEnergy(0, 40); Lab.setEnergy(1, 10); Lab.setEnergy(2, 10); Lab.setEnergy(3, 10); Lab.setEnergy(4, 10); Research.setRpPerSec(1); Research.upgradesDone = new int[upgradesDone.Length]; Research.buttonUnlocked = new bool[buttonUnlocked.Length]; Research.buttonUnlocked [0] = true; GameCore.startMoneyTimer = (System.DateTime.Now.Ticks / System.TimeSpan.TicksPerMillisecond); GameCore.averageMoneyPerSec = 20; GameCore.storyStarted = false; GameCore.storyEnded = false; float tempProfitsMulti = PlayerPrefs.GetFloat("profitsMulti"); PlayerPrefs.DeleteAll(); PlayerPrefs.SetFloat("profitsMulti", tempProfitsMulti); }
public ActionResult Create(Lab collection) { try { // TODO: Add insert logic here collection.BuildingName = _context.Building.FirstOrDefault(x => x.Id == collection.BuildingId).BuildingName; collection.FloorNumber = _context.Floors.FirstOrDefault(x => x.Id == collection.FloorId).FloorNumber; collection.RoomNumber = _context.Rooms.FirstOrDefault(x => x.Id == collection.RoomId).RoomNumber; collection.Updated = DateTime.Now; collection.UpdatedBy = User.Identity.Name; _context.Labs.Add(collection); _context.SaveChanges(); Room Room = _context.Rooms.Find(collection.RoomId); Room.Description = "Using For " + collection.Name + " Lab"; _context.Entry(Room).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
private Lab GetLab(CorporateCustomerEditModel model, OrganizationRoleUser createdByOrgRoleUser, IEnumerable <Lab> labs) { Lab lab = null; if (!string.IsNullOrEmpty(model.Lab)) { lab = labs.FirstOrDefault(l => l.Name.Trim().ToLower() == model.Lab.Trim().ToLower()); if (lab == null) { lab = _labRepository.GetByName(model.Lab); if (lab == null) { lab = new Lab { Name = model.Lab, Alias = model.Lab, IsActive = true, CreatedByOrgRoleUserId = createdByOrgRoleUser.Id, DateCreated = DateTime.Now }; lab = _labRepository.Save(lab); } } } return(lab); }
public async Task <IActionResult> EditLabAsync(Lab labData) { // Check input if (!ModelState.IsValid) { AddStatusMessage(_localizer["EditLabAsync:InvalidInput"], StatusMessageTypes.Error); return(await ShowEditLabFormAsync(null, labData)); } try { // Retrieve edited lab from database and apply changes var lab = await _labService.GetLabAsync(labData.Id, HttpContext.RequestAborted); lab.Name = labData.Name; lab.ApiCode = labData.ApiCode; lab.ServerBaseUrl = labData.ServerBaseUrl; lab.MaxPoints = labData.MaxPoints; lab.MaxFlagPoints = labData.MaxFlagPoints; await _labService.UpdateLabAsync(lab, HttpContext.RequestAborted); AddStatusMessage(_localizer["EditLabAsync:Success"], StatusMessageTypes.Success); } catch (InvalidOperationException ex) { _logger.LogError(ex, "Edit lab"); AddStatusMessage(_localizer["EditLabAsync:UnknownError"], StatusMessageTypes.Error); return(await ShowEditLabFormAsync(null, labData)); } return(await RenderLabListAsync()); }
private void ToggleDefaultTint(bool on) { ImmutableList <Store> allStores = LazyManager <BuildingManager> .Current.GetAll <Store>(); for (int i = 0; i < allStores.Count; i++) { Store store = allStores[i]; if (on && DisabledNodes?.Contains(store) == true) { continue; } LazyManager <BuildingTintManager> .Current.SetDefaultColor(store, on?new Color?(GameColors.WhiteModeCompanyTintColor) : null); store.SetTint(null); } ImmutableList <Lab> allLabs = LazyManager <BuildingManager> .Current.GetAll <Lab>(); for (int i = 0; i < allLabs.Count; i++) { Lab lab = allLabs[i]; if (on && DisabledNodes?.Contains(lab) == true) { continue; } LazyManager <BuildingTintManager> .Current.SetDefaultColor(lab, on?new Color?(GameColors.WhiteModeCompanyTintColor) : null); lab.SetTint(null); } }
public IActionResult Delete(int id) { //TODO: Implement me Lab lab = context.Labs.FirstOrDefault(l => l.Id == id); return(View(lab)); }
public static async Task <UsedReagent> AddReagent(IRequestContext context, Lab lab, Reagent reagent, int quantity) { if (reagent == null) { return(null); } if (quantity > reagent.Quantity) { throw new ArgumentOutOfRangeException(nameof(quantity), "Requested quantity exceeds reagent quantity."); } var usedReagent = new UsedReagent { Lab = lab, Reagent = reagent, Quantity = quantity, UsedDate = DateTimeOffset.Now, }; context.DbContext.UsedReagents.Add(usedReagent); reagent.Quantity -= quantity; await context.DbContext.SaveChangesAsync(); await context.LogAsync($"Used {quantity} of reagent ID {reagent.ReagentId} in lab ID {lab.LabId}"); return(usedReagent); }
public async Task <IActionResult> PutLab(short id, Lab lab) { if (id != lab.LabId) { return(BadRequest()); } if (lab.LabName == "deleted") { lab = _context.Labs.Where(p => p.LabId == id).FirstOrDefault(); lab.Deleted = true; } _context.Entry(lab).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LabExists(id)) { return(NotFound()); } else { throw; } } return(Ok(lab)); }
public async Task <IActionResult> Create(LabCreateModel model) { if (this.ModelState.IsValid) { var lab = new Lab { Name = model.Name, Address = model.Address, Phones = new Collection <LabPhone>() }; if (model.Phones != null) { var phoneId = 1; foreach (var phone in model.Phones.Split(',').Select(x => x.Trim()).Where(x => !String.IsNullOrEmpty(x))) { lab.Phones.Add(new LabPhone { PhoneId = phoneId++, Number = phone }); } } this.context.Add(lab); await this.context.SaveChangesAsync(); return(this.RedirectToAction("Index")); } return(this.View(model)); }
private void Button_Click(object sender, RoutedEventArgs e) { //When user clicks this button we want to save to the currently selected patient //The lab information populated in the Text Boxes UltimateMedDBWPFClient.Labs.LabViewModel currentViewModel = (UltimateMedDBWPFClient.Labs.LabViewModel)DataContext; if (currentViewModel.NewLab != null && currentViewModel.SelectedPatient != null) { currentViewModel.NewLab.Amount = Decimal.Parse(LabAmount.Text); currentViewModel.NewLab.Category = LabCategory.Text; currentViewModel.NewLab.Date = DateTime.Parse(LabDate.Text); currentViewModel.NewLab.PatientType = LabPatientType.Text; currentViewModel.NewLab.Weight = int.Parse(LabWeight.Text); currentViewModel.NewLab.Doc_id = int.Parse(LabDocId.Text); Lab.AddLab(currentViewModel.NewLab, currentViewModel.SelectedPatient.Name); MessageBox.Show("Lab has been successfully added to Patient's Account"); LabAmount.Text = null; LabCategory.Text = null; LabDate.Text = null; LabPatientType.Text = null; LabWeight.Text = null; LabDocId.Text = null; } }
//Used in averaging 25 Lab colors public static Lab DivideBy(double divisor, Lab lab) { lab.L /= divisor; lab.a /= divisor; lab.b /= divisor; return lab; }
public List <Lab> readLab() { List <Lab> LabList = new List <Lab>(); Lab Lab = new Lab(); //open database connection SqlConnection con = DatabaseConnection("open"); SqlCommand sqlCommand; try { sqlCommand = new SqlCommand("readLab", con); SqlDataReader reader = sqlCommand.ExecuteReader(); while (reader.Read()) { Lab.Id = reader.GetInt32(reader.GetOrdinal("id")); Lab.Name = reader.GetString(reader.GetOrdinal("name")); Lab.Description = reader.GetString(reader.GetOrdinal("description")); LabList.Add(Lab); } sqlCommand.Dispose(); } catch (SqlException sqlException) { Console.WriteLine("Database error: " + sqlException.ToString()); } finally { DatabaseConnection("close"); } return(LabList); }
private void InitDoor() { u1 = new OfficeUser() { Birthday = DateTime.Today, EmployeeNumber = "12046", Gender = Gender.Male, Name = "Devin" }; t1 = new Teacher() { Birthday = Convert.ToDateTime("1984-1-1"), EmployeeNumber = "12334", Gender = Gender.Female, Major = "Math", Name = "StevenMath" }; Session.SaveOrUpdate(u1); Session.SaveOrUpdate(t1); Student s1 = new Student() { Birthday = Convert.ToDateTime("1983-12-20"), Gender = Gender.Male, Name = "Jack" }; Session.SaveOrUpdate(s1); Lab l1 = new Lab() { Address = "Teaching Tower 1", Description = "For chemistry", Size = 70, LabSubject = "Primary Chemistry" }; Classroom cr1 = new Classroom() { Address = "Teaching Building 2", Description = "Common Room", RoomNumber = "402", Size = 150 }; Session.SaveOrUpdate(l1); Session.SaveOrUpdate(cr1); Session.Flush(); Education e1=new Education(){Employee = t1,GraduateYear = 2003,University = "UESTC"}; Education e11 = new Education() { Employee = t1, GraduateYear = 2007, University = "BJU" }; Education e2 = new Education() { Employee = u1, GraduateYear = 2001, University = "USTC" }; t1.Educations.Add(e1); t1.Educations.Add(e11); u1.Educations.Add(e2); DoorKey doorKey = new DoorKey() { Name = "401 Key" }; doorKey.Employees = new List<Employee>(); doorKey.Employees.Add(u1); doorKey.Employees.Add(t1); Session.SaveOrUpdate(doorKey); Session.Flush(); }
private static Color OklabToColor(Lab lab) { // Convert Oklab -> linear sRGB float l = lab.L + (0.3963377774f * lab.a) + (0.2158037573f * lab.b); float m = lab.L - (0.1055613458f * lab.a) - (0.0638541728f * lab.b); float s = lab.L - (0.0894841775f * lab.a) - (1.2914855480f * lab.b); l = l * l * l; m = m * m * m; s = s * s * s; double r = (+4.0767416621f * l) - (3.3077115913f * m) + (0.2309699292f * s); double g = (-1.2684380046f * l) + (2.6097574011f * m) - (0.3413193965f * s); double b = (-0.0041960863f * l) - (0.7034186147f * m) + (1.7076147010f * s); // Convert linear sRGB -> sRGB r = r > 0.0031308 ? (1.055 * Math.Pow(r, 1 / 2.4)) - 0.055 : 12.92 * r; g = g > 0.0031308 ? (1.055 * Math.Pow(g, 1 / 2.4)) - 0.055 : 12.92 * g; b = b > 0.0031308 ? (1.055 * Math.Pow(b, 1 / 2.4)) - 0.055 : 12.92 * b; // Convert 0-1.0 -> 0-255, and clamp (clamping should be sufficient for our use case) int cr = (int)(r * 255f).Clamp(0f, 255f); int cg = (int)(g * 255f).Clamp(0f, 255f); int cb = (int)(b * 255f).Clamp(0f, 255f); return(Color.FromArgb(cr, cg, cb)); }
public virtual void ColorTest03() { PdfWriter writer = new PdfWriter(destinationFolder + "colorTest03.pdf"); writer.SetCompressionLevel(CompressionConstants.NO_COMPRESSION); PdfDocument document = new PdfDocument(writer); PdfPage page = document.AddNewPage(); PdfCanvas canvas = new PdfCanvas(page); CalGray calGray1 = new CalGray(new float[] { 0.9505f, 1.0000f, 1.0890f }, 0.5f); canvas.SetFillColor(calGray1).Rectangle(50, 500, 50, 50).Fill(); CalGray calGray2 = new CalGray(new float[] { 0.9505f, 1.0000f, 1.0890f }, null, 2.222f, 0.5f); canvas.SetFillColor(calGray2).Rectangle(150, 500, 50, 50).Fill(); CalRgb calRgb = new CalRgb(new float[] { 0.9505f, 1.0000f, 1.0890f }, null, new float[] { 1.8000f, 1.8000f , 1.8000f }, new float[] { 0.4497f, 0.2446f, 0.0252f, 0.3163f, 0.6720f, 0.1412f, 0.1845f, 0.0833f, 0.9227f }, new float[] { 1f, 0.5f, 0f }); canvas.SetFillColor(calRgb).Rectangle(50, 400, 50, 50).Fill(); Lab lab1 = new Lab(new float[] { 0.9505f, 1.0000f, 1.0890f }, null, new float[] { -128, 127, -128, 127 }, new float[] { 1f, 0.5f, 0f }); canvas.SetFillColor(lab1).Rectangle(50, 300, 50, 50).Fill(); Lab lab2 = new Lab((PdfCieBasedCs.Lab)lab1.GetColorSpace(), new float[] { 0f, 0.5f, 0f }); canvas.SetFillColor(lab2).Rectangle(150, 300, 50, 50).Fill(); canvas.Release(); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "colorTest03.pdf", sourceFolder + "cmp_colorTest03.pdf", destinationFolder, "diff_")); }
public async Task <ActionResult <Lab> > PostLab(Lab lab) { _context.Labs.Add(lab); await _context.SaveChangesAsync(); return(CreatedAtAction("GetLab", new { id = lab.LabId }, lab)); }
internal static IRgb ToColor(ILch item) { var hRadians = item.H * Math.PI / 180.0; var lab = new Lab { L = item.L, A = Math.Cos(hRadians) * item.C, B = Math.Sin(hRadians) * item.C }; return lab.To<Rgb>(); }
Lab[,] RgbArrayToLabArray(Color[,] RgbArray) { Lab[,] rawLabArray= new Lab[RgbArray.GetLength(0), RgbArray.GetLength(1)]; for (int i = 0; i < RgbArray.GetLength (0); i++) { for (int j = 0; j < RgbArray.GetLength (1); j++) { rawLabArray[i,j] = ColorUtil.ConvertRGBtoLAB (RgbArray[i,j]); } } return rawLabArray; }
public static LabEquipmentSlot getLabEquipmentSlotFromConfigNode(ConfigNode node, Lab lab) { if (node.name != CONFIG_NODE_NAME) { NE_Helper.logError("getLabEquipmentFromNode: invalid Node: " + node.name); return new LabEquipmentSlot(EquipmentRacks.NONE); } EquipmentRacks type = EquipmentRacksFactory.getType(node.GetValue(TYPE_VALUE)); LabEquipment le = null; ConfigNode leNode = node.GetNode(LabEquipment.CONFIG_NODE_NAME); if (leNode != null) { le = LabEquipment.getLabEquipmentFromNode(leNode, lab); } return new LabEquipmentSlot(type, le); }
public void Parse(InterpreterContext context) { string starters = "LTME"; if (context.Input.Length > 0 && starters.IndexOf(context.Input[0]) >= 0) { switch (context.Input[0]) { case 'L': Next = new Lab(); break; case 'T': Next = new Test1(); break; case 'M': Next = new Midterm(); break; case 'E': Next = new Exam(); break; } Next.Weight = GetNumber(context); if (context.Input.Length > 0 && context.Input[0] == '(') { context.Input = context.Input.Substring(1); Next.Part = new Element(); Next.Part.Parse(context); Element e = Next.Part; while (e != null) { e.Weight = e.Weight * Next.Weight / 100; e = e.Next; } context.Input = context.Input.Substring(2); } Next.Parse(context); } }
public void SetUp() { ReBuildDatabase(); OfficeUser u1=new OfficeUser(){Birthday = DateTime.Today,EmployeeNumber = "12046",Gender = Gender.Male,Name = "Devin"}; Teacher t1=new Teacher(){Birthday = Convert.ToDateTime("1984-1-1"),EmployeeNumber = "12334",Gender = Gender.Female,Major = "Math",Name = "StevenMath"}; Session.SaveOrUpdate(u1); Session.SaveOrUpdate(t1); Student s1=new Student(){Birthday = Convert.ToDateTime("1983-12-20"),Gender = Gender.Male,Name = "Jack"}; Session.SaveOrUpdate(s1); Lab l1=new Lab(){Address = "Teaching Tower 1",Description = "For chemistry",Size = 70,LabSubject = "Primary Chemistry"}; Classroom cr1=new Classroom(){Address = "Teaching Building 2",Description = "Common Room",RoomNumber = "402",Size = 150}; Session.SaveOrUpdate(l1); Session.SaveOrUpdate(cr1); Session.Flush(); DoorKey doorKey = new DoorKey() { Name = "401 Key" }; doorKey.Employees = new List<Employee>(); doorKey.Employees.Add(u1); doorKey.Employees.Add(t1); Session.SaveOrUpdate(doorKey); Session.Flush(); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; string result = string.Empty; if(context.Request.Params["tbLabName"]==null) { result="{success:false,msg:'不能为空'}"; } else { try { Lab lab=new Lab(); lab.Name=context.Request.Params["tbLabName"].ToString(); lab.UnitID=new Guid(context.Request.Params["UnitID"].ToString()); lab.OtherName1=context.Request.Params["tbOtherName1"].ToString(); lab.OtherName2=context.Request.Params["tbOtherName2"].ToString(); lab.Address=context.Request.Params["tbAddress"].ToString(); lab.Postalcode=context.Request.Params["tbPostalcode"].ToString(); lab.Tel=context.Request.Params["tbTel"].ToString(); lab.Fax=context.Request.Params["tbFax"].ToString(); lab.Website=context.Request.Params["tbWebsite"].ToString(); lab.Email=context.Request.Params["tbEmail"].ToString(); lab.LabSortID=new Guid(context.Request.Params["ddlLabSort"].ToString()); lab.LabLevelID=new Guid(context.Request.Params["ddlLabLevel"].ToString()); lab.LabPrincipal=context.Request.Params["tbLabPrincipal"].ToString(); lab.LinkMan=context.Request.Params["tbLinkMan"].ToString(); lab.IsRecognize=int.Parse(context.Request.Params["tbRecognize"].ToString()); lab.RecognizeNumber=context.Request.Params["tbRecognizeNumber"].ToString(); lab.OrganizationCode=context.Request.Params["tbOrganizationCode"].ToString(); lab.Synopsis=context.Request.Params["tbSynopsis"].ToString(); lab.Remark=context.Request.Params["tbRemark"].ToString(); lab.Save(); CY.CSTS.Core.Business.FreshNews fresh = new CY.CSTS.Core.Business.FreshNews(); fresh.Sponsor = "管理员"; fresh.FreshEvent = "添加实验室" + lab.Name; CY.CSTS.Core.Business.UnitInfo unitinfo = CY.CSTS.Core.Business.UnitInfo.Load(lab.UnitID); fresh.Embracer = unitinfo.UnitName; fresh.UnitId = lab.UnitID; fresh.EventType = 8; fresh.EventTime = DateTime.Now; string domIDtemp = context.Request.Params["tbDomainID"]; if (!string.IsNullOrEmpty(domIDtemp)) { string[] domID=domIDtemp.Split(','); if (domID.Length > 0) { for (int m = 0; m < domID.Length; m++) { LabDomain labDomain = new LabDomain(); labDomain.LabID = lab.Id; labDomain.DomainID =new Guid(domID[m]); labDomain.Save(); } } } result = "{success:true}"; } catch(Exception ex) { result="{success:false,msg:'"+ex.Message+"'}"; } } context.Response.Write(result); }
private Generator createGenerator(string resToCreate, float creationRate, string useRes, float usePerUnit, Lab lab) { Generator gen = new Generator(lab.part); gen.addRate(resToCreate, -creationRate); if (usePerUnit > 0) gen.addRate(useRes, usePerUnit); return gen; }
public void install(Lab lab) { NE_Helper.log("Lab equipment install in " + lab.abbreviation); gen = createGenerator(product, productPerHour, reactant, reactantPerProduct, lab); lab.addGenerator(gen); this.lab = lab; }
static double LabDistance(Color rgb1, Color rgb2) { Lab lab1 = new Lab(), lab2 = new Lab(); LabConverter.ToColorSpace(new Rgb { R = rgb1.R, G = rgb1.G, B = rgb1.B }, lab1); LabConverter.ToColorSpace(new Rgb { R = rgb2.R, G = rgb2.G, B = rgb2.B }, lab2); return Math.Pow(lab2.L - lab1.L, 2) + Math.Pow(lab2.A - lab1.A, 2) + Math.Pow(lab2.B - lab1.B, 2); }
internal void onStart(Lab lab) { if (equ != null) { equ.install(lab); } }
internal static void ToColorSpace(Rgb color, Lab item) { var xyz = new Xyz(); xyz.Initialize(color); var white = XyzConverter.WhiteReference; var x = PivotXyz(xyz.X / white.X); var y = PivotXyz(xyz.Y / white.Y); var z = PivotXyz(xyz.Z / white.Z); item.L = Math.Max(0, 116 * y - 16); item.A = 500 * (x - y); item.B = 200 * (y - z); }
public static Lab ConvertRGBtoLAB(Color rgb) { double rLinear, gLinear, bLinear; double x,y,z; Lab lab = new Lab(); rLinear = (double)rgb.r; gLinear = (double)rgb.g; bLinear = (double)rgb.b; double r = (rLinear > 0.04045) ? Math.Pow((rLinear + 0.055) / ( 1 + 0.055), 2.2) : (rLinear / 12.92); double g = (gLinear > 0.04045) ? Math.Pow((gLinear + 0.055) / ( 1 + 0.055), 2.2) : (gLinear / 12.92); double b = (bLinear > 0.04045) ? Math.Pow((bLinear + 0.055) / ( 1 + 0.055), 2.2) : (bLinear / 12.92); x = r * 0.4124 + g * 0.3576 + b * 0.1805; y = r * 0.2126 + g * 0.7152 + b * 0.0722; z = r * 0.0193 + g * 0.1192 + b * 0.9505; lab.L = 116.0 * Fxyz(y / 1.0) - 16; lab.a = 500.0 * (Fxyz(x / 0.9505) - Fxyz(y / 1.0)); lab.b = 200.0 * (Fxyz(y / 1.0) - Fxyz(z / 1.0890)); return lab; }
public static Color AvgColor(Color rgb1, Color rgb2) { Lab lab1, lab2; lab1 = new Lab(); lab2 = new Lab(); lab1 = ConvertRGBtoLAB(rgb1); lab2 = ConvertRGBtoLAB(rgb2); //return sum/2 return ConvertLABtoRGB(DivideBy(2,(lab1 + lab2))); }
public static Color ConvertLABtoRGB(Lab lab) { double x, y, z, //CIE XYZ color space used as stepping stone for conversion //D65, (0.9505, 1.0, 1.0890) fy, fx, fz, //variables needed for calculation fr, fg, fb; //normalized rgb conversion int r, g, b; // final fy = (lab.L + 16) / 116.0; fx = fy + (lab.a / 500.0); fz = fy - (lab.b / 200.0); //Attempt 2 (easyrgb) if ((fy*fy*fy) > 0.008856) { fy = fy * fy * fy; } else { fy = (fy - 16 / 116) / 7.787; } if ((fx * fx * fx) > 0.008856) { fx = fx * fx * fx; } else { fx = (fx - 16 / 116) / 7.787; } if ((fz * fz * fz) > 0.008856) { fz = fz * fz * fz; } else { fz = (fz - 16 / 116) / 7.787; } x = 95.047 * fx; y = 100.000 * fy; z = 108.883 * fz; fx = x / 100; fy = y / 100; fz = z / 100; fr = fx * 3.2406 + fy * -1.5372 + fz * -0.4986; fg = fx * -0.9689 + fy * 1.8758 + fz * 0.0415; fb = fx * 0.0557 + fy * -0.2040 + fz * 1.0570; if ( fr > 0.0031308 ) { fr = 1.055 * ( Math.Pow(fr, ( 1.0 / 2.4 ))) - 0.055; } else { fr = 12.92 * fr; } if ( fg > 0.0031308 ) { fg = 1.055 * ( Math.Pow(fg,( 1.0 / 2.4 ))) - 0.055; } else { fg = 12.92 * fg; } if (fb > 0.0031308) { fb = 1.055 * ( Math.Pow(fb, (1.0 / 2.4))) - 0.055; } else { fb = 12.92 * fb; } if (fr > 1) { fr = 1f; } if (fg > 1f) { fg = 1f; } if (fb > 1f) { fb = 1f; } return new Color((float)fr * 255.0f, (float)fb * 255.0f, (float)fg * 255.0f, 255); }
public void install(LabEquipment eq, Lab lab) { if (eq != null && type == eq.getType()) { equ = eq; eq.install(lab); } else { NE_Helper.logError("LabEquipmentSlot.install: Type doesn't macht"); } }
private void installExperimentInLab(Lab lab) { lab.installExperiment(expData); removeExperimentData(); }
internal static Rgb ToColor(Lab item) { var y = (item.L + 16.0) / 116.0; var x = item.A / 500.0 + y; var z = y - item.B / 200.0; var white = XyzConverter.WhiteReference; var x3 = x * x * x; var z3 = z * z * z; var xyz = new Xyz { X = white.X * (x3 > XyzConverter.Epsilon ? x3 : (x - 16.0 / 116.0) / 7.787), Y = white.Y * (item.L > (XyzConverter.Kappa * XyzConverter.Epsilon) ? Math.Pow(((item.L + 16.0) / 116.0), 3) : item.L / XyzConverter.Kappa), Z = white.Z * (z3 > XyzConverter.Epsilon ? z3 : (z - 16.0 / 116.0) / 7.787) }; return xyz.ToRgb(); }
// Update is called once per frame void FixedUpdate () { Rigidbody2D body = GetComponent<Rigidbody2D> (); /* if (Input.touches > 1) { //color wheel } else if (Input1` */ if (Input.GetKeyDown(KeyCode.Space) && bucketAmount >= 25) //if (Input.touches.Length > 2 && bucketAmount >= 25) { GameObject splatter = (GameObject)Resources.Load("Splatter"); splatter.GetComponent<Splatter> ().color = bucketColor; GameObject splatterObj = (GameObject)Instantiate(splatter); splatterObj.transform.position = this.transform.position; //splatterObj.transform.localScale = new Vector3 (1, 1, 1); bucketAmount -= 25; } Color avgRGB = new Color (0, 0, 0); if (!Input.GetKey (KeyCode.LeftControl)) { //if (Input.touches.Length == 1) { float moveX = 0; float moveY = 0; moveX = Input.GetAxis ("Horizontal"); moveY = Input.GetAxis ("Vertical"); //camera.unproject /*if (Input.touches [0].position.x > this.transform.position.x) { moveX = 1; } if (Input.touches [0].position.y > this.transform.position.y) { moveY = 1; } if (Input.touches [0].position.x < this.transform.position.x) { moveX = -1; } if (Input.touches [0].position.y < this.transform.position.y) { moveY = -1; } */ if (splatters.Count == 0) { //CG force Vector2 CompressedPos = new Vector2 ((int)transform.position.x * 20, (int)transform.position.y * 20); //Debug.Log(CompressedPos.x + " " + CompressedPos.y); Lab avgLab = new Lab (0, 0, 0); for (int i = (int)CompressedPos.x - 3; i < (int)CompressedPos.x + 3; i++) { for (int j = (int)CompressedPos.y - 3; j < (int)CompressedPos.y + 3; j++) { if (PaintingController.CompressedLabArray.GetLength(0) > ((int)CompressedPos.x + (i - (int)CompressedPos.x)) && PaintingController.CompressedLabArray.GetLength(1) > ((int)CompressedPos.y + (j - (int)CompressedPos.y))) avgLab += PaintingController.CompressedLabArray [(int)CompressedPos.x + (i - (int)CompressedPos.x), (int)CompressedPos.y + (j - (int)CompressedPos.y)]; } } avgLab = avgLab / new Lab (25, 25, 25); avgRGB = ColorUtil.ConvertLABtoRGB (avgLab); avgRGB.r /= 255f; avgRGB.g /= 255f; avgRGB.b /= 255f; //Debug.Log (avgRGB.r + " " + avgRGB.g + " " + avgRGB.b); } else { foreach (GameObject obj in splatters) { Splatter splatter = obj.GetComponent<Splatter> (); avgRGB.r += splatter.color.r;// * 255f; avgRGB.g += splatter.color.g;// * 255f; avgRGB.b += splatter.color.b;// * 255f; } avgRGB.r /= splatters.Count; avgRGB.g /= splatters.Count; avgRGB.b /= splatters.Count; } //Debug.Log (avgRGB.r + " " + avgRGB.g + " " + avgRGB.b); float chroma = 0; float hue = ColorUtil.GetHueLightnessFromRGB (avgRGB, ref chroma); //Debug.Log (chroma); CGHud.UpdateCGHud (-1*hue, avgRGB, chroma); hue = (hue / 180f * Mathf.PI); //Debug.Log (hue); //body.AddForce (new Vector2 ((float)Mathf.Cos (hue)*14, (float)Mathf.Sin (hue))*14, ForceMode2D.Force); //input force //Debug.Log("Move x/y: " + moveX + " " + moveY); //Debug.Log("hue X: " + (float)Mathf.Cos (hue) + " " + (float)Mathf.Sin (hue)); //flipping y axis to fix if (chroma != 0) { body.AddForce (new Vector2 (((moveX * 2) + ((float)Mathf.Cos (hue)) * 3), ((moveY * 2)) + (-1 * (float)Mathf.Sin (hue)) * 3), ForceMode2D.Impulse); } else { body.AddForce (new Vector2 ((moveX * 2), (moveY * 2)), ForceMode2D.Impulse); } if (body.velocity.magnitude > maxSpeed) { body.velocity = body.velocity.normalized * maxSpeed; } } else { body.velocity = Vector2.zero; } UpdateBucketHUD (avgRGB, bucketAmount); //face direction of moving by rotation }
Lab[,] CompressLabArray (Lab[,] rawLabArray) { Lab[,] LabArray = new Lab[rawLabArray.GetLength(0)/5, rawLabArray.GetLength(1)/5]; Debug.Log (rawLabArray.GetLength (0) + " " + LabArray.GetLength (0)); //for every 5 by 5 box going from column top to bottom then row left to right for (int i = 0; i < rawLabArray.GetLength (0)-5; i=i+5) { for (int j = 0; j < rawLabArray.GetLength (1)-5; j=j+5) { Lab comps = new Lab(0,0,0); //for each box, for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { comps += rawLabArray [i + x, j + y]; } } LabArray [i / 5, j / 5] = (comps / (new Lab (25, 25, 25)));//making not decimal } } Debug.Log (LabArray [25, 26].L + " " + LabArray [25, 26].a + " " + LabArray [25, 26].b + " "); return LabArray; }