/// <summary> /// Draw the space /// </summary> private void RenderGrid() { fLines = new DynamicPrimitiveLine(GraphicsDevice); float worldFactor = WORLD_SIZE / (WORLD_BLOCKS - 1); VertexPositionColor p1; VertexPositionColor p2; for (int x = 0; x < WORLD_BLOCKS; x++) { float sx1 = (x + 0.5f) * worldFactor - HALF_WORLD_SIZE; for (int y = 0; y < WORLD_BLOCKS; y++) { float sy1 = (y + 0.5f) * worldFactor - HALF_WORLD_SIZE; for (int z = 0; z < WORLD_BLOCKS; z++) { float sz1 = (z + 0.5f) * worldFactor - HALF_WORLD_SIZE; float dx = 1024 * (fSpace[x, y, z].ForcePositiveX - fSpace[x, y, z].ForceNegativeX); float dy = 1024 * (fSpace[x, y, z].ForcePositiveY - fSpace[x, y, z].ForceNegativeY); float dz = 1024 * (fSpace[x, y, z].ForcePositiveZ - fSpace[x, y, z].ForceNegativeZ); Vector3 d = new Vector3(dx, dy, dz); float power = d.Length() / 1000000; if (power > 0) { d.Normalize(); if (power > 200) { power = 200; } dx = d.X * power; dy = d.Y * power; dz = d.Z * power; float sx2 = sx1 + dx; float sy2 = sy1 + dy; float sz2 = sz1 + dz; int r = (int)(255f * Math.Abs(d.X)); int g = (int)(255f * Math.Abs(d.Y)); int b = (int)(255f * Math.Abs(d.Z)); Color c1 = new Color(r, g, b); Color c2 = Color.Transparent; p1 = new VertexPositionColor(new Vector3(sx1, sy1, sz1), c1); p2 = new VertexPositionColor(new Vector3(sx2, sy2, sz2), c2); fLines.AddLine(p1, p2); } } } } fBasicEffect.World = fCamera.Camera.WorldMatrix; fBasicEffect.View = fCamera.Camera.ViewMatrix; fBasicEffect.Projection = fCamera.Camera.ProjectionMatrix; foreach (EffectPass pass in fBasicEffect.CurrentTechnique.Passes) { pass.Apply(); fLines.Render(); } }
private void SetupCircles() { int maxLines = 500000; fLines = new DynamicPrimitiveLine(fSpriteBatch.GraphicsDevice); bool first = true; while (fLines.Lines < maxLines) { //int w = Game.GraphicsDevice.Viewport.Width; //int h = Game.GraphicsDevice.Viewport.Height; float x = (float)(1500.0f * (fRandom.NextDouble() - 0.5f)); float y = (float)(1500.0f * (fRandom.NextDouble() - 0.5f)); int radius = fRandom.Next(400) + 10; int segments = 50; byte r = (byte)fRandom.Next(256); byte g = (byte)fRandom.Next(256); byte b = (byte)fRandom.Next(256); byte a = 255; if (first) { x = 0; y = 0; radius = 500; r = 255; g = 255; b = 255; first = false; } while (fLines.Lines < maxLines && radius > 20) { Color color = new Color(r, g, b, a); fLines.AddCircle(x, y, 0, radius, segments, color); radius--; x++; if (r > 3) { r -= 3; } if (g > 3) { g -= 3; } if (b > 3) { b -= 3; } } } }
private void InitLines() { fLinesChanged = false; fLines = new DynamicPrimitiveLine(fSpriteBatch.GraphicsDevice); int maxLines = 1000000; float rStep = 0.3f; int segments = 500; if (!fManyLines) { maxLines = 20000; rStep = 30.0f; } float radius1 = 0; Color color1a = GetRandomColor(); Color color1b = GetRandomColor(); Color color2a = GetRandomColor(); Color color2b = GetRandomColor(); int colorStep = 0; while (fLines.Lines < maxLines) { Color colorA = GetColor(color1a, color2a, colorStep / 100.0f); Color colorB = GetColor(color1b, color2b, colorStep / 100.0f); float radius2 = radius1 + rStep; fLines.AddCircle(0, 0, 0, radius1, radius2, segments, colorA, colorB); colorStep++; if (colorStep > 100) { color1a = color2a; color1b = color2b; color2a = GetRandomColor(); color2b = GetRandomColor(); colorStep = 0; } radius1 = radius2; } }
private void SetupTree() { int maxLines = 1000000; fLines = new DynamicPrimitiveLine(fSpriteBatch.GraphicsDevice); double maxRadius = Game.GraphicsDevice.Viewport.Width / 4.0f; while (fLines.Lines < maxLines) { byte r = (byte)fRandom.Next(256); byte g = (byte)fRandom.Next(256); byte b = (byte)fRandom.Next(256); byte a = 0; Color c = new Color(r, g, b, a); VertexPositionColor p1 = new VertexPositionColor(new Vector3(0, 0, 0), c); AddTreeBranch(p1, 20, maxRadius, maxLines); } }
private void UpdateScale() { InitializeTransform(); InitializeEffect(); if (fSpriteBatch == null) { return; } int maxLines = 1000000; fLines = new DynamicPrimitiveLine(fSpriteBatch.GraphicsDevice); CircleData circleTo = CreateRandomCircle(); CircleData circleFrom = null; int currentStep = 0; int maxSteps = 0; while (fLines.Lines < maxLines) { CircleData currentCircle; currentStep++; if (currentStep >= maxSteps) { circleFrom = circleTo; circleTo = CreateRandomCircle(); currentStep = 0; maxSteps = fRandom.Next(200) + 1; currentCircle = circleFrom; } else { float f = Convert.ToSingle(currentStep) / maxSteps; currentCircle = CalculateAverageCircle(circleFrom, circleTo, f); } Color c1 = new Color(currentCircle.R1, currentCircle.G1, currentCircle.B1, (byte)255); Color c2 = new Color(currentCircle.R2, currentCircle.G2, currentCircle.B2, (byte)255); fLines.AddCircle(currentCircle.X, currentCircle.Y, 0, currentCircle.Radius, currentCircle.Radius, currentCircle.Segments, c1, c2); } }
/// <summary> /// Initializes the lines /// </summary> private void InitializeLines() { fLines = new DynamicPrimitiveLine(GraphicsDevice); for (int i = 0; i < 256; i++) { fLines.AddCircle(TARGET_WIDTH / 2, TARGET_HEIGHT / 2, 0, i / 5.0f, 50, new Color(i, 255 - i, 255 - i, 255)); } for (int i = 0; i < 5; i++) { Color color = new Color(255 - i * 25, 0, 0, 255); fLines.AddLine( new VertexPositionColor(new Vector3(i, i, 0), color), new VertexPositionColor(new Vector3(TARGET_WIDTH - i - 1, i, 0), color)); fLines.AddLine( new VertexPositionColor(new Vector3(TARGET_WIDTH - i - 1, i, 0), color), new VertexPositionColor(new Vector3(TARGET_WIDTH - i - 1, TARGET_HEIGHT - i - 1, 0), color)); fLines.AddLine( new VertexPositionColor(new Vector3(TARGET_WIDTH - i - 1, TARGET_HEIGHT - i - 1, 0), color), new VertexPositionColor(new Vector3(i, TARGET_HEIGHT - i - 1, 0), color)); fLines.AddLine( new VertexPositionColor(new Vector3(i, TARGET_HEIGHT - i - 1, 0), color), new VertexPositionColor(new Vector3(i, i, 0), color)); } }
/// <summary> /// Draw the space /// </summary> private void RenderGrid() { fLines = new DynamicPrimitiveLine(fSpriteBatch.GraphicsDevice); float worldFactor = WORLD_SIZE / (WORLD_BLOCKS - 1); for (int x = 0; x < WORLD_BLOCKS; x++) { //int blockX = (int)((particle.Position.X + HALF_WORLD_SIZE) * PARTICLE_TO_WORLD); //int blockY = (int)((particle.Position.Y + HALF_WORLD_SIZE) * PARTICLE_TO_WORLD); float sx1 = (x + 0.5f) * worldFactor - HALF_WORLD_SIZE; for (int y = 0; y < WORLD_BLOCKS; y++) { float sy1 = (y + 0.5f) * worldFactor - HALF_WORLD_SIZE; float dx = 1024 * 1024 * 1024 * (fSpace[x, y].ForceRight - fSpace[x, y].ForceLeft); float dy = 1024 * 1024 * 1024 * (fSpace[x, y].ForceUp - fSpace[x, y].ForceDown); float f = Convert.ToSingle(Math.Sqrt(dx * dx + dy * dy)); float f1 = f; Color c1; Color c2; int b1; float size = 1.0f; if (f1 < 1024.0f) { size = f1 / 1024.0f; b1 = (byte)(f1 / 4.0f); c1 = new Color(0, 0, b1, 255); c2 = new Color(0, 0, b1, 255); } else { f1 /= 1024.0f; if (f1 < 1024.0f) { size = 1.0f;// 0.5f + f1 / 512.0f; b1 = (byte)(f1 / 4.0f); c1 = new Color(0, b1, 255 - b1, 255); c2 = new Color(0, 255, 0, 128); } else { f1 /= 1024.0f; if (f1 < 1024.0f) { size = 1.0f;//0.5f + f1 / 512.0f; b1 = (byte)(f1 / 4.0f); c1 = new Color(b1, 255, 0, 255); c2 = new Color(255, 255, 0, 128); } else { f1 /= 1024.0f; if (f1 < 1024.0f) { size = 1.0f;//0.5f + f1 / 512.0f; b1 = (byte)(f1 / 4.0f); c1 = new Color(255, 255 - b1, 0, 255); c2 = new Color(255, 0, 0, 128); } else { size = 1.0f; c1 = new Color(255, 0, 255, 255); c2 = new Color(255, 0, 255, 255); } } } } dx = MAX_LINE_SIZE * (dx / f) * size; dy = MAX_LINE_SIZE * (dy / f) * size; float sx2 = sx1 + dx; float sy2 = sy1 + dy; VertexPositionColor p1 = new VertexPositionColor(new Vector3(sx1, sy1, 0), c1); VertexPositionColor p2 = new VertexPositionColor(new Vector3(sx2, sy2, 0), c2); fLines.AddLine(p1, p2); } } fBasicEffect.World = fCamera.Camera.WorldMatrix; fBasicEffect.View = fCamera.Camera.ViewMatrix; fBasicEffect.Projection = fCamera.Camera.ProjectionMatrix; foreach (EffectPass pass in fBasicEffect.CurrentTechnique.Passes) { pass.Apply(); fLines.Render(); } }
private void UpdateRectangles(bool createNewRectangles) { if (fRectangles == null || createNewRectangles) { fRectangles = MyFactory.GetRandomRectangles(); fAngle = 0; } else { foreach (var rectangle in fRectangles) { rectangle.Angle = fAngle; } } int numberOfPoints = 4 * fRectangles.Count; MyPoint[] points = new MyPoint[numberOfPoints]; int pointIndex = 0; foreach (var rectangle in fRectangles) { var corners = rectangle.CalculateCorners(); points[pointIndex++] = corners[0]; points[pointIndex++] = corners[1]; points[pointIndex++] = corners[2]; points[pointIndex++] = corners[3]; } var polygon = CalculateConvexPolygon(points); if (fLines == null) { fLines = new DynamicPrimitiveLine(fSpriteBatch.GraphicsDevice); fLines.UseVertexBuffer = false; } else { fLines.Clear(); } double boardArea = 0; foreach (var rectangle in fRectangles) { var corners = rectangle.CalculateCorners(); fLines.AddLine(ToVertexPositionColor(corners[0], Color.White), ToVertexPositionColor(corners[1], Color.White)); fLines.AddLine(ToVertexPositionColor(corners[1], Color.White), ToVertexPositionColor(corners[2], Color.White)); fLines.AddLine(ToVertexPositionColor(corners[2], Color.White), ToVertexPositionColor(corners[3], Color.White)); fLines.AddLine(ToVertexPositionColor(corners[3], Color.White), ToVertexPositionColor(corners[0], Color.White)); boardArea += rectangle.Width * rectangle.Height; } double polyArea = 0; int numberOfPolyLines = polygon.Length; for (int i = 0; i < numberOfPolyLines; i++) { int j = (i + 1) % numberOfPolyLines; MyPoint p1 = polygon[i]; MyPoint p2 = polygon[j]; polyArea += MyPoint.Cross(p1, p2); fLines.AddLine(ToVertexPositionColor(p1, Color.Red), ToVertexPositionColor(p2, Color.Red)); } polyArea = polyArea / 2; double ratio = 100.0 * boardArea / polyArea; //System.Console.WriteLine($"Area: {polyArea} PolyPoints: {numberOfPolyLines}, Ratio: {ratio:F1} %"); }