//The images and the programming took me a reeeeaaallly long time, but I learned alot about Processing and Illustrator
//The notes below are as much for your benefit as mine, as I messed up every single line a dozen times or more
//Sorry if my notes are excessive, if I ever want to refer back I want to remember exactly what I did
//Without further ado, my second attempt at programming
//have to declare variables here before you can call them later
PImage lid, box, hands; //can list multiples variables of same type, use commas
PVector lidPosition = new PVector(0, 0); //vector sets a pt on your grid
float angle; // angle variable, affect it below, float=decimals
float speed = 2; //played around with speed rates, 2 just looks best
boolean left, right; //booleans are false by default
void setup() {
size(1000, 800);
frameRate (60); //chosen by trial and error
hands = loadImage("hand.gif");
box = loadImage("box.gif"); //this image contains a looping graphic pattern
lid = loadImage("panels2.gif");
}
void draw() { //draw function draws at the start of every frame
background (#FFFFFF); //this redraws the background, covering up the frames behind it
imageMode(CENTER); //changes the origin point to the center of the image, good for rotation/radial drawings
for (int yInt = 0; yInt < height; yInt+=2) {
float r = random(255);
stroke(r);
line(0, yInt, width, yInt);
}
moveLid(); //fuuuunnnctions! state them here so they're executed in draw
tiltBox();
}
//The below excerpt is to clarify how += works compared to =+
//If there is a name for the weird logic/math symbols or a reference page for them, I'd love to know!
/*int speed;
speed = 10; //sets value to 10
spped = 25; //replaces value to 25
speed = speed + 15 //speed 1 is slot/variable, speed 2 is the value, add 15 to the value of speed (25), so 25+15 = 40
0 = 0 + 15 //visual example of redundancy
speed =+ 15; // just states positive integer 15
speed += 15; // adds the 15 to the value in the variable */
void moveLid() // moveLid goes before tiltBox, because I want this to be smoother than the tilting, which is tied to keyboard lag
{
if (right && lidPosition.x <= 45) // don't have to type ==true because when you check booleans, by default you're looking for if it's true
lidPosition.x+= speed;
if (left && lidPosition.x >= -45) // && checks 2 conditions for being true, so the lid doesn't go too far, it will stop executing when it reaches limit
lidPosition.x -= speed;
}
void tiltBox() //pushMatrix basically starts funking around with your grid/layout, and popMatrix ends its effect
{
pushMatrix();
translate(500, 400);
rotate(radians(angle));
image (hands, 0, 0);
image (box, 0, 0);
image(lid, lidPosition.x, lidPosition.y); // . means you're accessing something inside it, Processing understands x and y without clarification
popMatrix();
}
void keyPressed()
{
switch(keyCode) // switch is the same as writing else if, only 1 can be true, checks for 1 and moves on
{ //it's going to continuously be checking the below options
case LEFT:
if (left == false) //because I only want the image to rotate once on the click
{//if left = false, move on to the break, and continue checking for right click and releases... if true, apply below effects and break
left = true;
angle = -10;
}
break; // stops a shallow instruction, first one it checks / last one executed, otherwise switch would keep executing everything below
case RIGHT:
if (right == false)
{
right = true;
angle = 10;
}
break;
}
}
void keyReleased()
{
switch(keyCode)
{
case LEFT:
if (left) //if the last key released was LEFT, don't worry about it program, move on!
{//if the last key released was not LEFT, set angle to 0
left = false;
angle = 0;
}
break;
case RIGHT:
{
right = false;
angle = 0;
}
break;
}
}
//Thank god it's done and working!
//Big thanks to my classmates with coding experience, who helped me make heads/tails of this switch business!
//I'll be paying special attention to interactivity as it comes up
//And maybe not set my expectations so high that I waste hours going in circles (haha, pun)
//Seriously though, that box spun aimlessly for 2 days