-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignment_2.pde
77 lines (67 loc) · 1.59 KB
/
assignment_2.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
67
68
69
70
71
72
73
74
75
76
77
PImage photo;
PImage photo2;
int clicks = 0;
void setup() {
size(650, 500);
background(0);
photo = loadImage("starryNight.jpeg");
photo.resize(650, 500);
photo2 = loadImage("starryNight2.jpeg");
photo2.resize(650, 500);
frameRate(30);
}
void draw() {
imageMode(CENTER);
noStroke();
int circleLimit = mouseX / 2;
float circleSize = 2;
float blackHoles = circleSize * 8;
for (int i = 0; i < circleLimit; i++) {
float x = random(width);
float y = random(height);
int a = int(x);
int b = int(y);
float c = random(4, 12);
int d = int(c);
if (clicks == 0) {
fill(photo.pixels[b*width+a]);
} else if (clicks == 1) {
fill(0, 25);
ellipse(x, y, blackHoles, blackHoles);
} else if (clicks == 2) {
fill(photo2.pixels[b*width+a]);
} else {
fill(0, 25);
ellipse(x, y, blackHoles, blackHoles);
}
pushMatrix();
translate(x, y);
star(0, 0, circleSize/random(2, 4), circleSize/random(8), d);
popMatrix();
}
}
void mouseClicked() {
if (clicks == 0) {
clicks = 1;
} else if (clicks == 1) {
clicks = 2;
} else if (clicks == 2) {
clicks = 3;
} else {
clicks = 0;
}
}
void star(float x, float y, float radius1, float radius2, int npoints) {
float angle = TWO_PI / npoints;
float halfAngle = angle/2.0;
beginShape();
for (float a = 0; a < TWO_PI; a += angle) {
float sx = x + cos(a) * radius2;
float sy = y + sin(a) * radius2;
vertex(sx, sy);
sx = x + cos(a+halfAngle) * radius1;
sy = y + sin(a+halfAngle) * radius1;
vertex(sx, sy);
}
endShape(CLOSE);
}