-
Notifications
You must be signed in to change notification settings - Fork 0
/
radialvectorfield.java
217 lines (164 loc) · 4.43 KB
/
radialvectorfield.java
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*----------------------------------
Based on https://www.openprocessing.org/sketch/146879 which used white pixels
Copyright by Diana Lange 2014
Don't use without any permission. Creative Commons: Attribution Non-Commercial.
mail: [email protected]
web: diana-lange.de
facebook: https://www.facebook.com/DianaLangeDesign
flickr: http://www.flickr.com/photos/dianalange/collections/
tumblr: http://dianalange.tumblr.com/
twitter: http://twitter.com/DianaOnTheRoad
vimeo: https://vimeo.com/dianalange/videos
-----------------------------------*/
int padding;
ArrayList <Mover> m;
int xRes = 50;
int yRes = 28;
float posX;
float posY;
int changer = 0;
float hueStart = 0;
float hueLimit = 60;
float hue = hueStart + (hueLimit-hueStart)/2;
boolean bDisplayVectorField = false, displayParticle = true;
void setup ()
{
size (800, 800);
//size (720, 405);
// size (1920, 1080);
noSmooth();
//smooth();
frameRate (30);
colorMode(HSB, 360);
padding = -2;
posX = width/2+1;
posY = 0;
m = new ArrayList();
background (#111111);
for (int i = 0; i < 1000; i++)
{
m.add (new Mover());
}
}
void draw ()
{
randomSeed (0);
// blur(1);
// fastblur (1);
noStroke();
fill (7, 19);
rect (0, 0, width, height);
posX = lerp (posX, (mousePressed ? mouseX : noise (frameCount /500.0) * width /*noise (20+frameCount / 100.0)*1.5*/), 0.05);
posY = lerp (posY, mousePressed ? map (mouseY, 0, height, 0, 1) : (noise (100+frameCount / 400.0)), 0.05) ;
if (displayParticle)
{
stroke(240);
for (int i = 0; i < m.size(); i++)
{
m.get(i).move();
m.get (i).setVelo (posX, posY, noise (frameCount / 300.0));
m.get(i).checkEdges();
m.get(i).display();
}
}
//copy (1, 1, width, height, -1, -1, width+3, height+3);
if (bDisplayVectorField) displayVectorField();
}
class Mover
{
PVector location;
PVector velo;
float speed;
color colour;
Mover ()
{
location = new PVector(random(width), random(height));
velo = new PVector(random(-1, 1), random(-1, 1));
velo.normalize();
colour = getNextColour();
speed = random (1, 3);
}
void setVelo (float posX, float posY, float stength)
{
float angle, fAngle;
float dis;
float mm = map (posX, 0, width, -1.2, 1.2);
if (mm == 0) mm = 0.0001;
float maxDis = mm*dist (0, 0, width/2, height/2);
dis = dist (location.x, location.y, width/2, height/2);
fAngle = map (dis, 0, maxDis, posY, 0);
angle = map (dis, 0, maxDis, PI, 0) + random (-PI/4*fAngle, PI/4*fAngle);
velo.x += cos (angle)*stength;
velo.y += sin (angle)*stength;
velo.normalize();
}
void move ()
{
location.add (multi (velo, speed));
}
void checkEdges ()
{
if (location.x < 0 || location.x > width || location.y < 0 || location.y > height)
{
location.x = random (width);
location.y = random (height);
colour = getNextColour();
}
}
PVector multi (PVector v, float m)
{
return new PVector (v.x*m, v.y*m);
}
void display ()
{
//strokeWeight (0.5);
//fill(#b1c999, 255);
stroke(colour);
ellipse( location.x, location.y, 2, 2);
// point (location.x, location.y); // original
}
}
color getNextColour() {
color c;
hue += noise(.00001);
if (hue>hueLimit) hue=hueStart;
c = color(hue, 360, 360);
return c;
}
void keyPressed ()
{
if (key == 'b') bDisplayVectorField = !bDisplayVectorField;
if (key == 'p') displayParticle = !displayParticle;
if (key == '+') m.add (new Mover());
if (key == ' ') noiseSeed ((int) random (10000));
if (key == '-')
{
if (m.size() > 0) m.remove (0);
}
}
void displayVectorField()
{
stroke (#b1c999, 40);
stroke (247, 20);
float xSpan = (width - (xRes-1)*(float) padding) / xRes;
float ySpan = (height - (yRes-1)*(float) padding) / yRes;
float x, y, angle;
noFill();
float dis;
float mm = map (posX, 0, width, -1.5, 1.5);
if (mm == 0) mm = 0.0001;
float maxDis = mm*dist (0, 0, width/2, height/2);
float fAngle;
for (int i = 0; i < yRes; i++)
{
for (int j = 0; j < xRes; j++)
{
x = xSpan * j + padding*j + xSpan/2;
y = ySpan * i + padding*i + ySpan/2;
dis = dist (x, y, width/2, height/2);
fAngle = map (dis, 0, maxDis, posY, 0);
angle = map (dis, 0, maxDis, PI, 0) + random (-PI/4*fAngle, PI/4*fAngle);
line (x, y, x+cos (angle) * xSpan, y + sin (angle) * ySpan);
}
}
}