Skip to content

Instantly share code, notes, and snippets.

# Bleuje/cubeperspectiveeffect.pde

Last active December 18, 2022 09:38
Show Gist options
• Save Bleuje/14cd23f2ce3a69d7712f5b66aaceaa0d to your computer and use it in GitHub Desktop.
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
 // Processing code by Etienne JACOB // inspired by beesandbombs : https://twitter.com/beesandbombs/status/1563110024204787712 // motion blur template by beesandbombs int[][] result; float t, c; // utils... most unused here float c01(float x) { return constrain(x,0,1); } float ease(float p) { return 3*p*p - 2*p*p*p; } float ease(float p, float g) { if (p < 0.5) return 0.5 * pow(2*p, g); else return 1 - 0.5 * pow(2*(1 - p), g); } float map(float x, float a, float b, float c, float d, boolean constr) { return constr ? constrain(map(x,a,b,c,d),min(c,d),max(c,d)) : map(x,a,b,c,d); } float mp01(float x, float a, float b) { return map(x,a,b,0,1,true); } float pow_(float p,float g) { return 1-pow(1-p,g); } float tanh(float x) { return (float)Math.tanh(x); } float softplus(float q,float p){ float qq = q+p; if(qq<=0){ return 0; } if(qq>=2*p){ return qq-p; } return 1/(4*p)*qq*qq; } float mn = .5*sqrt(3), ia = atan(sqrt(.5)); void push() { pushMatrix(); pushStyle(); } void pop() { popStyle(); popMatrix(); } void draw() { if (!recording) { t = (mouseX*1.4/width)%1; c = mouseY*1.0/height; if (mousePressed) println(c); draw_(); } else { for (int i=0; i> 16 & 0xff; result[i][1] += pixels[i] >> 8 & 0xff; result[i][2] += pixels[i] & 0xff; } } loadPixels(); for (int i=0; i f2 = f*CZ/bCZ; float f2 = f*CZ/baseCameraZ; float px = f2*x/(CZ-z); float py = f2*y/(CZ-z); return new PVector(px,py); } PVector rotX(PVector v_in,float theta) { float y = v_in.y*cos(theta) - v_in.z*sin(theta); float z = v_in.y*sin(theta) + v_in.z*cos(theta); return new PVector(v_in.x,y,z); } PVector rotY(PVector v_in,float theta) { float x = v_in.x*cos(theta) - v_in.z*sin(theta); float z = v_in.x*sin(theta) + v_in.z*cos(theta); return new PVector(x,v_in.y,z); } void showCube(float p,int mode,float sz,int showEdges) { int nn = (showEdges==0?n:2*(n-1)+1); for(int i=0;i=2) // don't draw in this case (kind of a simple brute force algo to draw only on the edges) continue; } float x0 = map(i,0,nn-1,-L,L); float y0 = map(j,0,nn-1,-L,L); float z0 = map(k,0,nn-1,-L,L); PVector v0 = new PVector(x0,y0,z0); float d = v0.mag(); float s = map(pow(c01(sin(PI*((7*t-0.0065*d+1234*4)%1))),2.5),0,1,3.2,5.0); PVector vrot = rotY(v0,2*HALF_PI*(mode==0?p:-p)+QUARTER_PI); vrot = rotX(vrot,-0.27*HALF_PI*(mode==0?1:-1)); PVector proj = project(vrot.x,vrot.y,vrot.z,1-sin(PI*p)); stroke(255,255,255,120); strokeWeight(sz*s); point(proj.x,proj.y); } } } } void setup(){ size(600,600,P2D); result = new int[width*height][3]; } void draw_(){ background(0); push(); translate(width/2,height/2); float m = 60; // number of drawn dots with more or less delay, per particle for(int i=0;i=1?1:0),sz,0); showCube(p,(p0>=1?1:0),sz,1); } pop(); }
to join this conversation on GitHub. Already have an account? Sign in to comment