// Проверка панелей на чертеже и панелей в памяти (this) public void CheckPanelsInDrawingAndMemory() { // Проверка зон покраски var colorAreasCheck = ColorArea.GetColorAreas(SymbolUtilityServices.GetBlockModelSpaceId(_db), this); // сравнение фоновых зон if (!colorAreasCheck.SequenceEqual(_colorAreas)) { throw new System.Exception("Изменились зоны покраски. Рекомендуется выполнить повторную покраску панелей командой PaintPanels."); } // Проверка панелей // Определение покраски панелей. var rtreeColorAreas = ColorArea.GetRTree(colorAreasCheck); SelectionBlocks selBlocks = new SelectionBlocks(_db); selBlocks.SelectBlRefsInModel(StartOptions.SortPanels); var marksSbCheck = MarkSb.GetMarksSB(rtreeColorAreas, this, "Проверка панелей...", selBlocks.IdsBlRefPanelAr); //RenamePanelsToArchitectIndex(marksSbCheck); if (!marksSbCheck.SequenceEqual(_marksSB)) { throw new System.Exception("Панели изменились после последнего выполнения команды покраски. Рекомендуется выполнить повторную покраску панелей командой PaintPanels."); } }
public BrushInfo GetBrushInfo(ColorArea area) { switch (area) { case ColorArea.Front_Text: return(Font.FrontTextBrushInfo.TextBrush); case ColorArea.Front_Border: return(Font.FrontTextBrushInfo.BorderBrush); case ColorArea.Front_Shadow: return(Font.FrontTextBrushInfo.ShadowBrush); case ColorArea.Back_Text: return(Font.BackTextBrushInfo.TextBrush); case ColorArea.Back_Border: return(Font.BackTextBrushInfo.BorderBrush); case ColorArea.Back_Shadow: return(Font.BackTextBrushInfo.ShadowBrush); default: throw new ArgumentOutOfRangeException(nameof(area)); } }
public BrushInfo GetBrushInfo(ColorArea area) { switch (area) { case ColorArea.Front_Text: return(Font.FrontTextBrushInfo.TextBrush); case ColorArea.Front_Border: return(Font.FrontTextBrushInfo.BorderBrush); case ColorArea.Front_Shadow: return(Font.FrontTextBrushInfo.ShadowBrush); case ColorArea.Back_Text: return(Font.BackTextBrushInfo.TextBrush); case ColorArea.Back_Border: return(Font.BackTextBrushInfo.BorderBrush); case ColorArea.Back_Shadow: return(Font.BackTextBrushInfo.ShadowBrush); } return(null); }
public ColorArea FloodFillPoint(ref Bitmap bmp, Point point, Color targetColor) { Stack <Point> pixels = new Stack <Point>(); targetColor = bmp.GetPixel(point.X, point.Y); pixels.Push(point); var nextColor = RandonColor(); var returnValue = new ColorArea { Cor = nextColor }; while (pixels.Count > 0) { Point a = pixels.Pop(); if (a.X < bmp.Width && a.X > 0 && a.Y < bmp.Height && a.Y > 0)//make sure we stay within bounds { if (bmp.GetPixel(a.X, a.Y) == targetColor) { returnValue.Area++; bmp.SetPixel(a.X, a.Y, nextColor); pixels.Push(new Point(a.X - 1, a.Y)); pixels.Push(new Point(a.X + 1, a.Y)); pixels.Push(new Point(a.X, a.Y - 1)); pixels.Push(new Point(a.X, a.Y + 1)); } } } return(returnValue); }
/// <summary> /// Залить цветом ячейки в таблице /// </summary> /// <param name="progress"></param> /// <param name="worksheet">Страница</param> /// <param name="colors">Цвета</param> private void DecorateWorksheetCells(ExcelExportProgressCommand progress, dynamic worksheet, Color[,] colors) { var areas = new List <ColorArea>(); for (int i = 0; i < Rows; i++) { for (int j = 0; j < Columns; j++) { var c = colors[i, j]; if (c.R < 250 || c.B < 250 || c.G < 250) { var a = new ColorArea(); a.Fill(colors, j, i); a.Bleach(colors); areas.Add(a); } } } foreach (var a in areas) { progress.Area = string.Format("{0}:{1:D2} - {2}:{3:D2}", a.Y + 2, a.X + 1, a.Y + 1 + a.Height, a.X + a.Width); var r1 = worksheet.Cells[a.Y + 2, a.X + 1]; var r2 = worksheet.Cells[a.Y + 1 + a.Height, a.X + a.Width]; var r = worksheet.Range(r1, r2); r.Interior.Color = a.Color.ToOle(); } }
//Mutator for color public void setColor(ColorArea.CharColor color) { if (this.color != color) { this.color = color; body.renderer.material.color = ColorArea.GetPallete(color); } }
public void Kill() { if (deathParticles != null) { ParticleSystem p = (Instantiate(deathParticles, transform.position, Quaternion.identity) as GameObject).particleSystem; p.startColor = ColorArea.GetPallete(brain.color); } }
public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) { return(true); } ColorArea otherArea = (ColorArea)obj; return(this.color == otherArea.color && this.areaMask == otherArea.areaMask); }
public virtual bool TryToSpreadColorAreaToPosition(ref ColorArea colorArea, Vector2Int position, ref List <Vector2Int> remainingPositions) { bool output = remainingPositions.Contains(position); if (output) { colorArea.edgePositions.Add(position); remainingPositions.Remove(position); colors[position.x + position.y * size.x] = colorArea.color; } return(output); }
public void MakeACO(string folder) { MemoryStream memory = new MemoryStream(); EndianBinaryWriter bwriterWriter = new EndianBinaryWriter(EndianBitConverter.Big, memory); const UInt16 separator = 0; UInt16 sectionCounter = 0; var colorlist = ColorArea.AllColors().ToList(); UInt16 numberOfColors = UInt16.Parse(colorlist.Count.ToString()); sectionCounter++; using (memory) { using (bwriterWriter) { bwriterWriter.Write(sectionCounter); bwriterWriter.Write(numberOfColors); // write the number of colors foreach (Color color in colorlist) { ColorStructureWriter(bwriterWriter, color); } sectionCounter++; bwriterWriter.Write(sectionCounter); bwriterWriter.Write(numberOfColors); var encoding = new UnicodeEncoding(true, true, true); foreach (var color in colorlist) { ColorStructureWriter(bwriterWriter, color); var tmpcol = ColorArea.List.FirstOrDefault(c => c.Color == color); var bytes = (encoding.GetBytes(tmpcol.Name)); bwriterWriter.Write((ushort)tmpcol.Name.Length + 1); bwriterWriter.Write(bytes); bwriterWriter.Write((ushort)0); } bwriterWriter.Flush(); using (FileStream output = new FileStream(Path.Combine(folder, "palette.ACO"), FileMode.Create)) { memory.WriteTo(output); } } } }
public static SampledColorGradient2D GenerateRandom(Vector2Int size, int colorAreaCount, int blurRadius) { SampledColorGradient2D output = new SampledColorGradient2D(); output.blurRadius = blurRadius; output.size = size; output.colors = new Color[size.x * size.y]; List <Vector2Int> remainingPositions = new List <Vector2Int>(); for (int x = 0; x < size.x; x++) { for (int y = 0; y < size.y; y++) { remainingPositions.Add(new Vector2Int(x, y)); } } for (int i = 0; i < colorAreaCount; i++) { ColorArea colorArea = new ColorArea(); colorArea.origin = new Vector2Int(Random.Range(0, size.x), Random.Range(0, size.y)); colorArea.edgePositions.Add(colorArea.origin); colorArea.color = ColorExtensions.RandomColor(); //.SetAlpha(Random.value); output.colorAreas = output.colorAreas.Add(colorArea); remainingPositions.Remove(colorArea.origin); output.colors[colorArea.origin.x + colorArea.origin.y * size.x] = colorArea.color; } while (remainingPositions.Count > 0) { for (int i = 0; i < colorAreaCount; i++) { ColorArea colorArea = output.colorAreas[i]; int edgePositionCount = colorArea.edgePositions.Count; if (edgePositionCount > 0) { for (int i2 = 0; i2 < edgePositionCount; i2++) { Vector2Int edgePosition = colorArea.edgePositions[i2]; output.TryToSpreadColorAreaToPosition(ref colorArea, edgePosition + Vector2Int.right, ref remainingPositions); output.TryToSpreadColorAreaToPosition(ref colorArea, edgePosition + Vector2Int.left, ref remainingPositions); output.TryToSpreadColorAreaToPosition(ref colorArea, edgePosition + Vector2Int.up, ref remainingPositions); output.TryToSpreadColorAreaToPosition(ref colorArea, edgePosition + Vector2Int.down, ref remainingPositions); colorArea.edgePositions.Remove(edgePosition); edgePositionCount--; } output.colorAreas[i] = colorArea; } } } return(output); }
void Update() { spawnCounter -= Time.deltaTime; if (spawnCounter < 0f) { spawnCounter += spawnCycle; CharacterControl spawn = (Instantiate(spawnObject, transform.position + Vector3.Scale(Random.insideUnitSphere, new Vector3(1f, 0f, 1f)), Quaternion.identity) as GameObject).GetComponent <CharacterControl>(); if (spawnColor != ColorArea.CharColor.None) { spawn.setColor = spawnColor; } else { spawn.setColor = ColorArea.RandomColor(); } } }
public static bool Colorize(Bitmap b, int red, int green, int blue, ColorArea ca) { if (red < -255 || red > 255) { return(false); } if (green < -255 || green > 255) { return(false); } if (blue < -255 || blue > 255) { return(false); } BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); int bytes = Math.Abs(bmData.Stride) * b.Height; int stride = bmData.Stride; System.IntPtr Scan0 = bmData.Scan0; byte[] p = new byte[bytes]; System.Runtime.InteropServices.Marshal.Copy(Scan0, p, 0, bytes); int i = 0; int nOffset = stride - b.Width * 3; int nPixel; for (int y = 0; y < b.Height; ++y) { for (int x = 0; x < b.Width; ++x) { int pdif = (p[i + 2] + p[i + 1] + p[i]) / 3; int newred = p[i + 2]; int newgreen = p[i + 1]; int newblue = p[i]; if (ca == ColorArea.Shadows) { float multi = (1 - newred / 255); newred += (int)(red * multi); multi = (1 - newgreen / 255); newgreen += (int)(green * multi); multi = (1 - newblue / 255); newblue += (int)(blue * multi); } if (ca == ColorArea.Hightlights) { float multi = (newred / 255); newred += (int)(red * multi); multi = (newgreen / 255); newgreen += (int)(green * multi); multi = (newblue / 255); newblue += (int)(blue * multi); } if (ca == ColorArea.Midtones) { float multi = 0; if (newred > 127) { multi = 127f / newred; } else { multi = newred / 127f; } newred += (int)(red * multi); if (newgreen > 127) { multi = 127f / newgreen; } else { multi = newgreen / 127f; } newgreen += (int)(green * multi); if (newblue > 127) { multi = 127f / newblue; } else { multi = newblue / 127f; } newblue += (int)(blue * multi); } nPixel = newred; nPixel = Math.Max(nPixel, 0); p[i + 2] = (byte)Math.Min(255, nPixel); nPixel = newgreen; nPixel = Math.Max(nPixel, 0); p[i + 1] = (byte)Math.Min(255, nPixel); nPixel = newblue; nPixel = Math.Max(nPixel, 0); p[i + 0] = (byte)Math.Min(255, nPixel); i += 3; } i += nOffset; } System.Runtime.InteropServices.Marshal.Copy(p, 0, Scan0, bytes); b.UnlockBits(bmData); return(true); }
public static WriteableBitmap Colorize(WriteableBitmap b, int red, int green, int blue, ColorArea ca) { if (red < -255 || red > 255) throw new ArgumentException("Red must be between -255 and +255"); if (green < -255 || green > 255) throw new ArgumentException("Green must be between -255 and +255"); if (blue < -255 || blue > 255) throw new ArgumentException("Blue must be between -255 and +255"); int stride = b.PixelWidth * 4; //The pixelformat for brga32 is 32 bits - so that's 4 bytes per pixel int bytes = Math.Abs(stride) * b.PixelHeight; byte[] p = b.ToByteArray(); int i = 0; int nOffset = stride - b.PixelWidth * 4; for (int y = 0; y < b.PixelHeight; ++y) { for (int x = 0; x < b.PixelWidth; ++x) { int pdif = (p[i + 2] + p[i + 1] + p[i]) / 3; int newred = p[i + 2]; int newgreen = p[i + 1]; int newblue = p[i]; switch (ca) { case ColorArea.Shadows: float multi = (1 - newred / 255); newred += (int)(red * multi); multi = (1 - newgreen / 255); newgreen += (int)(green * multi); multi = (1 - newblue / 255); newblue += (int)(blue * multi); break; case ColorArea.Highlights: float hmulti = (newred / 255); newred += (int)(red * hmulti); hmulti = (newgreen / 255); newgreen += (int)(green * hmulti); hmulti = (newblue / 255); newblue += (int)(blue * hmulti); break; case ColorArea.Midtones: float mmulti = 0; mmulti = (newred > 127) ? 127f / newred : newred / 127f; newred += (int)(red * mmulti); mmulti = (newgreen > 127) ? 127f / newgreen : newgreen / 127f; newgreen += (int)(green * mmulti); mmulti = (newblue > 127) ? 127f / newblue : newblue / 127f; newblue += (int)(blue * mmulti); break; } p[i + 2] = (byte)Math.Min(255, Math.Max(newred, 0)); p[i + 1] = (byte)Math.Min(255, Math.Max(newgreen, 0)); p[i + 0] = (byte)Math.Min(255, Math.Max(newblue, 0)); i += 4; } i += nOffset; } WriteableBitmap finalImg = new WriteableBitmap(b.PixelWidth, b.PixelHeight); return finalImg.FromByteArray(p); }
public void ApplyProperty(ColorArea area, Action <BrushInfo> action) { action.Invoke(GetBrushInfo(area)); ApplyFont(Font); }
void Start() { body.renderer.material.color = ColorArea.GetPallete(color); //Initial tint }
override public void TouchColorArea(ColorArea.CharColor touch) { Debug.Log("Touched object of color: :" + ColorArea.GetPallete(touch).ToString()); setColor(touch); }
private List<ColorArea> FindColorAreas(IEnumerable sel) { List<ColorArea> areas = new List<ColorArea>(); using (var t = Db.TransactionManager.StartTransaction()) { foreach (ObjectId idEnt in sel) { var blRef = idEnt.GetObject(OpenMode.ForRead) as BlockReference; if (blRef == null) continue; string blName = blRef.GetEffectiveName(); if (blName == Settings.Default.BlockColorAreaName) { var area = new ColorArea(blRef, blName); areas.Add(area); } } t.Commit(); } return areas; }
// Покраска панелей в модели (по блокам зон покраски) public void PaintPanels() { // Запрос начальных значений - Аббревиатуры, Номера первого этажа, Номера первого листа //promptStartOptions(); StartOptions = StartOptions.PromptStartOptions(); // Определение марок покраски панелей (Марок АР). // Создание определениц блоков марок АР. // Покраска панелей в чертеже. // В Модели должны быть расставлены панели Марки СБ и зоны покраски. // сброс списка цветов. _colors = new List <Paint>(); // Определение зон покраски в Модели _colorAreas = ColorArea.GetColorAreas(SymbolUtilityServices.GetBlockModelSpaceId(_db), this); RTree <ColorArea> rtreeColorAreas = ColorArea.GetRTree(_colorAreas); // Бонус - покраска блоков плитки разложенных просто в Модели try { Tile.PaintTileInModel(rtreeColorAreas); } catch (System.Exception ex) { Logger.Log.Error(ex, "Tile.PaintTileInModel(rtreeColorAreas);"); } // Сброс блоков панелей Марки АР на панели марки СБ. ResetBlocks(); // Проверка чертежа Inspector.Clear(); CheckDrawing checkDrawing = new CheckDrawing(); checkDrawing.CheckForPaint(); if (Inspector.HasErrors) { throw new System.Exception("\nПокраска панелей не выполнена, в чертеже найдены ошибки в блоках панелей, см. выше."); } SelectionBlocks selBlocks = new SelectionBlocks(_db); selBlocks.SelectBlRefsInModel(StartOptions.SortPanels); // В чертеже не должно быть панелей марки АР if (selBlocks.IdsBlRefPanelAr.Count > 0) { Inspector.AddError($"Ошибка. При покраске в чертеже не должно быть блоков панелей марки АР. Найдено {selBlocks.IdsBlRefPanelAr.Count} блоков марки АР.", icon: System.Drawing.SystemIcons.Error); } Sections = Panels.Section.GetSections(selBlocks.SectionsBlRefs); // Определение покраски панелей. _marksSB = MarkSb.GetMarksSB(rtreeColorAreas, this, "Покраска панелей...", selBlocks.IdsBlRefPanelSb); if (_marksSB?.Count == 0) { throw new System.Exception("Не найдены блоки панелей в чертеже. Выполните команду AKR-Help для просмотра справки к программе."); } // Проверить всели плитки покрашены. Если есть непокрашенные плитки, то выдать сообщение об ошибке. if (Inspector.HasErrors) { throw new System.Exception("\nПокраска не выполнена, не все плитки покрашены. См. список непокрашенных плиток в форме ошибок."); } // Определение принадлежности блоков панелеи секциям Panels.Section.DefineSections(this); // Переименование марок АР панелей в соответствии с индексами архитекторов (Э2_Яр1) RenamePanelsToArchitectIndex(_marksSB); // Создание определений блоков панелей покраски МаркиАР CreatePanelsMarkAR(); // Замена вхождений блоков панелей Марки СБ на блоки панелей Марки АР. ReplaceBlocksMarkSbOnMarkAr(); //// Определение принадлежности блоков панелеи фасадам //Facade.DefineFacades(this); // Добавление подписей к панелям Caption caption = new Caption(_marksSB); caption.CaptionPanels(); }