Created
August 18, 2014 00:28
-
-
Save riebschlager/86aa521309ae83e48e75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import toxi.color.*; | |
import toxi.geom.*; | |
import toxi.processing.*; | |
import java.util.*; | |
int num = 100; | |
float r; | |
int c; | |
PImage src; | |
PGraphics canvas; | |
List<ColoredPolygon> polygons = new ArrayList<ColoredPolygon>(); | |
ToxiclibsSupport gfx; | |
void setup() { | |
size(displayWidth, displayHeight); | |
src = loadImage("https://d13yacurqjgara.cloudfront.net/users/265879/screenshots/1687623/1_1x.jpg"); | |
canvas = createGraphics(width * 2, height * 2); | |
canvas.beginDraw(); | |
canvas.background(0); | |
canvas.smooth(); | |
canvas.noStroke(); | |
canvas.endDraw(); | |
gfx = new ToxiclibsSupport(this, canvas); | |
r = width * 1.2; | |
} | |
void draw() { | |
background(255); | |
canvas.beginDraw(); | |
for (ColoredPolygon p : polygons) { | |
p.smooth(0.01, 0.05); | |
canvas.fill(p.col); | |
gfx.polygon2D(p); | |
} | |
canvas.endDraw(); | |
image(canvas, 0,0, width, height); | |
} | |
void mousePressed() { | |
int randX = floor(random(0, src.width)); | |
int randY = floor(random(0, src.height)); | |
c = src.get(randX, randY); | |
ColoredPolygon poly=new ColoredPolygon(c); | |
float radius=r;//random(50,1000); | |
//float mMouseX = map(mouseX, 0, width, 0, canvas.width); | |
//float mMouseY = map(mouseY, 0, height, 0, canvas.height); | |
float mMouseX = canvas.width / 2; | |
float mMouseY = canvas.height / 2; | |
for (int i=0; i < num; i++) { | |
poly.add(Vec2D.fromTheta((float)i/num*TWO_PI).scaleSelf(random(0.8,1)*radius).addSelf(mMouseX, mMouseY)); | |
} | |
polygons.add(poly); | |
r = r > 100 ? r - 75 : 50; | |
} | |
void keyPressed(){ | |
if(key == 's'){ | |
String filename = "output/" + floor(random(1000,10000)) + ".tif"; | |
canvas.save(filename); | |
} | |
if(key == 'c') { | |
canvas.beginDraw(); | |
canvas.background(0); | |
canvas.endDraw(); | |
r = width * 1.2; | |
polygons.clear(); | |
} | |
} | |
class ColoredPolygon extends Polygon2D { | |
int col; | |
public ColoredPolygon(int col) { | |
this.col= col; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment