Robot as a function

Exercise 7-10

and the code…

void setup() {
size(600, 300);
smooth();
background(240);
rectMode(CENTER);
// done with setup
}

void draw() {

background(240); // this kepps the whole thing from redrawing itself
drawRobot(80,mouseX-200,mouseY);
drawRobot(120,mouseX,mouseY);
drawRobot(60,mouseX+160,mouseY);

}

void drawRobot(int robotWidth, int xPos, int yPos) {
// robotWidth is the width of the robot body
// xPos and yPos are the x and y coordinates of the center of the robot

// body and arms
fill(200); // make it grey
rect(xPos,yPos,robotWidth,robotWidth*.6); //body is 50x30
ellipse(xPos-robotWidth*.6,yPos-robotWidth*.1,robotWidth*.2,robotWidth*.2);
ellipse(xPos+robotWidth*.6,yPos-robotWidth*.1,robotWidth*.2,robotWidth*.2);

// legs
float legStart = xPos-robotWidth*.3;
for (int i=0; i<2; i++) { rect(legStart,yPos+robotWidth*.4,robotWidth*.2,robotWidth*.2); legStart = legStart+robotWidth*.6; } // head rect(xPos,yPos-robotWidth*.45,robotWidth*.8,robotWidth*.3); // head is 40x15 // mouth fill(255); rect(xPos,yPos-robotWidth*.37,robotWidth*.4,robotWidth*.06); // eyes if (mousePressed == true) { fill(255,0,0); // make the eyes red } else { fill(255); // make the eyes white } ellipse(xPos-robotWidth*.18,yPos-robotWidth*.49,robotWidth*.1,robotWidth*.1); ellipse(xPos+robotWidth*.18,yPos-robotWidth*.49,robotWidth*.1,robotWidth*.1); }

loops

I have been thinking about doing Bridget Riley-ish optical art with processing started with a line loop

int y = 0;
int x = 0;

void setup() {
size(1000,1000);
background(255);
frameRate(100);
}

void draw() {
// Draw a line
strokeWeight(5);
stroke(0);
// draw line
line(0,y,width,y);
// Increment y
y += 10;
strokeWeight(5);
stroke(255);
// Only one line is drawn each time through draw().
line(x,0,x,height);
// Increment x
x += 10;
// Reset x back to 0 when it gets to the side of window
if (y > height) {
y = 0;
}
if (x > width) {
x = 0;
}
}