Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float[][] noiseMap;
- ArrayList<Brush> brushes;
- PImage imgMap;
- int num = 2000, min=2, max=50;
- float noiseIncr = .01, drain=.05, brushSize;
- void setup() {
- imgMap = loadImage("nathalie.jpg");
- size(imgMap.width, imgMap.height);
- noiseMap = new float[width][height]; //creating a 2D array for the noise values to be used later
- brushes = new ArrayList<Brush>();
- float xstart = random(10);
- float xnoise = xstart;
- float ynoise = random(10);
- for (int y=0; y<height; y++) {
- ynoise += noiseIncr;
- xnoise = xstart;
- for (int x=0; x<width; x++) {
- xnoise += noiseIncr;
- float myNoise = noise(xnoise, ynoise);
- noiseMap[x][y] = myNoise;
- }
- }
- }
- void draw() {
- brushSize = constrain(map(frameCount, 0, 1000, max, min), min, max);
- if (brushes.size()<num) brushes.add(new Brush(new PVector(random(width), random(height))));
- for (int i=0; i<brushes.size(); i++) {
- Brush brush = brushes.get(i);
- brush.move();
- brush.display();
- brush.life -= drain; //the brush dies at a certain point and gets reborn somewhere else
- if (brush.life<0) {
- brush.life = 1;
- brush.resetPosition();
- }
- }
- }
- void keyPressed() {
- save(random(2334234)+".tif");
- }
- class Brush {
- PVector location;
- PVector velocity = new PVector(0, 0);
- float angle, life=1.0;
- color s;
- Brush(PVector _location) {
- location = _location;
- createVector();
- }
- void move() {
- location.add(velocity);
- }
- void display() {
- strokeWeight(brushSize);
- stroke(s, 20);
- point(location.x, location.y);
- }
- void resetPosition() {
- location = new PVector(random(width), random(height), 0);
- createVector();
- }
- void createVector() {
- s = imgMap.get(int(location.x), int(location.y));
- angle = noiseMap[int(location.x)][int(location.y)] * TWO_PI; // an angle gets created based on the noise values
- velocity.add(cos(angle), sin(angle), 0); //that angle gets turned into a velocity vector that gets normalized in the next step
- velocity.normalize();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement