ProcessingでGenerative art #56
Code
Particle[] particles = new Particle[4000];
int particlesCount = 4000;
float noiseScale = 800, noiseStrength = 30;
float pAlpha = 30, strokeWidth = 0.3;
int drawMode = 1;
void setup() {
size(800, 800);
pixelDensity(2);
background(255);
for (int i=0; i<particles.length; i++) {
particles[i] = new Particle();
}
}
void draw() {
for (int i=0; i<particlesCount; i++) {
particles[i].run();
}
}
void keyPressed() {
if (key == BACKSPACE)background(255);
if (key == ' ') {
int newNoiseSeed = (int)random(10000);
noiseSeed(newNoiseSeed);
}
}
//-----------------------------------------------------------------
class Particle {
PVector pos, posOld;
float stepSize, angle;
boolean isOutside = false;
Particle() {
pos = new PVector(random(width), random(height));
posOld = new PVector(pos.x, pos.y);
stepSize = random(1, 5);
}
void update() {
angle = noise(pos.x/noiseScale, pos.y/noiseScale) * noiseStrength;
pos.x += cos(angle) * stepSize;
pos.y += sin(angle) * stepSize;
if (pos.x<-10) isOutside = true;
else if (pos.x>width+10)isOutside = true;
else if (pos.y<-10)isOutside = true;
else if (pos.y>height+10)isOutside = true;
if (isOutside) {
pos.x = random(width);
pos.y = random(height);
posOld.set(pos);
}
}
void draw() {
float col = map(angle, 0, noiseStrength, 0, 255);
stroke(102, 98, col, pAlpha);
strokeWeight(strokeWidth * stepSize);
line(posOld.x, posOld.y, pos.x, pos.y);
posOld.set(pos);
isOutside = false;
}
void run() {
update();
draw();
}
}
Happy coding!
応援してくださる方!いつでもサポート受け付けてます!