Example #1
1
		public static int[] CreateDottedImage(int width, int height)
		{
			Random rnd = new Random();
			const int pointsNum = 100000;
			const double radius = 1.5;

			var randomPoints = Enumerable.Range(0, pointsNum).Select(_ => new Point(rnd.NextDouble() * width, rnd.NextDouble() * height));
			randomPoints = Filter(randomPoints, radius);

			DrawingGroup drawing = new DrawingGroup();
			var dc = drawing.Append();
			foreach (var point in randomPoints)
			{
				HsbColor color = new HsbColor(0, 0, Math.Round(5 * rnd.NextDouble()) / 4);
				SolidColorBrush brush = new SolidColorBrush(color.ToArgbColor());

				//drawing.Children.Add(new GeometryDrawing(brush, null, new EllipseGeometry(point, radius, radius)));
				dc.DrawEllipse(brush, null, point, radius, radius);
			}
			dc.Close();

			DrawingImage drawingImage = new DrawingImage();
			drawingImage.Drawing = drawing;
			drawingImage.Freeze();

			if ((imageCreatingThread.ThreadState | ThreadState.Running) != imageCreatingThread.ThreadState)
				imageCreatingThread.Start();
			imageQueue.Add(new RequestInfo { Width = width, Heigth = height, DrawingImage = drawingImage });
			var pixels = resultQueue.Take();

			return pixels;
		}
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            AddRandomPoint();
            AddRandomPoint();
            AddRandomPoint();

            // these are functions that sets different properties of drawn ellipses;
            // these functions can be replaced by real, non-demo ones.
            chart.AddPropertyBindingForNamedPart <Point>("ellipse", Ellipse.FillProperty, p =>
            {
                double hue = Math.Sin(1000 * (p.X + p.Y)) * 180 + 180;
                var color  = new HsbColor(hue, 0.2, 1);
                return(new SolidColorBrush(color.ToArgbColor()).MakeTransparent(0.7));
            });
            chart.AddPropertyBindingForNamedPart <Point>("ellipse", Ellipse.StrokeProperty, p =>
            {
                double hue = Math.Sin(1000 * (p.X + p.Y)) * 180 + 180;
                var color  = new HsbColor(hue, 1, 1);
                return(new SolidColorBrush(color.ToArgbColor()));
            });
            chart.AddPropertyBindingForNamedPart <Point>("ellipse", Ellipse.RenderTransformProperty, p => new RotateTransform(120 * Math.Atan2(p.Y, p.X)));
            chart.AddPropertyBinding <Point>(ViewportPanel.ViewportWidthProperty, p => 0.2 * Math.Abs(Math.Sin(p.X)));
            chart.AddPropertyBinding <Point>(ViewportPanel.ViewportHeightProperty, p => 0.2 * Math.Abs(Math.Cos(p.X)));

            DataContext = points;
        }
Example #3
0
        private static void ChangeFill(Ellipse ellipse, double sign)
        {
            Color    fill = ((SolidColorBrush)ellipse.Fill).Color;
            HsbColor hsb  = fill.ToHsbColor();

            hsb.Hue = (hsb.Hue + sign * 70) % 360;
            Color newColor = hsb.ToArgbColor();

            if (newColor.A == 0 || (newColor.R == 0 && newColor.G == 0 && newColor.B == 0))
            {
                Debugger.Break();
            }

            var brush = new SolidColorBrush(newColor);

            ellipse.Fill = brush;
        }
        public Color GetColor(double t)
        {
            Verify.AssertIsFinite(t);
            Verify.IsTrue(0 <= t && t <= 1);

            if (t <= 0)
            {
                return(colors[0]);
            }
            else if (t >= 1)
            {
                return(colors[colors.Count - 1]);
            }
            else
            {
                int i = 0;
                while (points[i] < t)
                {
                    i++;
                }

                double ratio = (points[i] - t) / (points[i] - points[i - 1]);

                Verify.IsTrue(0 <= ratio && ratio <= 1);

                Color c0  = colors[i - 1];
                Color c1  = colors[i];
                Color res = Color.FromRgb(
                    (byte)(c0.R * ratio + c1.R * (1 - ratio)),
                    (byte)(c0.G * ratio + c1.G * (1 - ratio)),
                    (byte)(c0.B * ratio + c1.B * (1 - ratio)));

                // Increasing saturation and brightness
                if (increaseBrightness)
                {
                    HsbColor hsb = res.ToHsbColor();
                    //hsb.Saturation = 0.5 * (1 + hsb.Saturation);
                    hsb.Brightness = 0.5 * (1 + hsb.Brightness);
                    return(hsb.ToArgbColor());
                }
                else
                {
                    return(res);
                }
            }
        }
Example #5
0
        public static int[] CreateDottedImage(int width, int height)
        {
            Random       rnd       = new Random();
            const int    pointsNum = 100000;
            const double radius    = 1.5;

            var randomPoints = Enumerable.Range(0, pointsNum).Select(_ => new Point(rnd.NextDouble() * width, rnd.NextDouble() * height));

            randomPoints = Filter(randomPoints, radius);

            DrawingGroup drawing = new DrawingGroup();
            var          dc      = drawing.Append();

            foreach (var point in randomPoints)
            {
                HsbColor        color = new HsbColor(0, 0, Math.Round(5 * rnd.NextDouble()) / 4);
                SolidColorBrush brush = new SolidColorBrush(color.ToArgbColor());

                //drawing.Children.Add(new GeometryDrawing(brush, null, new EllipseGeometry(point, radius, radius)));
                dc.DrawEllipse(brush, null, point, radius, radius);
            }
            dc.Close();

            DrawingImage drawingImage = new DrawingImage();

            drawingImage.Drawing = drawing;
            drawingImage.Freeze();

            if ((imageCreatingThread.ThreadState | ThreadState.Running) != imageCreatingThread.ThreadState)
            {
                imageCreatingThread.Start();
            }
            imageQueue.Add(new RequestInfo {
                Width = width, Heigth = height, DrawingImage = drawingImage
            });
            var pixels = resultQueue.Take();

            return(pixels);
        }