-
Notifications
You must be signed in to change notification settings - Fork 1
/
prj2_growing_colors.pde
93 lines (78 loc) · 2.16 KB
/
prj2_growing_colors.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
Project #2 by Sehyun Hwang
* name : Growing colors
* description : All dots start from the bottom center of screen.
All starts grow with the different color.
After they all grow, another colors start to grow with different colors and directions.
*/
Dot []dots;
int number=80;
float size = 10;
float offSet;
int rs = 0;
void setup() {
size(1100, 700);
background(50, 50, 50); // dark gray
noStroke();
offSet = radians(3); // variable for next dots location
/* Initialization of the dots */
dots=new Dot[number];
for (int i=0; i<number; i++) {
float speed=random(0, 1);
dots[i]=new Dot(random(255), speed);
}
}
void draw() {
translate(width/2, height); // starts from the bottom center
fill(50, 50, 50,10);
rect(-width/2,-height,1100,700); // this is for background footprints
/* drawing dots */
for (int i=0; i<number; i++) {
dots[i].setRandomSeed();
dots[i].drawingDot(0, 0, size, radians(random(360)), 1);
dots[i].changeCount();
}
}
class Dot {
int rs;
float count;
float speed;
color dotColor;
Dot(float _rs, float _speed) {
rs=(int)_rs;
count=0;
speed=_speed*0.1;
float r=random(255);
float g=random(255);
float b=random(255);
dotColor=color(r, g, b);
}
void drawingDot(float x, float y, float size, float angle, float sign) {
if (size > 10-count) {
float p = random(0, 1.0);
fill(dotColor);
ellipse(x, y, size, size);
float nx = x + size * cos(angle);
float ny = y + size * sin(angle);
if (p >= 0.1) {
drawingDot(nx, ny, size * 0.99, angle + sign*offSet, sign);
} else {
drawingDot(nx, ny, size * 0.99, angle - sign*offSet, -sign);
}
}
}
void changeCount() {
count += 0.03; // the count variable is for progressive drawing
if (count>5) {
rs=(int)random(50);
float r=random(255);
float g=random(255);
float b=random(255);
dotColor=color(r, g, b);
count=0;
}
}
void setRandomSeed() {
randomSeed(rs);
}
}