Source Code. Projects. Nerd Stuff. Art Stuff.

Drawing, Variables, and Simple Animation

[gn_media url="https://vimeo.com/45851523" width="600" height="400"]

 

class1BounceTest.pde

[gn_spoiler title="Bounce test source code:" open="0" style="1"]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//class1BounceTest.pde
int y;
int x;
boolean revX;
boolean revY;

void setup(){
  size(500,500);
  revY=false;
  revX=false;
  x = 5;
  y = 5;   
}

void draw(){
  if(!revY){
    y = y + 5;
  } else {
    y=y-5;
  }
 
  if(y>height){
    revY=true;
  }
 
  if(y<0){
    revY=false;
  }
 
  if(!revX){
    x = x + 7;
  } else {
    x=x-7;
  }
 
  if(x>width||x<0){
    revX=!revX;
  }
 
  ellipseMode(CENTER);
  ellipse(x, y, 10, 10);
  fill(x%255,x*y%255,y%255);  
}
[/gn_spoiler]

 
 

class1Mouseover.pde

[gn_spoiler title="Mouseover source code:" open="0" style="1"]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// class1Mouseover.pde
void setup(){
  size(640, 480);
}

void draw(){
  background(0);
 
  fill(255, 0, 0);
  // if the mouse is over the rectangle
  // then we change the fill color to green
  if(mouseX > width/2 && mouseX < width/2 + 200 && mouseY > height/2 && (mouseY < height - 40)){
    fill(0, 255, 0);
  }
 
  rect(width/2, height/2, 200, 200);
 
  fill(0, 0, 255);
  ellipseMode(CENTER);
  ellipse(mouseX, mouseY, 75, 75);
}
[/gn_spoiler]