private void AllocateNodes() { zoom.Zoom = 1; zoom.Offset = new Point(0, 0); // Fill a sparse grid of rectangular color palette nodes with each tile being 50x30. // with hue across x-axis and saturation on y-axis, brightness is fixed at 100; Random r = new Random(Environment.TickCount); grid.VirtualChildren.Clear(); double w = _tileWidth + _tileMargin; double h = _tileHeight + _tileMargin; int count = (rows * cols) / 20; double width = (w * (cols - 1)); double height = (h * (rows - 1)); while (count > 0) { double x = r.NextDouble() * width; double y = r.NextDouble() * height; Point pos = new Point(_tileMargin + x, _tileMargin + y); Size s = new Size(r.Next((int)_tileWidth, (int)_tileWidth * 5), r.Next((int)_tileHeight, (int)_tileHeight * 5)); TestShapeType type = (TestShapeType)r.Next(0, (int)TestShapeType.Last); //Color color = HlsColor.ColorFromHLS((x * 240) / cols, 100, 240 - ((y * 240) / rows)); TestShape shape = new TestShape(new Rect(pos, s), type, r); SetRandomBrushes(shape, r); grid.AddVirtualChild(shape); count--; } }
public TestShape(Rect bounds, TestShapeType s, Random r) { _bounds = bounds; _shape = s; if (s == TestShapeType.Curve) { _bounds.Width *= 2; _bounds.Height *= 2; _points = new Point[3]; bounds = new Rect(0, 0, _bounds.Width, _bounds.Height); switch (r.Next(0, 8)) { case 0: _points[0] = bounds.TopLeft; _points[1] = bounds.TopRight; _points[2] = bounds.BottomRight; break; case 1: _points[0] = bounds.TopRight; _points[1] = bounds.BottomRight; _points[2] = bounds.BottomLeft; break; case 2: _points[0] = bounds.BottomRight; _points[1] = bounds.BottomLeft; _points[2] = bounds.TopLeft; break; case 3: _points[0] = bounds.BottomLeft; _points[1] = bounds.TopLeft; _points[2] = bounds.TopRight; break; case 4: _points[0] = bounds.TopLeft; _points[1] = new Point(bounds.Right, bounds.Height / 2); _points[2] = bounds.BottomLeft; break; case 5: _points[0] = bounds.TopRight; _points[1] = new Point(bounds.Left, bounds.Height / 2); _points[2] = bounds.BottomRight; break; case 6: _points[0] = bounds.TopLeft; _points[1] = new Point(bounds.Width / 2, bounds.Bottom); _points[2] = bounds.TopRight; break; case 7: _points[0] = bounds.BottomLeft; _points[1] = new Point(bounds.Width / 2, bounds.Top); _points[2] = bounds.BottomRight; break; } } }