de schets terug naar de inleiding de schets op open processing
Alien a1;
void setup() {
background(0);
fullScreen();
frameRate(1);
a1 = new Alien();
}
void draw() {
a1.display();
}
void keyPressed() {
if (key == 's') {
noLoop();
}
if (key == 'r') {
loop();
}
if (key == 'c') {
setup();
}
De class Alien
class Alien {
float x;
float y;
float dx;
float dy;
//Constructor
Alien() {
}
void display() {
color hoofd = color(random(0, 200), random(0, 200), random(0, 200), random(0, 200));
color oren = color(random(0, 200), random(0, 200), random(0, 200), random(0, 200));
color lichaam = color(random(0, 200), random(0, 200), random(0, 200), random(0, 200));
color ogen = color(255, 0, 0);
color mond = color(random(0, 200), random(0, 100), random(0, 100));
x = random(width);
y = random(height);
dx = random(20, 100);
dy = random(20, 100);
fill(hoofd);
ellipse(x, y, dx, dy); // hoofd
fill(oren);
ellipse(x+dx/2, y, dx/6, dy/5); // rechter oortje
ellipse(x-dx/2, y, dx/6, dy/5); // linker oortje
fill(ogen);
ellipse(x+dx/4, y-dy/4, dx/6, dy/6); // re oogje
ellipse(x-dx/4, y-dy/4, dx/6, dy/6); // li oogje
fill(lichaam);
ellipse(x, y+dy, dx, 2*dy); //lichaam
fill(mond);
ellipse(x, y+dy/4, dx/2, dy/6); //Mondje
}
}