1/**
2 * Objects
3 * by hbarragan.
4 *
5 * Move the cursor across the image to change the speed and positions
6 * of the geometry. The class MRect defines a group of lines.
7 */
8
9MRect r1, r2, r3, r4;
10
11void setup()
12{
13  size(200, 200);
14  fill(255, 204);
15  noStroke();
16  r1 = new MRect(1, 134.0, 0.532, 0.083*height, 10.0, 60.0);
17  r2 = new MRect(2, 44.0, 0.166, 0.332*height, 5.0, 50.0);
18  r3 = new MRect(2, 58.0, 0.332, 0.4482*height, 10.0, 35.0);
19  r4 = new MRect(1, 120.0, 0.0498, 0.913*height, 15.0, 60.0);
20}
21
22void draw()
23{
24  background(0);
25
26  r1.display();
27  r2.display();
28  r3.display();
29  r4.display();
30
31  r1.move(mouseX-(width/2), mouseY+(height*0.1), 30);
32  r2.move((mouseX+(width*0.05))%width, mouseY+(height*0.025), 20);
33  r3.move(mouseX/4, mouseY-(height*0.025), 40);
34  r4.move(mouseX-(width/2), (height-mouseY), 50);
35}
36
37class MRect
38{
39  int w; // single bar width
40  float xpos; // rect xposition
41  float h; // rect height
42  float ypos ; // rect yposition
43  float d; // single bar distance
44  float t; // number of bars
45
46  MRect(int iw, float ixp, float ih, float iyp, float id, float it) {
47    w = iw;
48    xpos = ixp;
49    h = ih;
50    ypos = iyp;
51    d = id;
52    t = it;
53  }
54
55  void move (float posX, float posY, float damping) {
56    float dif = ypos - posY;
57    if (abs(dif) > 1) {
58      ypos -= dif/damping;
59    }
60    dif = xpos - posX;
61    if (abs(dif) > 1) {
62      xpos -= dif/damping;
63    }
64  }
65
66  void display() {
67    for (int i=0; i<t; i++) {
68      rect(xpos+(i*(d+w)), ypos, w, height*h);
69    }
70  }
71}
72