Skip to content

Instantly share code, notes, and snippets.

@alexdwagner
Created October 25, 2018 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexdwagner/cfd034aaa55dd3298654e953266b7f16 to your computer and use it in GitHub Desktop.
Save alexdwagner/cfd034aaa55dd3298654e953266b7f16 to your computer and use it in GitHub Desktop.
/* This is a Processing sketch in which two rectangles in back-and-forth vertical motion paint the canvas
in Rothko-like fashion. Click the mouse to change the color of "Brick 1" and click-and-drag the mouse to change
the color of "Brick 2".
Brick b1;
Brick b2;
void setup()
{
size(1280, 720);
//fullScreen();
noStroke();
frameRate(30);
background(#FFFFFF);
/* Brick constructor has 5 args:
int tempD, = height of rect
int tempYpos, = starting position of rect
int tempYdir, = direction of rect, up or down(1 or -1?)
float tempYspeed, = float of yspeed. a decent speed is between 2.0-3.0
int tempValue = starting transparency value of rect's fill. can be changed with mouseDragged
*/
b1 = new Brick(30, 300, -1, 2.5, 50);
b2 = new Brick(60, 600, 1, 1.5, 100);
}
void draw()
{
//background(#FFFFFF);
b1.ascend();
b1.display();
//b.top();
b2.ascend();
b2.display();
//b3.ascend();
//b3.display();
//saveFrame("frames/####.png");
}
void mousePressed(){
b1.changeColor();
}
void mouseDragged(){
b2.changeTransp();
}
class Brick {
int lengthBlock; // Length of shape
int widthBlock = width; // Width of the shape
float xpos, ypos;
float yspeed = 2.2; // Speed of the shape
int ydirection; // Top to Bottom
int rColor = 200;
int bColor = 0;
int value;
Brick(int tempD, int tempYpos, int tempYdir, float tempYspeed, int tempValue){
xpos = width/2;
lengthBlock = tempD;
ypos = tempYpos; // Starting position of shape
ydirection = tempYdir;
yspeed = tempYspeed;
value = tempValue;
}
// Draw the shape
void display() {
fill(rColor, 0, bColor, value);
rectMode(CENTER);
rect(xpos, ypos, widthBlock, lengthBlock);
widthBlock = mouseX;
lengthBlock = mouseY;
}
void ascend() {
ypos = ypos + ( yspeed * ydirection );
if (ypos > height || ypos < -60) {
ydirection *= -1;
}
}
void changeColor() {
rColor += 10/3%5 ;
bColor += 20;
if (rColor > 255) {
rColor = 100;
}
if (bColor > 255) {
bColor = 100;
}
}
void changeTransp() {
value = value + 1;
println(value);
if (value > 50) {
value = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment