Hi everyone!
I hope you are all well, considering the circumstances.
I am a Graphic Designer and have just begun exploring Generative Art and Processing. I’ve watched tutorials about Perlin Noise, which is beautiful on its own. I was wondering if anyone could help me find a way, if possible, to have it take on the forms/shapes of a referenced image.
Thank you!! I hope you all stay safe, stay well, and stay inside!
The following is the current code:
FlowField flowfield;
ArrayList<Particle> particles;
boolean debug = false;
void setup() {
size(1200, 800);
flowfield = new FlowField(10);
flowfield.update();
particles = new ArrayList<Particle>();
for (int i = 0; i < 10000; i++) {
PVector start = new PVector(random(width), random(height));
particles.add(new Particle(start, random(2, 7)));
}
background(0);
colorMode (HSB, 360, 100, 100);
}
void draw() {
flowfield.update();
if (debug) flowfield.display();
for (Particle p : particles) {
p.follow(flowfield);
p.run();
}
}
public class FlowField {
PVector[] vectors;
int cols, rows;
float inc = 0.1;
float zoff = 0;
int scl;
FlowField(int res) {
scl = res;
cols = floor(width / res) + 1;
rows = floor(height / res) + 1;
vectors = new PVector[cols * rows];
}
void update() {
float xoff = 0;
for (int y = 0; y < rows; y++) {
float yoff = 0;
for (int x = 0; x < cols; x++) {
float angle = noise(xoff, yoff, zoff) * TWO_PI * 2;
PVector v = PVector.fromAngle(angle);
v.setMag(1);
int index = x + y * cols;
vectors[index] = v;
xoff += inc;
}
yoff += inc;
}
zoff += 0.0000000004;
}
void display() {
for (int y = 0; y < rows; y++) {
for (int x = 0; x < cols; x++) {
int index = x + y * cols;
PVector v = vectors[index];
stroke(HSB, 360, 360);
strokeWeight(0.1);
pushMatrix();
translate(x * scl, y * scl);
rotate(v.heading());
line(0, 0, scl, 0);
popMatrix();
}
}
}
}
public class Particle {
PVector pos;
PVector vel;
PVector acc;
PVector previousPos;
float maxSpeed;
Particle(PVector start, float maxspeed) {
maxSpeed = maxspeed;
pos = start;
vel = new PVector(0, 0);
acc = new PVector(0, 0);
previousPos = pos.copy();
}
void run() {
update();
edges();
show();
}
void update() {
pos.add(vel);
vel.limit(maxSpeed);
vel.add(acc);
acc.mult(0);
}
void applyForce(PVector force) {
acc.add(force);
}
void show() {
stroke(180, 360, 360, 5);
strokeWeight(1);
line(pos.x, pos.y, previousPos.x, previousPos.y);
//point(pos.x, pos.y);
updatePreviousPos();
}
void edges() {
if (pos.x > width) {
pos.x = 0;
updatePreviousPos();
}
if (pos.x < 0) {
pos.x = width;
updatePreviousPos();
}
if (pos.y > height) {
pos.y = 0;
updatePreviousPos();
}
if (pos.y < 0) {
pos.y = height;
updatePreviousPos();
}
}
void updatePreviousPos() {
this.previousPos.x = pos.x;
this.previousPos.y = pos.y;
}
void follow(FlowField flowfield) {
int x = floor(pos.x / flowfield.scl);
int y = floor(pos.y / flowfield.scl);
int index = x + y * flowfield.cols;
PVector force = flowfield.vectors[index];
applyForce(force);
}
}