Processing

Posted: December 13th, 2010 | Author: | Filed under: Processing | 2 Comments »

Here’s a quick code sample in Processing, an open source programming language that allows you to easily create animations and interactions.

Here’s the code in action…do a bit of clicking and dragging for good measure…

…and here’s the code…

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
44
45
46
int expand = 0;
int colorValue1 = 255;
int colorValue2 = 255;
int canvasSize = 500;
 
void setup() {
  background(255);
  size(canvasSize, canvasSize);
  smooth();
}
 
void draw() {
  if (mousePressed) {
    doDraw(mouseX, mouseY);  
  }else{
     doDraw(int(random(500)), int(random(500))); 
  }
}
 
void doDraw(int xPosition, int yPosition){
 
    colorValue1 = colorValue1 - 5;
    colorValue2 = colorValue2 - 5;
    if(colorValue1 <= 0){
     colorValue1 = 255; 
    }
    if(colorValue2 <= 0){
     colorValue2 = 255; 
    }
    fill(colorValue1,colorValue2,0);
 
    ellipse(xPosition + expand-(expand/4), yPosition + expand-(expand/4), expand, expand);
    ellipse(xPosition + expand, yPosition + 0, expand, expand);
    ellipse(xPosition + 0, yPosition + expand, expand, expand);
    ellipse(xPosition + expand-(expand/4), yPosition - expand+(expand/4), expand, expand);
    ellipse(xPosition - expand+(expand/4), yPosition + expand-(expand/4), expand, expand);
    ellipse(xPosition - expand, yPosition - 0, expand, expand);
    ellipse(xPosition - expand+(expand/4), yPosition - expand+(expand/4), expand, expand);
    ellipse(xPosition - 0, yPosition - expand, expand, expand);
    ellipse(xPosition, yPosition, expand+(expand/2), expand+(expand/2));
 
    expand = expand + 1;
    if(expand >= canvasSize / 10){
       expand = 0; 
    }
}