public void step() { x += (int)vx; y += (int)vy; if (x > StreamGraphics.width) { x = StreamGraphics.width - (x - StreamGraphics.width); vx = -vx; vy += StepWorker.rnd.Next(3) - 1; } if (x < 0) { x = -x; vx = -vx; vy += StepWorker.rnd.Next(3) - 1; } if (y > StreamGraphics.height) { y = StreamGraphics.height - (y - StreamGraphics.height); vy = -vy; vx += StepWorker.rnd.Next(3) - 1; } if (y < 0) { y = -y; vy = -vy; vx += StepWorker.rnd.Next(3) - 1; } StreamGraphics.moveTo(id, x, y); }
} // TODO: get this dynamically. internal void reset() { lock (commandQueue) { commandQueue.Clear(); // foreach (GraphicsWorker worker in workers) // { // worker.reset(); // } foreach (Thread workerThread in workerThreads) { workerThread.Interrupt(); } foreach (Thread workerThread in workerThreads) { workerThread.Join(); } workerThreads.Clear(); clear(); foreach (GraphicsWorker worker in workers) { StreamGraphics.startWorker(worker); } } }
public void run() { StreamGraphics.clear(); StreamGraphics.setStepDelayMs(10); for (int x = 0; x < 600; x += 10) { StreamGraphics.drawLine( x, 0, 0, 600 - x, Color.RED); StreamGraphics.step(); } StreamGraphics.setStepDelayMs(500); StreamGraphics.drawText("Hello World!", 180, 300, 30, Color.YELLOW); StreamGraphics.step(); StreamGraphics.drawText("Hello World!", 180, 300 + 40, 50, Color.MAGENTA); StreamGraphics.step(); string bigtextId = StreamGraphics.drawText("Hello World!", 180, 300 + 40 + 50 + 20, 70, Color.CYAN); StreamGraphics.rotateTo(bigtextId, -4); StreamGraphics.step(); StreamGraphics.drawText( "Try clicking with the mouse; use arrow keys; type something, use BACKSPACE to erase typed text!", 40, 570, 12, Color.WHITE); robotX = 700; robotY = 300; robotId = StreamGraphics.drawSprite("images/robot.png", robotX, robotY); StreamGraphics.step(); StreamGraphics.setStepDelayMs(10); }
public static void Main(string[] args) { StreamGraphics.registerWorker(new DemoWorker()); // StreamGraphics.registerWorker(new SimpleWorker()); // StreamGraphics.registerWorker(new StepWorker()); CreateWebHostBuilder(args).Build().Run(); StreamGraphics.shutdown(); }
public void onPointerDown(int x, int y) { StreamGraphics.drawCircle(x, y, 20, Color.BLUE); StreamGraphics.drawRect(x, y, 20, 30, Color.GREEN); pointerX = x; pointerY = y; chars.Clear(); }
public Ball createBall() { int x = rnd.Next(StreamGraphics.width); int y = rnd.Next(StreamGraphics.height); int vx = rnd.Next(10) + 2; int vy = rnd.Next(10) + 2; string id = StreamGraphics.drawCircle( x, y, 20, Color.randomLight(rnd)); return(new Ball(id, x, y, vx, vy)); }
public void onKeyDown(string key) { if (key == "Backspace") { if (chars.Count > 0) { string id = chars.Pop(); StreamGraphics.delete(id); pointerX -= 20; } return; } else if (key == "ArrowUp") { robotY -= 10; StreamGraphics.moveTo(robotId, robotX, robotY); return; } else if (key == "ArrowUp") { robotY -= 10; StreamGraphics.moveTo(robotId, robotX, robotY); return; } else if (key == "ArrowDown") { robotY += 10; StreamGraphics.moveTo(robotId, robotX, robotY); return; } else if (key == "ArrowLeft") { robotX -= 10; StreamGraphics.moveTo(robotId, robotX, robotY); return; } else if (key == "ArrowRight") { robotX += 5; StreamGraphics.moveTo(robotId, robotX, robotY); return; } if (key.Length > 1) { return; } { string id = StreamGraphics.drawText(key, pointerX, pointerY, 30, Color.WHITE); chars.Push(id); pointerX += 20; } }
public void randomLines() { for (int i = 0; i < 5000; i++) { StreamGraphics.drawLine( rnd.Next(800), rnd.Next(600), rnd.Next(800), rnd.Next(600), new Color(rnd.Next(256), rnd.Next(256), rnd.Next(256))); StreamGraphics.step(); } }
public void redNoise() { StreamGraphics.setStepDelayMs(50); StreamGraphics.setBufferSize(60 * StreamGraphics.width / 20 * StreamGraphics.height / 20); while (true) { StreamGraphics.clear(); for (int x = 0; x < StreamGraphics.width; x += 20) { for (int y = 0; y < StreamGraphics.height; y += 20) { StreamGraphics.drawRect( x, y, 20, 20, new Color(rnd.Next(265), 0, 0)); } } StreamGraphics.step(); } }
public void run() { StreamGraphics.setBufferSize(2000); StreamGraphics.clear(); List <Ball> balls = new List <Ball>(); for (int i = 0; i < 30; i++) { Ball ball = createBall(); balls.Add(ball); } while (true) { foreach (Ball ball in balls) { ball.step(); } StreamGraphics.step(); } }