public double Distance(GSColor color) { return(color.Distance(new GSColor( (byte)(Begin.R + (Begin.Distance(color) / Length * (End.R - Begin.R))), (byte)(Begin.G + (Begin.Distance(color) / Length * (End.G - Begin.G))), (byte)(Begin.B + (Begin.Distance(color) / Length * (End.B - Begin.B)))))); }
private void color_Delete(object sender, RoutedEventArgs e) { Button button = (Button)sender; DockPanel parent = (DockPanel)button.Parent; Border border = parent.Children.OfType <Border>().First(); byte offset = 0; foreach (Label label in parent.Children.OfType <Label>()) { byte.TryParse((string)label.Content, out offset); } GSColor color = new GSColor(((SolidColorBrush)border.Background).Color.R, ((SolidColorBrush)border.Background).Color.G, ((SolidColorBrush)border.Background).Color.B); colorList.RemoveAll(item => item.Pallet.Color.Equals(color) && item.Pallet.Pos == offset); colorIndex.Children.Clear(); colorList.ForEach(item => { colorIndex.Children.Add(item.Panel); }); UpdateGradation(); }
public static List <GSColor> MakeGradation(List <Pallet> palletList) { List <GSColor> colorList = new List <GSColor>(); for (int i = 1; i < palletList.Count; i++) { colorList.AddRange(GSColor.Gradation(palletList[i - 1].Color, palletList[i].Color, palletList[i].Pos)); } colorList.Add(palletList.Last().Color); return(colorList); }
public Pallet(GSColor color, byte pos = 0) { Color = color; Pos = pos; }
public ColorLine(GSColor begin, GSColor end) { Begin = begin; End = end; }
public ColorChunk(GSColor color, int count = 0) { Color = color; Count = count; }
public List <Pallet> GetKeyColorList() { List <GSColor> queue = new List <GSColor>(ColorList); List <GSColor> buffer = new List <GSColor>(); List <GSColor> lineColorList = new List <GSColor>(); GSColor begin = new GSColor(); GSColor end = new GSColor(); List <ColorLine> lineList = new List <ColorLine>(); int i; Stopwatch stopwatch = new Stopwatch(); Console.WriteLine("Getting key color data..."); stopwatch.Start(); ColorLine dummy = new ColorLine(queue[0], queue[1]); for (i = 0; i < queue.Count && !lineColorList.Any(); i++) { //1番目に数の多い色と2番目に数の多い色を通る直線を引く dummy = new ColorLine(queue[0], queue[i]); //その直線に近い点をすべてlineColorListに追加,queueから削除 lineColorList.AddRange(queue.FindAll(color => dummy.Distance(color) < CLOSENESS)); } queue.RemoveAll(color => lineColorList.Contains(color)); //その直線に近い点の中で,直線の端に近い点(影が一番長い)を始点,終点にする //影の長さでソート 降順? lineColorList = new List <GSColor>(lineColorList.OrderBy(color => dummy.Begin.Projection(dummy.End, color))); begin = lineColorList.First(); end = lineColorList.Last(); //直線をlineListに追加 lineList.Add(new ColorLine(begin, end)); int count = 0; while (queue.Any()) { //終点を始点にしてqueueの中で1番に遠い色を終点とする直線を引く dummy = new ColorLine(end, queue.OrderBy(color => end.Distance(color)).First()); //lineのBeginよりEnd側をlineColorListに追加 queue.OrderBy(color => dummy.Begin.Projection(dummy.End, color)); for (i = 0; i < queue.Count - 1; i++) { if (dummy.Begin.Projection(dummy.End, queue[i]) < 0) { break; } } lineColorList = new List <GSColor>(queue.GetRange(0, i)); Console.WriteLine("count: " + lineColorList.Count); //lineに近い点のみwaitListに追加,queueから削除 lineColorList = new List <GSColor>(lineColorList.OrderBy(color => - dummy.Distance(color))); for (i = 0; i < lineColorList.Count - 1; i++) { if (dummy.Distance(lineColorList[i]) >= CLOSENESS) { break; } } lineColorList.RemoveRange(i, lineColorList.Count - i); queue.RemoveAll(color => lineColorList.Contains(color)); Console.WriteLine("Count: " + lineColorList.Count); //その直線に近い点の中で,直線の端に近い点(影が一番長い)を終点にする始点は直線の始点 //影の長さでソート 降順? lineColorList = new List <GSColor>(lineColorList.OrderBy(color => dummy.Begin.Projection(dummy.End, color))); begin = dummy.Begin; try { end = lineColorList.Last(); } catch (Exception e) { Console.WriteLine(e.Message); } //直線をlineListに追加 lineList.Add(new ColorLine(begin, end)); count++; } //lineListの直線の長さの合計とそれぞれの直線の長さから長さの割合を出す //その割合に合わせてKeyColorListに追加 stopwatch.Stop(); Console.WriteLine("Key colors data was gotten successfully!"); Console.WriteLine("Elapsed: " + stopwatch.Elapsed.ToString()); Console.WriteLine("CaluculateTime: " + count.ToString()); double LengthSum = lineList.Sum(line => line.Length); List <Pallet> palletList = new List <Pallet>(); palletList.Add(new Pallet(lineList.First().Begin, 0)); lineList.ForEach(line => { Console.WriteLine((int)(line.Length / LengthSum * 255)); palletList.Add(new Pallet(line.End, (byte)(line.Length / LengthSum * 255))); }); return(palletList); }