Created
July 21, 2019 06:33
-
-
Save samclane/5ee6cd5a29e633044578fe60afe17572 to your computer and use it in GitHub Desktop.
Recreating /u/f-x-p-x's AAA animation. All credit goes to them.
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
/* | |
Recreating /u/f-x-p-x's AAA animation. | |
Requires OpenSimplexNoise.java: | |
https://github.com/CodingTrain/website/blob/master/CodingChallenges/CC_137_4D_Noise_Loop/Processing/CC_137_4D_Noise_Loop/OpenSimplexNoise.java | |
*/ | |
PGraphics pg; | |
float fontSize; | |
int cols = 30; | |
int rows = 30; | |
float zoff = 0; | |
float xoffsp = 0.2; | |
float yoffsp = 0.2; | |
float zoffsp = 0.005; | |
float[][] sizes; | |
float[] multiplyerX; | |
float multiplyerY; | |
float mapCutter = 0.1; | |
float mapCutterSP = 0.0025; | |
float mapCutterANG = 0; | |
OpenSimplexNoise noise; | |
void setup () { | |
size(1080, 1080, P2D); | |
pg = createGraphics(1080, 1080); | |
noise = new OpenSimplexNoise(); | |
fontSize = pg.width/rows; | |
sizes = new float[cols][rows]; | |
multiplyerX = new float[cols]; | |
multiplyerY = 0; | |
noStroke(); | |
} | |
void draw() { | |
mapCutterANG += mapCutterSP; | |
mapCutter = sin(mapCutterANG); | |
background(100); | |
float yoff = 0; | |
for (int y = 0; y < rows; y++) { | |
float xoff = 0; | |
for (int x = 0; x < cols; x++) { | |
sizes[x][y] = map((float) noise.eval(xoff, yoff, zoff), -mapCutter, mapCutter, 0, 1); | |
xoff += xoffsp; | |
} | |
yoff += yoffsp; | |
} | |
zoff += zoffsp; | |
genTexre(); | |
updWidths(); | |
display(); | |
} | |
void updWidths() { | |
for (int y = 0; y < rows; y++) { | |
float sum = 0; | |
for (int x = 0; x < cols; x++) { | |
sum += sizes[x][y]; | |
} | |
multiplyerX[y] = width/sum; | |
} | |
float sum = 0; | |
for (int y = 0; y < rows; y++) { | |
sum += sizes[0][y]; | |
multiplyerY = height/sum; | |
} | |
} | |
void display() { | |
float texHCounter = 0; | |
float texHCounterStep = pg.width/cols; | |
float texWCounterStep = pg.height/rows; | |
float hcounter = 0; | |
for (int y = 0; y < rows; y++) { | |
float texWCounter = 0; | |
float wcounter = 0; | |
for (int x = 0; x < cols; x++) { | |
beginShape(QUAD); | |
textureMode(IMAGE); | |
texture(pg); | |
vertex(wcounter, hcounter, texWCounter, texHCounter); | |
vertex(wcounter+sizes[x][y]*multiplyerX[y], hcounter, texWCounter+texWCounterStep, texHCounter); | |
vertex(wcounter+sizes[x][y]*multiplyerX[y], hcounter+sizes[0][y]*multiplyerY, texWCounter+texWCounterStep, texHCounterStep+texHCounter); | |
vertex(wcounter, hcounter+sizes[0][y]*multiplyerY, texWCounter, texHCounterStep+texHCounter); | |
endShape(); | |
wcounter += sizes[x][y]*multiplyerX[y]; | |
texWCounter += texWCounterStep; | |
} | |
texHCounter += texHCounterStep; | |
hcounter += sizes[0][y]*multiplyerY; | |
} | |
} | |
void genTexre() { | |
pg.beginDraw(); | |
pg.background(0); | |
pg.textSize(fontSize); | |
pg.textAlign(CENTER, BOTTOM); | |
for (int y = 0; y < rows; y++) { | |
for (int x = 0; x < cols; x++) { | |
pg.pushMatrix(); | |
pg.translate(x*fontSize+fontSize/2, y*fontSize+fontSize); | |
pg.fill(255); | |
pg.text("X", 0, 0, 0); | |
pg.popMatrix(); | |
} | |
} | |
pg.endDraw(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment