public void Run(LEDEngine3D engine3D) { if (firework != null) { firework.ApplyForce(Gravity); firework.Update(); firework.Display(engine3D); if (firework.Explode()) { for (int i = 0; i < 100; i++) { particles.Add(new Particle(firework.Location, hu)); // Add "num" amount of particles to the arraylist } firework = null; } } for (int i = particles.Count - 1; i >= 0; i--) { Particle p = particles[i]; p.ApplyForce(Gravity); p.Run(engine3D); if (p.IsDead()) { particles.RemoveAt(i); } } }
protected override Image <Rgba32> Run() { TimeSpan countDownSpan = timeSpan - stopwatch.Elapsed; string displayText; Color color = Color.White; FontFamily fo; SystemFonts.TryFind("Times New Roman", out fo); Font font = new Font(fo, 20, FontStyle.Regular); if (countDownSpan.TotalSeconds > 11) { font = new Font(fo, 20, FontStyle.Regular); string hours = string.Empty; string minutes = string.Empty; string seconds = string.Empty; if (countDownSpan.Hours > 0) { hours = "0" + countDownSpan.Hours.ToString(); hours = hours.Substring(hours.Length - 2) + ":"; } minutes = "0" + countDownSpan.Minutes.ToString(); minutes = minutes.Substring(minutes.Length - 2) + ":"; seconds = "0" + countDownSpan.Seconds.ToString(); seconds = seconds.Substring(seconds.Length - 2); displayText = hours + minutes + seconds; } else if (countDownSpan.TotalSeconds <= 1) { displayText = string.Empty; } else { font = new Font(fo, 35, FontStyle.Regular); displayText = countDownSpan.Seconds.ToString(); color = color.WithAlpha(LEDEngine3D.Map(countDownSpan.Milliseconds, 1, 1000, 0f, 1f)); } FontRectangle size = TextMeasurer.Measure( displayText, new RendererOptions(font)); image = new Image <Rgba32>(LEDWidth, LEDHeight); SetBackgroundColor(image); image.Mutate(c => c.DrawText( displayText, font, color, new PointF((image.Width - size.Width) / 2, (image.Height - size.Height) / 2))); return(image); }
// Method to display public void Display(LEDEngine3D engine3D) { if (lifespan < 0) { return; } Vector3D lifeTimeHu = hu.Sub(255 - lifespan, false); Rgba32 pixel = new Rgba32(Convert.ToByte(lifeTimeHu.vector.X), Convert.ToByte(lifeTimeHu.vector.Y), Convert.ToByte(lifeTimeHu.vector.Z)); if (seed) { engine3D.Draw(Location.X - 1, Location.Y, pixel); engine3D.Draw(Location.X, Location.Y - 1, pixel); engine3D.Draw(Location.X, Location.Y, pixel); engine3D.Draw(Location.X, Location.Y + 1, pixel); engine3D.Draw(Location.X + 1, Location.Y, pixel); } else { Vector3D trailHu = lifeTimeHu; for (int i = pastLocations.Count - 1; i >= 0; i--) { bool outOfColor = trailHu.vector.X < 0 && trailHu.vector.Y < 0 && trailHu.vector.Z < 0; if (outOfColor) { break; } Vector2D pastLocation = pastLocations[i]; engine3D.Draw(pastLocation.X, pastLocation.Y, new Rgba32(Convert.ToByte(trailHu.vector.X), Convert.ToByte(trailHu.vector.Y), Convert.ToByte(trailHu.vector.Z))); trailHu = trailHu.Sub(5f, false); } engine3D.Draw(Location.X, Location.Y, pixel); } }
private void updateTriangles() { List <Triangle> triangles = new List <Triangle>(); for (int y = 0; y < scaleGrid - 1; y++) { for (int x = 0; x < scaleGrid - 1; x++) { triangles.Add(new Triangle(new List <Vector3D>() { new Vector3D(LEDEngine3D.Map(x, 0, scaleGrid - 1, 0, 1), LEDEngine3D.Map(y + 1, 0, scaleGrid - 1, 0, 1), perlin.perlin(LEDEngine3D.Map(x, 0, scaleGrid - 1, 0, 1), y + 1 + offsetY)), //1 new Vector3D(LEDEngine3D.Map(x + 1, 0, scaleGrid - 1, 0, 1), LEDEngine3D.Map(y, 0, scaleGrid - 1, 0, 1), perlin.perlin(LEDEngine3D.Map(x + 1, 0, scaleGrid - 1, 0, 1), y + offsetY)), //3 new Vector3D(LEDEngine3D.Map(x, 0, scaleGrid - 1, 0, 1), LEDEngine3D.Map(y, 0, scaleGrid - 1, 0, 1), perlin.perlin(LEDEngine3D.Map(x, 0, scaleGrid - 1, 0, 1), y + offsetY)), //2 }, new List <Vector2D>() { new Vector2D(0.0f, LEDEngine3D.Map(y, 0, scaleGrid - 1, 0, 1), 1.0f), new Vector2D(0.0f, 0.0f, 1.0f), new Vector2D(LEDEngine3D.Map(x, 0, scaleGrid - 1, 0, 1), 0.0f, 1.0f), } )); triangles.Add(new Triangle(new List <Vector3D>() { new Vector3D(LEDEngine3D.Map(x, 0, scaleGrid - 1, 0, 1), LEDEngine3D.Map(y + 1, 0, scaleGrid - 1, 0, 1), perlin.perlin(LEDEngine3D.Map(x, 0, scaleGrid - 1, 0, 1), y + 1 + offsetY)), new Vector3D(LEDEngine3D.Map(x + 1, 0, scaleGrid - 1, 0, 1), LEDEngine3D.Map(y + 1, 0, scaleGrid - 1, 0, 1), perlin.perlin(LEDEngine3D.Map(x + 1, 0, scaleGrid - 1, 0, 1), y + 1 + offsetY)), new Vector3D(LEDEngine3D.Map(x + 1, 0, scaleGrid - 1, 0, 1), LEDEngine3D.Map(y, 0, scaleGrid - 1, 0, 1), perlin.perlin(LEDEngine3D.Map(x + 1, 0, scaleGrid - 1, 0, 1), y + offsetY)), }, new List <Vector2D>() { new Vector2D(0.0f, LEDEngine3D.Map(y, 0, scaleGrid - 1, 0, 1), 1.0f), new Vector2D(LEDEngine3D.Map(x, 0, scaleGrid - 1, 0, 1), 0.0f, 1.0f), new Vector2D(LEDEngine3D.Map(x, 0, scaleGrid - 1, 0, 1), LEDEngine3D.Map(y, 0, scaleGrid - 1, 0, 1), 1.0f), } )); } } meshCube.Tris = triangles; offsetY += 1f; }
protected override Image <Rgba32> Run() { Image <Rgba32> image = new Image <Rgba32>(renderHeight, renderWidth); SetBackgroundColor(image); for (int i = 1; i < renderHeight - 1; i++) { for (int j = 1; j < renderWidth - 1; j++) { List <Cell> beforeRow = prev[i - 1]; List <Cell> currentRow = prev[i]; List <Cell> nextRow = prev[i + 1]; Cell spot = currentRow[j]; Cell newspot = grid[i][j]; float a = spot.A; float b = spot.B; float laplaceA = 0; laplaceA += a * -1; laplaceA += nextRow[j].A * 0.2f; laplaceA += beforeRow[j].A * 0.2f; laplaceA += currentRow[j + 1].A * 0.2f; laplaceA += currentRow[j - 1].A * 0.2f; laplaceA += beforeRow[j - 1].A * 0.05f; laplaceA += nextRow[j - 1].A * 0.05f; laplaceA += beforeRow[j + 1].A * 0.05f; laplaceA += nextRow[j + 1].A * 0.05f; float laplaceB = 0; laplaceB += b * -1; laplaceB += nextRow[j].B * 0.2f; laplaceB += beforeRow[j].B * 0.2f; laplaceB += currentRow[j + 1].B * 0.2f; laplaceB += currentRow[j - 1].B * 0.2f; laplaceB += beforeRow[j - 1].B * 0.05f; laplaceB += nextRow[j - 1].B * 0.05f; laplaceB += beforeRow[j + 1].B * 0.05f; laplaceB += nextRow[j + 1].B * 0.05f; newspot.A = a + (dA * laplaceA - a * b * b + feed * (1 - a)) * 1; newspot.B = b + (dB * laplaceB + a * b * b - (k + feed) * b) * 1; newspot.A = LEDEngine3D.Constrain(newspot.A, 0, 1); newspot.B = LEDEngine3D.Constrain(newspot.B, 0, 1); } } for (int i = 0; i < renderHeight; i++) { for (int j = 0; j < renderWidth; j++) { int color = Convert.ToInt32((grid[i][j].A - grid[i][j].B)) * 255; image.GetPixelRowSpan(i)[j] = new Rgba32(255 - color, 255 - color, 255 - color); } } image.Mutate(c => c.Resize(LEDWidth, LEDHeight)); copyGrid(); return(image); }
public void Run(LEDEngine3D engine3D) { Update(); Display(engine3D); }