/** * Pointillism * by Daniel Shiffman. * * Mouse horizontal location controls size of dots. * Creates a simple pointillist effect using ellipses colored * according to pixels in an image. */ PImage a; int originX; int originY; void setup() { a = loadImage("deadness.jpg"); size(a.width,a.height); noStroke(); background(255); smooth(); originX = 0; originY = 0; } void draw() { //reset it all to a new origin point if(mousePressed){ originX = mouseX; originY = mouseY; background(255); } pointilize(); pointilize(); pointilize(); pointilize(); pointilize(); } void pointilize() { //float pointillize = map(mouseX, 0, width, 2, 18); int x = int(random(a.width)); int y = int(random(a.height)); float distance = max((dist(x,y,originX, originY))/8,1); //color pix = a.get(x, y); //fill(pix, 126); drawCircle(x, y, distance); } void drawCircle(int x, int y, float radius) { radius = ceil(radius); fill(getColorFromCircle(x,y,radius), 126); ellipse(x,y,radius,radius); if(radius > 1){ drawCircle(x, y, radius -1); } } color getColorFromCircle(int x, int y, float radius){ //we want to get a point that is radius away from x,y //the new radius is actually rand()*(radius - floor(radius)) + floor(radius) radius = random(floor(radius-1), radius) + radius; //let's pic a random angle around the circle. int angle = floor(random(0,360)); int newX = floor((cos(angle) * radius)) + x; int newY = floor((sin(angle) * radius)) + y; return a.get(newX, newY); }