Created
February 19, 2020 04:02
-
-
Save slambert/b09c097eb47c015cdac4ca4e0d7147d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Robot with Red Eyes using variables | |
Steve Lambert | |
Originally written sometime in 2012 | |
*/ | |
// robotWidth is the width of the robot body | |
int robotWidth = 200; | |
// xPos and yPos are the x and y coordinates of the center of the robot | |
int xPos = 300; | |
int yPos = 150; | |
// Change any of the above and see what happens. | |
void setup() { | |
size(600, 300); | |
smooth(); | |
background(240); | |
rectMode(CENTER); | |
} // done with setup | |
void draw() { | |
background(240); | |
// Note that all the sizes are relative multiples of robotWidth, this is | |
// so they'll adjust to various sizes. | |
// body and arms | |
fill(200); // make it grey | |
rect(xPos, yPos, robotWidth, robotWidth*.6); | |
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; | |
// The two legs are created with this for loop. | |
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment