Snowbot

The Code


// declare variables
//colors
float r;
float g;
float b;
float a;

//construction
float circW = width/2;
float circH = height;
float x;
float y;

void setup() {
rectMode(CENTER);
size(400,400);
background(200);
smooth();
frameRate(30);
}
void draw() {

// snow
for (int i=0; i<400; i++) { noStroke(); // pick a random color r = random(240,255); g = random(240,255); b = random(240,255); a = random(20,255); circW = random(1,3); circH = random(1,3); x = random(width); y = random(height); // create a random colored line of random dimensions fill(r,g,b,a); ellipse(x,y,circW,circH); } } // if the mouse is pressed, redraw the background void mousePressed() { // body and arms stroke(255); fill(150); // make it grey rect(mouseX,mouseY,50,30); //body is 50x30 ellipse(mouseX-30,mouseY-5,10,10); ellipse(mouseX+30,mouseY-5,10,10); // legs rect(mouseX-10,mouseY+20,10,10); rect(mouseX+10,mouseY+20,10,10); // head rect(mouseX,mouseY-22.5,40,15); // head is 40x15 // eyes fill(255); // make the eyes white ellipse(mouseX-9,mouseY-24.5,5,5); ellipse(mouseX+9,mouseY-24.5,5,5); // mouth rect(mouseX,mouseY-18.5,20,3); }

bouncing ball

click to drop again.

code


boolean button = false; // initial state for start/stop switch

// setting up variables
float locX = 0; // location X
float locY = 100; // location Y
float xSpeed = random(1,3); // Speed on X axis
float ySpeed = random(1,3); // Speed on Y axis
float gravity = 0.1; // gravity!

void setup() {
size(200,200);
ellipseMode(CORNER);
}

void draw() {
background(255);
stroke(255);
fill(255,166,70); // orange!

locX = locX + xSpeed; // x = x + 1 ... but with variables
locY = locY + ySpeed; // y = y + 1 ... but with variables

ySpeed = ySpeed + gravity; // speed on y axis is affected by gravity, always pushing down

// if object gets to the edge, go the other way.
if ((locX > width-21) || (locX < 1)){ xSpeed = xSpeed * -1; } if ((locY > height-21) || (locY < 1)){ ySpeed = ySpeed * -.75; // inertia? } //draw the circle ellipse(locX,locY,20,20); // Increment x if (button) { locX = locX + xSpeed; locY = locY + ySpeed; } else { locX = locX; locY = locY; } locX = constrain(locX,0,width-20); locY = constrain(locY,0,height-20); } void mousePressed() { locX = mouseX; locY = mouseY; xSpeed = int(random(-3,3)); ySpeed = int(random(-3,3)); } void keyPressed() { button = !button; }

expanding circles

code


// declaring variables
int circleX = 100;
int circleY = 100;
int circleW = 50;
int circleH = 50;
int circleBg = 100;
int circleStroke = 255;
int circleFill = 0;

// setup
void setup() {
size(200,200);
}

// draw
void draw() {
background(circleBg);
stroke(circleStroke);
fill(circleFill);

// four circles
ellipse(circleX-50,circleY-50,circleH,circleW);
ellipse(circleX+50,circleY-50,circleH,circleW);
ellipse(circleX+50,circleY+50,circleH,circleW);
ellipse(circleX-50,circleY+50,circleH,circleW);

// action!
circleW = circleW+2;
circleH = circleH+2;
circleBg = circleH;
circleFill = (-circleH*1)+(255);

// constraints
circleFill = constrain(circleFill,0,255);
circleH = constrain(circleH,0,height*2);
circleW = constrain(circleW,0,width*2);
}

void mousePressed() {
// when mouse is pressed, reset it all and start again
circleW = 1;
circleH = 1;
loop();
}