-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisect_backbuffer.pde
66 lines (53 loc) · 1.29 KB
/
isect_backbuffer.pde
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
PGraphics pickbuffer = null;
int numCircles = 10;
MyCircle[] circles;
void setup() {
smooth();
size(600, 600);
pickbuffer = createGraphics(width, height);
circles = new MyCircle [numCircles];
for (int i=0; i<numCircles; i++) {
int radius = (int)random(10, 100);
int posx = (int)random(radius, width-radius);
int posy = (int)random(radius, height-radius);
circles[i] = new MyCircle(i*10000, posx, posy, radius);
int r = (int)random(0, 255);
int g = (int)random(0, 255);
int b = (int)random(0, 255);
circles[i].setColor (r, g, b);
}
}
void draw () {
background(255);
for (int i=0; i<numCircles; i++) {
if (circles[i].getSelected() == true) {
circles[i].renderSelected();
}
else {
circles[i].render();
}
}
if (keyPressed) {
drawPickBuffer();
image(pickbuffer, 0, 0);
}
}
void drawPickBuffer() {
pickbuffer.beginDraw();
for (int i = 0; i < numCircles; i++) {
circles[i].renderIsect(pickbuffer);
}
pickbuffer.endDraw();
}
void mouseMoved () {
drawPickBuffer();
color c = pickbuffer.get(mouseX, mouseY);
for (int i=0; i<numCircles; i++) {
if (circles[i].isect(c) == true) {
circles[i].setSelected(true);
}
else {
circles[i].setSelected(false);
}
}
}