xxxxxxxxxx
int maxDots = 255;
int distance = 500;
int minProximity = 0;
int maxProximity = 127;
int limit = 1;
dot[] dots = new dot[maxDots];
void setup()
{
fullScreen();
for (int b = 0; b < maxDots; b++)
{
dots[b] = new dot();
}
colorMode(HSB);
}
void draw()
{
background(0);
for (int f = 0; f < limit; f++)
{
dots[f].move();
}
for (int i = 0; i < limit; i++)
{
float c = 1;
for (int j = i + 1; j < limit; j++)
{
float d = dist(dots[i].sx, dots[i].sy, dots[j].sx, dots[j].sy);
if ( d >= minProximity && d <= maxProximity)
{
c++;
line(dots[i].sx, dots[i].sy, dots[j].sx, dots[j].sy);
}
}
stroke(c<<3, 255, 255);
c = constrain(c, 2, 16);
fill(255);
ellipse(dots[i].sx, dots[i].sy, c, c);
}
if (limit < maxDots)
{
limit++;
}
}
class dot
{
int x, y, z, sx, sy;
float ax, ay, az, ix, iy, iz;
dot()
{
x = int(random(-(width/2), width/2));
y = int(random(-(height/2), height/2));
z = int(random(-512, 512));
ax = random(TWO_PI);
ay = random(TWO_PI);
az = random(TWO_PI);
ix = random(0.001, 0.003);
iy = random(0.001, 0.003);
iz = random(0.001, 0.003);
sx = 0;
sy = 0;
}
void move()
{
float rx1, ry1, rz1, rx2, ry2, rz2, rx3, ry3, rz3;
rx1 = x * cos(az) - y * sin(az); //Rotate around the Z axis
ry1 = x * sin(az) + y * cos(az);
rz1 = z;
rx2 = rx1 * cos(ay) - rz1 * sin(ay); //Rotate around the Y axis
rz2 = rx1 * sin(ay) + rz1 * cos(ay);
ry2 = ry1;
ry3 = ry2 * cos(ax) - rz2 * sin(ax); //Rotate around the X axis
rz3 = ry2 * sin(ax) + rz2 * cos(ax);
rx3 = rx2;
sx = int(rx3 * 512 / (rz3 + distance)) + width/2; //Perspective projection on screen
sy = int(ry3 * 512 / (rz3 + distance)) + height/2;
ax += ix;
ay += iy;
az += iz;
}
}