public void makeBox() { Globals.GraphicsDevice.Textures[0] = null; Color[] colors = new Color[CellBorder.Width * CellBorder.Height]; CellBorder.GetData(colors); // left side for (int y = 0; y < CellBorder.Height; y++) { colors[y] = Color.Gray; } // right side for (int y = colors.Count() - 1; y > colors.Count() - CellBorder.Height; y--) { colors[y] = Color.Gray; } // Top for (int y = 0; y < colors.Count(); y = y + CellBorder.Height) { colors[y] = Color.Gray; } // Bottom for (int y = CellBorder.Height - 1; y < colors.Count(); y = y + CellBorder.Height) { colors[y] = Color.Gray; } CellBorder.SetData(colors); Globals.GraphicsDevice.Textures[0] = Textures.texture; }
void calculateRadius() { radiiSquared = new float[cols * rows]; int frameNo = 0; for (int y = 0; y < rows; ++y) { for (int x = 0; x < cols; ++x, ++frameNo) { radiiSquared[frameNo] = 0; if (Texture != null) { Rectangle dimension = this.dimension; dimension.X = this.dimension.Width * x; dimension.Y = this.dimension.Height * y; Color[] colors = new Color[dimension.Width * dimension.Height]; Texture.GetData <Color>(0, dimension, colors, 0, colors.Count()); Vector2 pos = new Vector2(0, 0); // Begin radius check loop for (int i = 0; pos.X < dimension.Width; ++pos.X) { for (pos.Y = 0; pos.Y < dimension.Height; ++pos.Y, ++i) { if (colors[i].A > 0) { radiiSquared[frameNo] = Math.Max(radiiSquared[frameNo], (pos - Origin).LengthSquared()); } } } } } } }
/// <summary> /// 将Grid对象转换为Bitmap /// </summary> /// <returns></returns> public Bitmap ToBitmap() { Bitmap gridBmp = new Bitmap(col, row); // 随机生成颜色数组 Color[] colors = new Color[21]; // 以时间为随机数种子,生成随机数 System.Random r = new Random(System.DateTime.Now.Second); System.Random g = new Random(System.DateTime.Now.Minute); System.Random b = new Random(System.DateTime.Now.Hour); // 保证宇宙多边形(以外)为透明 colors[0] = System.Drawing.Color.Transparent; // 生成随机颜色 for (int i = 1; i < colors.Count(); i++) { colors[i] = Color.FromArgb(r.Next(256), g.Next(256), b.Next(256)); //System.Console.Write(colors[i].ToString()); } //MessageBox.Show(colors[1].ToString() + '\n' + colors[2].ToString()); // 根据栅格阵列数据,填充位图 for (int i = 0; i < col * row; i++) { if (grid[i % col, row - i / col - 1] < 0) { gridBmp.SetPixel(i % col, row - i / col - 1, colors[20]); continue; } gridBmp.SetPixel(i % col, row - i / col - 1, colors[grid[i % col, row - i / col - 1] % 20]); } return(gridBmp); }
public MetricReportResultForm(MetricReport report) { InitializeComponent(); this.report = report; fromDateBox.Text = report.fromDate.ToShortDateString(); toDateBox.Text = report.toDate.ToShortDateString(); Color[] colors = new Color[] {Color.Red, Color.Blue, Color.Green, Color.Violet, Color.Cyan}; int i = 0; foreach (var record in report.data) { var metric = record.Key; var values = record.Value; var series = chart.Series.Add(metric.Name); series.BorderWidth = 2; series.ChartArea = chart.ChartAreas[0].Name; series.ChartType = SeriesChartType.Line; series.IsValueShownAsLabel = true; series.MarkerStyle = MarkerStyle.Circle; series.Color = colors[i]; i = (i + 1) % colors.Count(); foreach (var value in values) series.Points.AddXY(value.Date, value.Value); foreach (DataPoint p in series.Points) { p.MarkerStyle = MarkerStyle.Circle; p.MarkerSize = 5; } } }
/// <summary> /// Gets the average color of a particular stone from the center 8x8 square of its pixels. /// </summary> /// <param name="spriteIndex">Index of sprite to get color of from SDV object sprite sheet</param> /// <returns>average color of given sprite</returns> private static Color GetObjectSpriteAverageColor(int spriteIndex) { Color[] colors = new Color[8 * 8]; Game1.objectSpriteSheet.GetData(0, new Rectangle((spriteIndex % 24) * 16 + 4, (int)(spriteIndex / 24) * 16 + 4, 8, 8), colors, 0, 8 * 8); var average = new Color(Convert.ToByte(colors.Sum(c => c.R) / colors.Count()), Convert.ToByte(colors.Sum(c => c.G) / colors.Count()), Convert.ToByte(colors.Sum(c => c.B) / colors.Count())); return(average); }
public static Texture2D Fill(Texture2D img, Color fillColor) { Color[] data = new Color[img.Width * img.Height]; img.GetData(data); for (int i = 0; i < data.Count(); i++) { data[i] = fillColor; } img.SetData(data); return(img); }
private Texture2D CreateTexture() { var texture = new Texture2D(_device, _width, _height); var data = new Color[_width * _height]; for (int pixel = 0; pixel < data.Count(); pixel++) { data[pixel] = Color.Black * 0.7f; } texture.SetData(data); return(texture); }
public override void createTexture(GraphicsDevice graphics, Func <int, Color> paint) { this.texture = new Texture2D(graphics, (int)size.X, (int)size.Y); Color[] data = new Color[(int)size.X * (int)size.Y]; for (int pixel = 0; pixel < data.Count(); pixel++) { data[pixel] = paint(pixel); } this.texture.SetData(data); }
public static Texture2D CreateFlatTexture(GraphicsDevice graphicsDevice, int width, int height, Color color) { Texture2D t = new Texture2D(graphicsDevice, width, height); Color[] pixels = new Color[width * height]; for (int i = 0; i < pixels.Count(); i++) { pixels[i] = color; } t.SetData(pixels); return(t); }
public Texture2D CreateTexture(int width, int height, Func <int, Color> paint) { Texture2D texture = new Texture2D(graphics.GraphicsDevice, width, height); Color[] data = new Color[width * height]; for (int pixel = 0; pixel < data.Count(); pixel++) { data[pixel] = paint(pixel); } texture.SetData(data); return(texture); }
public static Texture2D GenerateTexture(GraphicsDevice device, int size, Color color) { Texture2D texture = new Texture2D(device, size, size); Color[] data = new Color[size * size]; for (int pixel = 0; pixel < data.Count(); pixel++) { data[pixel] = color; } texture.SetData(data); return(texture); }
public static Texture2D CreateTexture(GraphicsDevice device, int width, int height, Color color) { Texture2D texture = new Texture2D(device, width, height); Color[] data = new Color[width * height]; for (int pixel = 0; pixel < data.Count(); pixel++) { data[pixel] = color; } texture.SetData(data); return(texture); }
public static Texture2D CreateSolidColorTexture(int width, int height, Color paint) { Texture2D texture = new Texture2D(Pulsarc.Graphics.GraphicsDevice, width, height); Color[] data = new Color[width * height]; for (int pixel = 0; pixel < data.Count(); pixel++) { data[pixel] = paint; } texture.SetData(data); return(texture); }
public static void DrawRectangle(SpriteBatch spriteBatch, Rectangle rect, Color col) { Texture2D tex = new Texture2D(spriteBatch.GraphicsDevice, rect.Width, rect.Height); Color[] drawn = new Color[rect.Width * rect.Height]; for (int pixel = 0; pixel < drawn.Count(); pixel++) { drawn[pixel] = col; } tex.SetData(drawn); spriteBatch.Draw(tex, new Vector2(rect.X, rect.Y), col); }
private Texture CreateTexture(Device device, int width, int height, Func <int, Color> paint) { //initialize a texture Texture texture = new Texture(device, width, height, 0, Usage.None, Format.A8R8G8B8, Pool.Scratch); //the array holds the color for each pixel in the texture Color[] data = new Color[width * height]; for (int pixel = 0; pixel < data.Count(); pixel++) { //the function applies the color according to the specified pixel data[pixel] = paint(pixel); } //set the color // texture.Fill(data); return(texture); }
public static Texture2D CreateColoredTexture(Color paint) { //initialize a texture Texture2D texture = new Texture2D(Device, 1, 1); //the array holds the color for each pixel in the texture Color[] data = new Color[1 * 1]; for (int pixel = 0; pixel < data.Count(); pixel++) { //the function applies the color according to the specified pixel data[pixel] = paint; } //set the color texture.SetData(data); return(texture); }
public static Texture2D CreateTexture(GraphicsDevice device, int width, int height, Func <int, Color> paint) { //initialize a texture Texture2D texture = new Texture2D(device, width, height); //the array holds the color for each pixel in the texture Color[] data = new Color[width * height]; for (int pixel = 0; pixel < data.Count(); pixel++) { //the function applies the color according to the specified pixel data[pixel] = paint(pixel); } //set the color texture.SetData(data); return(texture); }
public static Texture2D CreateTextureHollow(GraphicsDevice device, int width, int height, Color brighter, Color darker, int bordersize = 10, int alpha = 255) { //initialize a texture Texture2D texture = new Texture2D(device, width, height); //the array holds the color for each pixel in the texture Color[] data = new Color[width * height]; for (int pixel = 0; pixel < data.Count(); pixel++) { //the function applies the color according to the specified pixel data[pixel] = NewSetColor(GetPosition(pixel, width, height), width, height, true, bordersize, alpha, brighter, darker); // data[pixel] = paint(pixel); } //set the color texture.SetData(data); return(texture); }
public override void start() { texture = new Texture2D(Game1.self.GraphicsDevice, Game1.self.GraphicsDevice.Viewport.Width, Game1.self.GraphicsDevice.Viewport.Height); numberOfGrays = 256; for (int i = 0; i < numberOfGrays; i++) { Rectangle grayArea = new Rectangle(i, 0, 1, texture.Height); Color[] gray = new Color[texture.Height]; for (int y = 0; y < texture.Height; y++) { gray[y] = new Color(i, i, i); } texture.SetData <Color>(0, grayArea, gray, 0, gray.Count()); } }
public UCmenu() { this.InitializeComponent(); //小按钮背景透明 _MenuANNIU_you.Background.Opacity = anniuTM; //大按钮色块颜色随机 Color[] D_Background = new Color[] { Color.FromArgb(255, 112, 181, 255), Color.FromArgb(255, 255, 246, 74), Color.FromArgb(255, 168, 255, 17), Color.FromArgb(255, 255, 112, 112), Color.FromArgb(255, 123, 124, 152), Color.FromArgb(255, 156, 179, 169), Color.FromArgb(255, 243, 193, 170), Color.FromArgb(255, 226, 146, 135), Color.FromArgb(255, 230, 64, 78), Color.FromArgb(255, 255, 166, 33) }; Random rd = new Random(DateTime.Now.Millisecond); int i = rd.Next(0, D_Background.Count() - 1); _MenuANNIU_zuo.Background = new SolidColorBrush(D_Background[i]); _MenuANNIU_zuo.Background.Opacity = zuoTM; //说明文字透明 _MenuANNIU_zhong.Background.Opacity = 0.001; //边框透明 _biankuang.Background.Opacity = 0.05; }
public Classifier(int index, List <Color> usedColors, Color[] row) { Index = index; var colorRow = new Color[row.Length]; for (int i = 0; i < row.Length; i++) { colorRow[i] = row[i]; } foreach (Color color in usedColors) { var count = colorRow.Count(c => c == color); var firstIndex = Array.IndexOf(colorRow, color); var lastIndex = Array.LastIndexOf(colorRow, color); var isConnected = (lastIndex - firstIndex + 1) - count == 0; Colors.Add(new ColorClassifier { Count = count, MyColor = color, IsConnected = isConnected }); } }
public Graph(SpriteBatch spriteBatch, SpriteFont font) { //Create the white background of the graph backGround = new Texture2D(spriteBatch.GraphicsDevice, size, size, false, SurfaceFormat.Color); Color[] data = new Color[size * size]; for (int pixel = 0; pixel < data.Count(); pixel++) { data[pixel] = Color.White; } backGround.SetData(data); this.font = font; //Create random colors for each angle color = new Color[Global.A.Count()]; Random rand = new Random(); for (int i = 0; i < color.Length; i++) { color[i] = new Color(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)); } }
public static Texture2D CreateTexture(GraphicsDevice device, int width, int height, Func <int, Color> paint, Shapes shape) { //initialize a texture Texture2D texture = new Texture2D(device, width, height); //the array holds the color for each pixel in the texture Color[] data = new Color[width * height]; switch (shape) { case Shapes.CIRCLE: for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { double distance = Math.Sqrt(Math.Pow(i - height / 2, 2) + Math.Pow(j - width / 2, 2)); if (distance <= width / 2.0) { data[width * i + j] = paint(width * i + j); } } } break; case Shapes.RECTANGLE: for (int pixel = 0; pixel < data.Count(); pixel++) { //the function applies the color according to the specified pixel data[pixel] = paint(pixel); } break; } //set the color texture.SetData(data); return(texture); }
private void ShadeSortFilter(object sender, EventArgs e) { if (pbBild.Image == null) { return; } //Problems: When the shades are sorted the heap sort leaves weird artifacting in the image //take any image and then sort the pixels by brightness for a cool visualisation Bitmap picture = GetCurrentImage(); Color[] allPixels = new Color[picture.Width * picture.Height]; int[] colorValue = new int[allPixels.Count()]; for (int y = 0, whichPixel = 0; y < picture.Height; y++) { for (int x = 0; x < picture.Width; x++, whichPixel++) { allPixels[whichPixel] = picture.GetPixel(x, y); } } //theory: using reference with heap sort is the most memory efficent because it doesn't create a new array and heapsort is an in-place sorting algorithm which makes it use even less space ShadeHeapSort(ref allPixels); //draws image for (int y = 0, whichPixel = 0; y < picture.Height; y++) { for (int x = 0; x < picture.Width; x++, whichPixel++) { picture.SetPixel(x, y, allPixels[whichPixel]); } } pbBild.Image = picture; }
public override void RenderPreview(Bitmap output, Action<int> progressCallback) { //for (int y = 0; y < height; y++) { var pixels = new Color[Width * Height]; #if PL Parallel.For(0, Height, y => #else for (int y = 0; y < height; y++) #endif { for (int x = 0; x < Width; x++) { IRay ray; camera.GetRay(x, y, out ray); var pixelColor = Trace((RayInfo) ray, 1.0f, Air, 0); pixels[x + y * Width] = pixelColor.ToColor(); } //Console.Write("{0}->", height / (y+1) ); } #if PL ); #endif Console.WriteLine("{0} Non black pixels", pixels.Count(item => (item.R > 0 || item.G > 0 || item.B > 0))); Console.WriteLine("{0} Triangles", scene.Vertices.Length / 3); Console.WriteLine("{0} Intersections", Intersections); Console.WriteLine("{0} Rays traced", RaysTraced); Console.WriteLine("Splatting"); for (int y = 0; y < Height; y++) for (int x = 0; x < Width; x++) { output.SetPixel(x, y, pixels[x + (Height - 1 - y) * Width]); } }
void buildview() { Color[] colors = new Color[] { Colors.Red, Colors.Cyan, Colors.Yellow, Colors.Lime, Colors.Blue, Colors.Purple }; int idx = 0; foreach (var item in year.projects) { item.color = colors[idx % colors.Count()]; PAllPrj prj = new PAllPrj() { name = item.name, note = item.note, isSelected = idx == 0, idx = idx, color = item.color, Tag = item }; if (idx == 0) { selprj = prj; } prj.projectChanged += new EventHandler(prj_projectChanged); prjviews.Add(prj); grdMain.Children.Add(prj); idx++; } }
private void ColorSortFilter(object sender, EventArgs e) { if (pbBild.Image == null) { return; } //Problems: Has issues with black so it makes it stick with the red because black has he same hue as red but bottomed brightness //take any image and then sort the pixels from red, green and then blue for a cool visualisation Bitmap picture = GetCurrentImage(); Color[] allPixels = new Color[picture.Width * picture.Height]; int[] colorValue = new int[allPixels.Count()]; for (int y = 0, whichPixel = 0; y < picture.Height; y++) { for (int x = 0; x < picture.Width; x++, whichPixel++) { allPixels[whichPixel] = picture.GetPixel(x, y); } } //theory: using reference with heap sort is the most memory efficent because it doesn't create a new array and heapsort is an in-place sorting algorithm which makes it use even less space ColorHeapSort(ref allPixels); //draws image for (int y = 0, whichPixel = 0; y < picture.Height; y++) { for (int x = 0; x < picture.Width; x++, whichPixel++) { picture.SetPixel(x, y, allPixels[whichPixel]); } } pbBild.Image = picture; }
public static Texture2D CreateTexture(GraphicsDevice device, int width, int height) { //initialize a texture Random rndRandom = new Random(); Texture2D texture = new Texture2D(device, width, height); //the array holds the color for each pixel in the texture Color[] data = new Color[width * height]; Color empty = new Color(); int colorRange = 5; int startMin = 0; int startMax = 255; double minAddition = 2.56; double maxAddition = 1; for (int pixel = 0; pixel < data.Count(); pixel++) { //the function applies the color according to the specified pixel if (pixel % width > 0 && data[pixel - 1] != empty) { if (pixel - width > 0 && data[pixel - width] != empty) // inside { if (pixel - 2 * width > 0 && data[pixel - 2 * width] != empty && (pixel - 2) % width > 0) // further rows inside { Color cl = new Color( rndRandom.Next((int)Math.Round((data[pixel - 1].R + data[pixel - width].R + data[pixel - 2].R + data[pixel - 2 * width].R + minAddition) / 4.0f - colorRange), (int)Math.Round((data[pixel - 1].R + data[pixel - width].R + data[pixel - 2].R + data[pixel - 2 * width].R + maxAddition) / 4.0f + colorRange)), rndRandom.Next((int)Math.Round((data[pixel - 1].G + data[pixel - width].G + data[pixel - 2].G + data[pixel - 2 * width].G + minAddition) / 4.0f - colorRange), (int)Math.Round((data[pixel - 1].G + data[pixel - width].G + data[pixel - 2].G + data[pixel - 2 * width].G + maxAddition) / 4.0f + colorRange)), rndRandom.Next((int)Math.Round((data[pixel - 1].B + data[pixel - width].B + data[pixel - 2].B + data[pixel - 2 * width].B + minAddition) / 4.0f - colorRange), (int)Math.Round((data[pixel - 1].B + data[pixel - width].B + data[pixel - 2].B + data[pixel - 2 * width].B + maxAddition) / 4.0f + colorRange))) ; data[pixel] = cl; } else // first row inside { Color cl = new Color( rndRandom.Next((int)Math.Floor((data[pixel - 1].R + data[pixel - width].R) / 2.0f - colorRange), (int)Math.Ceiling((data[pixel - 1].R + data[pixel - width].R) / 2.0f + colorRange)), rndRandom.Next((int)Math.Floor((data[pixel - 1].G + data[pixel - width].G) / 2.0f - colorRange), (int)Math.Ceiling((data[pixel - 1].G + data[pixel - width].G) / 2.0f + colorRange)), rndRandom.Next((int)Math.Floor((data[pixel - 1].B + data[pixel - width].B) / 2.0f - colorRange), (int)Math.Ceiling((data[pixel - 1].B + data[pixel - width].B) / 2.0f + colorRange))) ; data[pixel] = cl; } } else // top edge { Color cl = new Color( rndRandom.Next(data[pixel - 1].R - colorRange, data[pixel - 1].R + colorRange), rndRandom.Next(data[pixel - 1].G - colorRange, data[pixel - 1].G + colorRange), rndRandom.Next(data[pixel - 1].B - colorRange, data[pixel - 1].B + colorRange) ); data[pixel] = cl; } } else if (pixel - width >= 0 && data[pixel - width] != empty) // left edge { Color cl = new Color( rndRandom.Next((data[pixel - width].R) - colorRange, (data[pixel - width].R) + colorRange), rndRandom.Next((data[pixel - width].G) - colorRange, (data[pixel - width].G) + colorRange), rndRandom.Next((data[pixel - width].B) - colorRange, (data[pixel - width].B) + colorRange)); data[pixel] = cl; } else // first pixel { Color cl = new Color(rndRandom.Next(startMin, startMax), rndRandom.Next(startMin, startMax), rndRandom.Next(startMin, startMax)); data[pixel] = cl; } // data[pixel] = paint(pixel); } //set the color texture.SetData(data); return(texture); }
void calculateRadius() { radiiSquared = new float[cols * rows]; int frameNo = 0; for (int y = 0; y < rows; ++y) { for (int x = 0; x < cols; ++x, ++frameNo) { radiiSquared[frameNo] = 0; if (Texture != null) { Rectangle dimension = this.dimension; dimension.X = this.dimension.Width * x; dimension.Y = this.dimension.Height * y; Color[] colors = new Color[dimension.Width * dimension.Height]; Texture.GetData<Color>(0, dimension, colors, 0, colors.Count()); Vector2 pos = new Vector2(0, 0); // Begin radius check loop for (int i = 0; pos.X < dimension.Width; ++pos.X) for (pos.Y = 0; pos.Y < dimension.Height; ++pos.Y, ++i) { if (colors[i].A > 0) radiiSquared[frameNo] = Math.Max(radiiSquared[frameNo], (pos - Origin).LengthSquared()); } } } } }
//Create the Graph and configure is proprties private void CreateGraph(ZedGraphControl zgc) { GraphPane myPane = zgc.GraphPane; List <ThresholdItem> listCurrentThresholds = this.ReadFromDBThresholdType(cmbBoxDeviceType.SelectedItem.ToString()); // Set the titles and axis labels per selection myPane.Title.Text = cmbBoxDeviceType.GetItemText(cmbBoxDeviceType.SelectedItem); myPane.XAxis.Title.Text = "Thresholds"; myPane.YAxis.Title.Text = ""; myPane.CurveList.Clear();// clear the graph for (int i = 0; i < listCurrentThresholds.Count(); ++i) { ThresholdItem item = listCurrentThresholds[i]; item.name = item.name.Replace(" ", String.Empty);//remove whitespaces LineItem myLine = new LineItem(item.name + "Threshold", new double[] { ((float)(i * 2 + 1)) / (listCurrentThresholds.Count() * 2) - (1.0 / (listCurrentThresholds.Count() * 2 + 1)), ((float)(i * 2 + 1)) / (listCurrentThresholds.Count() * 2) + (1.0 / (listCurrentThresholds.Count() * 2 + 1)) }, new double[] { item.value, item.value }, Color.Black, SymbolType.Diamond, 3.0f); myLine.IsX2Axis = true; myPane.CurveList.Add(myLine); } List <BarItem> listBarItems = new List <BarItem>(); //Create Random colors to show on Graph Color[] barColors = new Color[] { //set of orange Color.FromArgb(49, 130, 189), Color.FromArgb(49, 163, 84), Color.FromArgb(99, 99, 99), Color.Azure, Color.Bisque, Color.Coral, Color.Crimson, Color.ForestGreen, Color.Lavender, Color.Navy }; for (int idx = 0; idx < listDevices.SelectedItems.Count; ++idx) { DeviceItem currDevice = (DeviceItem)listDevices.SelectedItems[idx]; String currDeviceName = currDevice.name; //Get one point for each threshold according to the device type. PointPairList listDeviceValues = GetDeviceData(listCurrentThresholds, currDevice.id); //use this to add line width 3.0F BarItem myCurve = new BarItem(currDeviceName, listDeviceValues, barColors[idx % barColors.Count()]); listBarItems.Add(myCurve); } for (int idx = 0; idx < listCurrentThresholds.Count(); ++idx) { ThresholdItem item = listCurrentThresholds[idx]; item.name = item.name.Replace(" ", String.Empty);//remove whitespaces //myPane.CurveList.Average try { double avg = listBarItems.Where(v => v.Points.Count > idx) .Select(v => v.Points[idx].Y).Average(); double stdDev = Math.Sqrt(listBarItems.Where(v => v.Points.Count > idx) .Select(v => v.Points[idx].Y) .Average(v => Math.Pow(v - avg, 2))); //MessageBox.Show("i:" + idx + " stdDev: " + stdDev); LineItem myLine = new LineItem(item.name + "Deviation", new double[] { ((float)(idx * 2 + 1)) / (listCurrentThresholds.Count() * 2) - (1.0 / (listCurrentThresholds.Count() * 2 + 1)), ((float)(idx * 2 + 1)) / (listCurrentThresholds.Count() * 2) + (1.0 / (listCurrentThresholds.Count() * 2 + 1)) }, new double[] { stdDev, stdDev }, Color.FromArgb(240, 59, 32), SymbolType.Diamond, 3.0f); myLine.IsX2Axis = true; myPane.CurveList.Add(myLine); } catch (InvalidOperationException) { } catch (NullReferenceException) { } } myPane.CurveList.AddRange(listBarItems); // Fill the axis background with a color gradient myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45F); // Fill the pane background with a color gradient myPane.Fill = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45F); //This informs ZedGraph to use the labels supplied by the user in Axis.Scale.TextLabels //Axis.Default.Type = AxisType.Text; //Show tooltips when the mouse hovers over a point zgc.IsShowPointValues = true; zgc.PointValueEvent += new ZedGraphControl.PointValueHandler(MyPointValueHandler); // Set the XAxis to date type myPane.XAxis.Type = AxisType.Text; string[] thresholdNames = new string[listCurrentThresholds.Count]; for (int i = 0; i < thresholdNames.Count(); ++i) { thresholdNames[i] = listCurrentThresholds[i].name; } myPane.XAxis.Scale.TextLabels = thresholdNames; myPane.XAxis.IsVisible = true; myPane.X2Axis.Scale.Min = 0; myPane.X2Axis.Scale.Max = 1; myPane.X2Axis.IsVisible = false; myPane.YAxis.MajorGrid.IsVisible = true; myPane.YAxis.MinorGrid.IsVisible = true; // Calculate the Axis Scale Ranges axisChangeZedGraph(zgc); //refrsh the graph }
private void AbsoluteColorFilter(object sender, EventArgs e) { if (pbBild.Image == null) { return; } //Set every pixel to their absolute RGB color Bitmap picture = GetCurrentImage(); Color[] allPixels = new Color[picture.Width * picture.Height]; //gets every pixel for (int y = 0, whichPixel = 0; y < picture.Height; y++) { for (int x = 0; x < picture.Width; x++, whichPixel++) { allPixels[whichPixel] = picture.GetPixel(x, y); } } //processes every pixel for (int i = 0; i < allPixels.Count(); i++) { //red if (allPixels[i].GetHue() >= 0 && allPixels[i].GetHue() < 30) { allPixels[i] = Color.Red; } //orange else if (allPixels[i].GetHue() >= 30 && allPixels[i].GetHue() < 60) { allPixels[i] = Color.Orange; } //yellow else if (allPixels[i].GetHue() >= 60 && allPixels[i].GetHue() < 90) { allPixels[i] = Color.Yellow; } //lime else if (allPixels[i].GetHue() >= 90 && allPixels[i].GetHue() < 120) { allPixels[i] = Color.Lime; } //green else if (allPixels[i].GetHue() >= 120 && allPixels[i].GetHue() < 150) { allPixels[i] = Color.Green; } //cyan else if (allPixels[i].GetHue() >= 150 && allPixels[i].GetHue() < 180) { allPixels[i] = Color.Cyan; } //lightblue else if (allPixels[i].GetHue() >= 180 && allPixels[i].GetHue() < 210) { allPixels[i] = Color.LightBlue; } //turquise else if (allPixels[i].GetHue() >= 210 && allPixels[i].GetHue() < 240) { allPixels[i] = Color.Turquoise; } //blue else if (allPixels[i].GetHue() >= 240 && allPixels[i].GetHue() < 270) { allPixels[i] = Color.Blue; } //purple else if (allPixels[i].GetHue() >= 270 && allPixels[i].GetHue() < 300) { allPixels[i] = Color.Purple; } //magenta else if (allPixels[i].GetHue() >= 300 && allPixels[i].GetHue() < 330) { allPixels[i] = Color.Magenta; } //pink else if (allPixels[i].GetHue() >= 330 && allPixels[i].GetHue() < 360) { allPixels[i] = Color.Pink; } } //draws image for (int y = 0, whichPixel = 0; y < picture.Height; y++) { for (int x = 0; x < picture.Width; x++, whichPixel++) { picture.SetPixel(x, y, allPixels[whichPixel]); } } pbBild.Image = picture; }
public static Display ByPointsColors([KeepReferenceAttribute]Point[] points, Color[] colors) { if(points == null) { throw new ArgumentNullException("points"); } if (!points.Any()) { throw new ArgumentException(Resources.NoVertexExceptionMessage, "points"); } if (points.Count() %3 != 0) { throw new ArgumentException(Resources.VerticesDivisibleByThreeExceptionMessage); } if(colors == null) { throw new ArgumentNullException("colors"); } if (!colors.Any()) { throw new ArgumentException(Resources.NoColorsExceptionMessage, "colors"); } if (colors.Count() != points.Count()) { throw new ArgumentException(Resources.VertexColorCountMismatchExceptionMessage, "colors"); } return new Display(points, colors); }
public Texture2D CreateMazeTexture() { var texWidth = Width * 6 + 1; var texHeight = Height * 6 + 1; Texture2D texture = new Texture2D(Main.Instance.GraphicsDevice, texWidth, texHeight); Color[] data = new Color[texWidth * texHeight]; // Set background black for (int pixel = 0; pixel < data.Count(); pixel++) { data[pixel] = Color.Black; } var wallColour = Color.DarkOrange; for (int i = 0; i < texWidth; i++) { data[i] = wallColour; data[PositionHelper.Convert2Dto1D(i, texHeight - 1, texWidth)] = wallColour; } for (int i = 0; i < texHeight; i++) { data[PositionHelper.Convert2Dto1D(0, i, texWidth)] = wallColour; data[PositionHelper.Convert2Dto1D(texWidth - 1, i, texWidth)] = wallColour; } for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { var cell = Maze[P(x, y)]; if (!cell.East.HasValue) { data[PositionHelper.Convert2Dto1D(x * 6 + 6, y * 6, texWidth)] = wallColour; data[PositionHelper.Convert2Dto1D(x * 6 + 6, y * 6 + 1, texWidth)] = wallColour; data[PositionHelper.Convert2Dto1D(x * 6 + 6, y * 6 + 2, texWidth)] = wallColour; data[PositionHelper.Convert2Dto1D(x * 6 + 6, y * 6 + 3, texWidth)] = wallColour; data[PositionHelper.Convert2Dto1D(x * 6 + 6, y * 6 + 4, texWidth)] = wallColour; data[PositionHelper.Convert2Dto1D(x * 6 + 6, y * 6 + 5, texWidth)] = wallColour; } if (!cell.South.HasValue) { data[PositionHelper.Convert2Dto1D(x * 6, y * 6 + 6, texWidth)] = wallColour; data[PositionHelper.Convert2Dto1D(x * 6 + 1, y * 6 + 6, texWidth)] = wallColour; data[PositionHelper.Convert2Dto1D(x * 6 + 2, y * 6 + 6, texWidth)] = wallColour; data[PositionHelper.Convert2Dto1D(x * 6 + 3, y * 6 + 6, texWidth)] = wallColour; data[PositionHelper.Convert2Dto1D(x * 6 + 4, y * 6 + 6, texWidth)] = wallColour; data[PositionHelper.Convert2Dto1D(x * 6 + 5, y * 6 + 6, texWidth)] = wallColour; } if (!cell.East.HasValue || !cell.South.HasValue) { data[PositionHelper.Convert2Dto1D(x * 6 + 6, y * 6 + 6, texWidth)] = wallColour; } } } texture.SetData(data); return(texture); }
/// <summary> /// Stamp the alpha values from one sprite onto another sprite /// </summary> /// <param name="transformA">World transform of the first sprite.</param> /// <param name="widthA">Width of the first sprite's texture.</param> /// <param name="heightA">Height of the first sprite's texture.</param> /// <param name="dataA">Pixel color data of the first sprite.</param> /// <param name="transformB">World transform of the second sprite.</param> /// <param name="widthB">Width of the second sprite's texture.</param> /// <param name="heightB">Height of the second sprite's texture.</param> /// <param name="dataB">Pixel color data of the second sprite.</param> private static Color[] StampAlpha( Matrix transformA, int widthA, int heightA, Color[] dataA, Matrix transformB, int widthB, int heightB, Color[] dataB, bool Invert) { Color[] newPixels = new Color[dataA.Count()]; // Calculate a matrix which transforms from A's local space into // world space and then into B's local space Matrix transformAToB = transformA * Matrix.Invert(transformB); /* Vector3 scale; Quaternion rotation; Vector3 translation; transformAToB.Decompose(out scale, out rotation, out translation); */ //transformAToB = Matrix.CreateScale(scale) * Matrix.CreateRotationZ(rotation.Z) * Matrix.CreateTranslation(translation); // When a point moves in A's local space, it moves in B's local space with a // fixed direction and distance proportional to the movement in A. // This algorithm steps through A one pixel at a time along A's X and Y axes // Calculate the analogous steps in B: Vector2 stepX = Vector2.TransformNormal(Vector2.UnitX, transformAToB); Vector2 stepY = Vector2.TransformNormal(Vector2.UnitY, transformAToB); // Calculate the top left corner of A in B's local space // This variable will be reused to keep track of the start of each row Vector2 yPosInB = Vector2.Transform(Vector2.Zero, transformAToB); // For each row of pixels in A for (int yA = 0; yA < heightA; yA++) { // Start at the beginning of the row Vector2 posInB = yPosInB; // For each pixel in this row for (int xA = 0; xA < widthA; xA++) { // Round to the nearest pixel int xB = (int)Math.Round(posInB.X); int yB = (int)Math.Round(posInB.Y); int indexA = xA + ((heightA - yA - 1) * widthA); Color colorA = dataA[indexA]; // If the pixel lies within the bounds of B if (0 <= xB && xB < widthB && 0 <= yB && yB < heightB) { // Get the colors of the overlapping pixels Color colorB = dataB[xB + ((heightB - yB - 1) * widthB)]; byte alpha = colorA.A; byte alphaB = colorB.A; if (Invert) { alphaB = (byte)(0xff - alphaB); } alpha = (byte)(Math.Max(0, alpha - alphaB)); // newPixels[indexA] = colorB; newPixels[indexA] = colorA *(alpha / 255f); } else { if (Invert) { newPixels[indexA] = Color.Transparent; } else { newPixels[indexA] = colorA; } } // Move to the next pixel in the row posInB += stepX; } // Move to the next row yPosInB += stepY; } return newPixels; }
public void LoadContent(ContentManager content, string filename, Color boundingColor, float layer) { #region Getting Colors Texture2D tex = content.Load<Texture2D>(filename); Color[] data = new Color[tex.Width * tex.Height]; tex.GetData<Color>(data); //Get the data in 2D array form Color[,] colors = new Color[tex.Width, tex.Height]; int z = 0; for (int y = 0; y < tex.Height; y++) { for (int x = 0; x < tex.Width; x++, z++) { colors[x, y] = data[z]; } } #endregion Getting Colors #region Getting Rectangles int y1 = 1; int x1 = 1; int rectCount = 0; int lastXBound = 0; int nextXBound = 0; int height = tex.Height - 2; Rectangle[] rects = new Rectangle[41]; while (rectCount < rects.Count()) { while (colors[x1, 1] != boundingColor) { x1++; } nextXBound = x1; Rectangle rect = new Rectangle(lastXBound + 1, y1, nextXBound - lastXBound - 1, height); rects[rectCount] = rect; rectCount++; lastXBound = nextXBound; x1++; } #endregion Getting Rectangles #region Removing Source Rectangles for (int j = 0; j < data.Count(); j++) { if (data[j] == boundingColor) { data[j] = new Color(0, 0, 0, 0); } } texture = new Texture2D(ScreenHelper.GraphicsDevice, tex.Width, tex.Height); texture.SetData<Color>(data); #endregion Removing Source Rectangles #region Adding chars int charNext = 65; int i = 0; while (charNext <= 90) { letters.Add((char)charNext++, rects[i++]); } charNext = 49; while (charNext <= 57) { letters.Add((char)charNext++, rects[i++]); } letters.Add('0', rects[i++]); letters.Add('%', rects[i++]); letters.Add(':', rects[i++]); letters.Add('!', rects[i++]); letters.Add('?', rects[i++]); letters.Add('.', rects[i]); #endregion Adding chars Layer = layer; }