Generative Art #140
Code
ArrayList<Particle> particles;
int num = 200;
//int[] colors = {#58355e ,#e03616 ,#fff689 ,#cfffb0 ,#5998c5};
int[] colors = {#ed9e1e ,#d13247 ,#00c6e5 ,#4ea3e8 ,#00a1f2};
void setup() {
size(900, 900);
pixelDensity(2);
colorMode(HSB, 360, 100, 100, 100);
newParticles();
}
void draw() {
for (Particle p : particles) {
p.run();
}
}
void tile(){
int count = 20;
float w = width/count;
noFill();
strokeWeight(0.5);
stroke(0);
for(int j = 0; j < count; j++){
for(int i = 0; i < count; i++){
rect(i*w, j*w, w, w);
}
}
}
void newParticles(){
background(#ffffff);
tile();
particles = new ArrayList<Particle>();
for (int i = 0; i < num; i ++) {
particles.add(new Particle());
}
}
void mousePressed() {
//redraw();
noiseSeed((int)random(100000));
newParticles();
}
void keyPressed() {
if (key == 's')saveFrame("####.png");
}
int getCol() {
return colors[(int)random(colors.length)];
}
class Particle {
PVector pos;
float step, tStep;
float s, t;
color c1, c2;
color col, alph;
float angle;
float noiseScale, noiseStrength, noiseZ;
Particle() {
pos = new PVector(random(width), random(height));
step = random(0.5, 2);
tStep = random(0.1);
s = 10;
t = random(10);
c1 = getCol();
c2 = getCol();
alph = 20;
noiseScale = 750;
noiseStrength = 50;
noiseZ = 0;
}
void show() {
noStroke();
fill(col, alph);
circle(pos.x, pos.y, map(sin(t), -1, 1, 0, 1) * s);
}
void move() {
angle = noise(pos.x/noiseScale, pos.y/noiseScale, noiseZ) * noiseStrength;
pos.x += cos(angle) * step;
pos.y += sin(angle) * step;
noiseZ += 0.001;
t += tStep;
col = lerpColor(c1, c2, map(sin(t), -1, 1, 0, 1));
}
void run() {
show();
move();
}
}
パーティクルが大きさと色を変えながらパーリンノイズ の軌跡を取る。
Happy coding!
応援してくださる方!いつでもサポート受け付けてます!