Forked from anonymous/gist:cc42d733bed53f60fe70bb225893d88a
Last active
October 12, 2016 02:36
-
-
Save Aatch/d240761415bea7de0e54b3606ccff865 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 processing.pdf.*; | |
import java.util.Collection; | |
import java.util.Map; | |
float[] sizes; | |
float[] distortions; | |
float FREQUENCY = 5; | |
int mindiameter = 100; | |
int maxdiameter = 0; | |
float cellWidth; | |
float cellHeight; | |
boolean[][]cells = new | |
boolean[5][4]; | |
Words words; | |
void setup() { | |
words = new Words("lyrics.txt"); | |
sizes = words.relativeSizes(); | |
distortions = words.distortions(); | |
size(1024, 320); | |
background(255); | |
cellWidth = 1024/5; | |
cellHeight = 320/4; | |
maxdiameter = min(width, height) - 20; | |
noStroke(); | |
noLoop(); | |
} | |
void draw() { | |
for (int i = 0; i < sizes.length; i++) { | |
float diameter = (sizes[i] * (maxdiameter - mindiameter)) + mindiameter; | |
float x; float y; | |
float gx; float gy; | |
do{ | |
float[] pos = generatePosition(diameter); | |
x = pos[0]; | |
y = pos[1]; | |
gx = floor(x/cellWidth); | |
gy = floor(y/cellHeight); | |
} while (validPos((int)gx,(int)gy)); | |
drawCircle(x, y, diameter, distortions[i]*(1-sizes[i])); | |
} | |
//save("distortion-test4"); | |
} | |
boolean validPos(int gx, int gy) { | |
if (cells[gx][gy]) return false; | |
else { | |
cells[gx][gy] = true; | |
return true; | |
} | |
} | |
float[2] generatePosition(float diameter) { | |
float radius = diameter/2; | |
float x = random(width); | |
float y = random(height); | |
if ((x - radius) < 0) x = radius; | |
if ((x + radius) > width) x = width - radius; | |
if ((y - radius) < 0) y = radius; | |
if ((y + radius) > height) y = height - radius; | |
return { x, y }; | |
} | |
void drawCircle(float x, float y, float diameter, float distortion) { | |
fill(0, 100); | |
float radius = diameter/2; | |
float d = diameter*(1 + distortion); | |
ellipse(x, y, d, d); | |
beginShape(); | |
for (int i = 0; i < 90; i++) { | |
float angle = (float)(i*4); | |
angle = (angle/180)*PI; | |
float dx = sin(angle)*radius; | |
float dy = cos(angle)*radius; | |
float r = noise((x + dx)/FREQUENCY, (y + dy)/FREQUENCY); | |
r *= distortion*2; | |
r -= distortion; | |
float dist = 1.0 + r; | |
dx *= dist; | |
dy *= dist; | |
float px = x + dx; | |
float py = y + dy; | |
vertex(px, py); | |
} | |
endShape(CLOSE); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment