131 lines
2.3 KiB
Plaintext
131 lines
2.3 KiB
Plaintext
// Based on Listing 5.1, Generative Art
|
|
float xstart, xnoise, ystart, ynoise, tnoise;
|
|
float x_end1, y_end1;
|
|
float x_end2, y_end2;
|
|
|
|
int num = 1;
|
|
Walker[] walkers = new Walker[num];
|
|
|
|
float magnitude;
|
|
float angle;
|
|
float noise_speed;
|
|
|
|
int width = 500;
|
|
int height= 500;
|
|
int cache_len = width * height;
|
|
|
|
float[] temp_xy;
|
|
float[][] mag_angle_list = new float[250000][2];
|
|
int j,k;
|
|
|
|
void setup() {
|
|
size(500, 500);
|
|
background(255);
|
|
xstart = random(10);
|
|
ystart = random(10);
|
|
frameRate(25);
|
|
|
|
textSize(30);
|
|
|
|
for (int i = 0; i < num; i++){
|
|
walkers[i] = new Walker(i);
|
|
}
|
|
|
|
|
|
|
|
ynoise = ystart;
|
|
|
|
j = 0;
|
|
for (int y = 1; y <= height; y+=1) {
|
|
ynoise += 0.01;
|
|
xnoise = xstart;
|
|
for (int x = 1; x <= width; x+=1) {
|
|
xnoise += 0.01;
|
|
angle = noise(xnoise, ynoise, tnoise) * 3.14 * 2;
|
|
|
|
x_end1 = (2 * cos(angle)) + x;
|
|
y_end1 = (2 * sin(angle)) + y;
|
|
|
|
mag_angle_list[j][0] = x_end1;
|
|
mag_angle_list[j][1] = y_end1;
|
|
|
|
j = j + 1;
|
|
|
|
if ((y % 10) == 0) {
|
|
if ((x % 10) == 0) {
|
|
line(x, y, (5 * cos(angle)) + x, (5 * sin(angle)) + y);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
void draw() {
|
|
background(255);
|
|
|
|
// println(frameRate);
|
|
// xstart += 0.01;
|
|
// ystart += 0.01;
|
|
|
|
for (int i = 0; i < num; i++){
|
|
temp_xy = walkers[i].getLocation();
|
|
// lookup mechanism
|
|
int idx = (int)(((temp_xy[1] ) * width) + temp_xy[0]);
|
|
// let y = 10, x = 10
|
|
// int idx = 5010;
|
|
|
|
float next_x = mag_angle_list[idx][0];
|
|
float next_y = mag_angle_list[idx][1];
|
|
|
|
// println((int)next_x,(int)next_y);
|
|
walkers[i].update((int)next_x,(int)next_y);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
class Walker {
|
|
// fields
|
|
String s;
|
|
float x, y, a;
|
|
float tx, ty, ta;
|
|
color c;
|
|
|
|
// constructor
|
|
Walker(int i) {
|
|
s = nf(i);
|
|
x = random(width);
|
|
y = random(height);
|
|
tx = random(1000);
|
|
ty = random(1000);
|
|
ta = random(1000);
|
|
c = color(2,2,2);
|
|
// c = color(random(255),random(255),random(255));
|
|
}
|
|
|
|
float[] getLocation(){
|
|
return new float[]{x,y};
|
|
}
|
|
|
|
// method
|
|
void update(float next_x, float next_y) {
|
|
stroke(color(255, 0, 0));
|
|
circle(next_x, next_y, 5);
|
|
this.x = next_x;
|
|
this.y = next_y;
|
|
|
|
if (x<10)
|
|
{x = 479;}
|
|
else if (x>480)
|
|
{x = 1;}
|
|
if (y<10)
|
|
{y = 479;}
|
|
else if (y>480)
|
|
{y = 1;}
|
|
}
|
|
}
|