Created
May 27, 2012 18:20
-
-
Save companje/2815350 to your computer and use it in GitHub Desktop.
Spherical lens effect for spinning globe
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 processing.video.*; | |
PImage bg; | |
Movie mov; | |
final int w=255; | |
void setup() { | |
size(w,w); | |
frameRate(30); | |
bg = loadImage("earth1024.jpg"); | |
mov = new Movie(this,"clouds.mov"); | |
mov.loop(); | |
} | |
void draw() { | |
background(0); | |
if (mov.available()) mov.read(); | |
if (mov.width==1) return; | |
for (int j=0; j<w; j++) { | |
for (int i=0; i<w; i++) { | |
float x=-1+2.0*i/w; | |
float y=-1+2.0*j/w; | |
float m=x*x+y*y; //0..2 | |
float t=(3-sqrt(4-5*m))/(m+1); //t=1...1.642 | |
int xx=int(map(x*w*t+frameCount,-370,370,-256,256)+512); | |
int yy=int(map(y*w*t,-370,370,-256,256)+256); | |
if (xx<0) xx+=1024; | |
if (xx>1024) xx-=1024; | |
if (yy<0) yy+=512; | |
if (yy>512) yy-=512; | |
if (m<.8) set(i,j,blendColor(mov.get(xx,yy), bg.get(xx,yy), SCREEN)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment