mirror of
https://github.com/processing/processing4.git
synced 2026-04-18 18:29:31 +02:00
removing old nature of code examples before adding new ones
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
// Random Walker (No Vectors)
|
||||
// Daniel Shiffman <http://www.shiffman.net>
|
||||
// The Nature of Code
|
||||
|
||||
Walker w;
|
||||
|
||||
void setup() {
|
||||
size(400,400);
|
||||
frameRate(30);
|
||||
|
||||
// Create a walker object
|
||||
w = new Walker();
|
||||
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
// Run the walker object
|
||||
w.walk();
|
||||
w.render();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
// Random Walker (No Vectors)
|
||||
// Daniel Shiffman <http://www.shiffman.net>
|
||||
// The Nature of Code
|
||||
// A random walker class!
|
||||
|
||||
class Walker {
|
||||
PVector loc;
|
||||
|
||||
Walker() {
|
||||
loc = new PVector(width/2,height/2);
|
||||
}
|
||||
|
||||
void render() {
|
||||
stroke(0);
|
||||
fill(175);
|
||||
rectMode(CENTER);
|
||||
rect(loc.x,loc.y,40,40);
|
||||
}
|
||||
|
||||
// Randomly move up, down, left, right, or stay in one place
|
||||
void walk() {
|
||||
PVector vel = new PVector(random(-2,2),random(-2,2));
|
||||
loc.add(vel);
|
||||
|
||||
// Stay on the screen
|
||||
loc.x = constrain(loc.x,0,width-1);
|
||||
loc.y = constrain(loc.y,0,height-1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user