Last active
May 30, 2020 02:24
-
-
Save marcedwards/068c57c9c5fcb39a2fc7a14a8300dc44 to your computer and use it in GitHub Desktop.
Cloud Zoom in Processing
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
// | |
// Cloud Zoom. | |
// Created using Processing 3.5.4. | |
// | |
// Code by @marcedwards from @bjango. | |
// | |
// A GIF of this code can be seen here: | |
// https://twitter.com/marcedwards/status/1266555783061225473 | |
// | |
color[] cols = { #ffeb33, #fd8b45, #ff3351, #9152e1, #ff4d16, #191030 }; | |
PImage buffer; | |
void setup() { | |
size(600, 600, P2D); | |
frameRate(30); | |
smooth(0); | |
buffer = createImage(width, height, RGB); | |
background(0); | |
} | |
void draw() { | |
drawDots(); | |
buffer.copy(g, 0, 0, width, height, 0, 0, width, height); | |
pushMatrix(); | |
translate(width / 2, height / 2); | |
rotate(0.01); | |
scale(1.05, 1.05); | |
translate(-width / 2, -height / 2); | |
image(buffer, 0, 0); | |
popMatrix(); | |
} | |
void drawDots() { | |
loadPixels(); | |
int cx = width / 2; | |
int cy = height / 2; | |
for (int i = 0; i < 120; i++) { | |
int value = int(valueNoise(timeLoop(120), i, 0) * cols.length); | |
int xoff = int(valueNoise(timeLoop(120), i, 2) * 128 - 64); | |
int yoff = int(valueNoise(timeLoop(120), i, 3) * 128 - 64); | |
int x = cx + xoff; | |
int y = cy + yoff; | |
pixels[x + y * width] = cols[value]; | |
} | |
updatePixels(); | |
} | |
float timeLoop(float totalframes) { | |
return (frameCount) % totalframes / totalframes; | |
} | |
float valueNoise(float x, float y, float z) { | |
float v = sin(x * 281 + y * 95317 + z * 703) * 6731; | |
return v - floor(v); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment