Created
March 30, 2020 22:01
-
-
Save clemp/16d0ffdc553a7a2f8b8cf53d2f447841 to your computer and use it in GitHub Desktop.
3d pixel effects
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
import peasy.*; | |
PeasyCam cam; | |
PImage img; | |
float[][] reds; | |
float[][] greens; | |
float[][] blues; | |
float progress; | |
void setup() { | |
size(600, 600, P3D); | |
cam = new PeasyCam(this, 500); | |
background(0); | |
img = loadImage("/home/christian/Documents/profile-photo.png"); // <--- use your own picture here smaller pics work best. 320x240 | |
reds = new float[img.width][img.height]; | |
greens = new float[img.width][img.height]; | |
blues = new float[img.width][img.height]; | |
for (int j = 0; j < img.height; j++) { | |
for (int i = 0; i < img.width; i++) { | |
color c = img.get(i, j); | |
reds[i][j] = red(c); | |
greens[i][j] = green(c); | |
blues[i][j] = blue(c); | |
} | |
} | |
} | |
void draw() { | |
background(0); | |
translate(-width/4, width/4); | |
stroke(255, 0, 0); | |
line(0, 0, 0, 255, 0, 0); | |
stroke(0, 255, 0); | |
line(0, 0, 0, 0, -255, 0); | |
stroke(0, 0, 255); | |
line(0, 0, 0, 0, 0, 255); | |
strokeWeight(1); | |
for (int j = 0; j < img.height; j++) { | |
for (int i = 0; i < img.width; i++) { | |
float lerpX = lerp(i, reds[i][j], progress); | |
float lerpY = lerp(img.height-j, greens[i][j], progress); | |
float lerpZ = lerp(0, blues[i][j], progress); | |
stroke(color(reds[i][j], greens[i][j], blues[i][j])); | |
pushMatrix(); | |
translate(lerpX, -lerpY, lerpZ); | |
point(0, 0); | |
popMatrix(); | |
} | |
} | |
if(progress < 1.0) progress += 0.01; | |
// progress = map(mouseX, 0, width, 0, 1.0); // <--- control the progress with the mouse | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment