Skip to content

Instantly share code, notes, and snippets.

@brendandawes
Last active June 1, 2016 13:09
Show Gist options
  • Save brendandawes/a7906d22b7a76d5c61e2ab1d830fbe27 to your computer and use it in GitHub Desktop.
Save brendandawes/a7906d22b7a76d5c61e2ab1d830fbe27 to your computer and use it in GitHub Desktop.
My little interpretation of the Reasons.to R
// Requires the DawesomeToolkit http://cloud.brendandawes.com/dawesometoolkit
import java.util.Collections;
import java.util.Random;
import dawesometoolkit.*;
import processing.pdf.*;
ArrayList<PVector> vectors;
DawesomeToolkit dawesome;
ArrayList<Integer> colors;
boolean record = false;
void setup() {
size(800, 800);
dawesome = new DawesomeToolkit(this);
dawesome.enableLazySave('s', ".png");
colors = dawesome.colorSpectrum(16, 100, 50);
vectors = alphaMaskToVectors("reasonslogo.png");
long seed = System.nanoTime();
Collections.shuffle(vectors, new Random(seed));
smooth();
}
void draw() {
if (record) {
String filename = dawesome.uniqueFileName();
beginRecord(PDF, filename+".pdf");
}
background(255);
int count = 0;
for (PVector p: vectors){
if (count%13==0){
fill(colors.get(count%colors.size()));
float dotSize = count%25;
if (count%2==0){
rect(p.x, p.y, dotSize, dotSize);
} else {
ellipse(p.x, p.y, dotSize, dotSize);
}
}
count++;
}
if (record) {
endRecord();
record = false;
println("finished pdf");
}
}
ArrayList alphaMaskToVectors(String file){
PImage img = loadImage(file);
ArrayList vectors = new ArrayList();
for (int i=0; i < img.width; i++) {
for (int j=0; j < img.height; j++) {
color c = img.get(i,j);
if (red(c) != 255 && green(c) != 255 && blue(c) != 255) {
vectors.add(new PVector(i,j));
}
}
}
return vectors;
}
void keyPressed() {
if (key=='p'){
record = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment