Created
October 12, 2016 02:29
-
-
Save anonymous/cc42d733bed53f60fe70bb225893d88a 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() { | |
float x; float y; | |
float gx; float gy; | |
for (int i = 0; i < sizes.length; i++) { | |
do{ | |
x = random(width); | |
y = random(height); | |
gx = floor(x/cellWidth); | |
gy = floor(y/cellHeight); | |
} while (validPos((int)gx,(int)gy)); | |
float diameter = (sizes[i] * (maxdiameter - mindiameter)) + mindiameter; | |
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; | |
} | |
} | |
void drawCircle(float x, float y, float diameter, float distortion) { | |
fill(0, 100); | |
float radius = diameter/2; | |
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; | |
float d = radius*2*(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