RedBlue – A Processing Library
RedBlue is a library for creating Anaglyph Stereographic 3D images in Processing. RedBlue plugs right in as a renderer in size() and makes the digital world jump out and play! In order to join in the fun, you're going to need a hot pair of specs, as found in a box of sugary cereal from the year 1987.
RedBlue is an extention of P3D, so don't try to make something really huge unless you're rendering to video. I'm quite sorry to let you know that because of this you also cannot use smooth().
Getting it running
size(width, height, "megamu.redblue.RedBlue");
It's just one extra little detail in that friendly size() command that we all know and love. Add “megamu.redblue.RedBlue” as the third parameter, and things should just work! Put on your glasses and let 'er fly.
import megamu.redblue.RedBlue;
public void setup() {
size(640, 480, "megamu.redblue.RedBlue");
noStroke();
}
public void draw() {
background(0);
lights();
rotateY((float)millis()/2000);
translate(200,0,0);
box(50);
}
Advanced things
Lets say for example that you want things to pop out more. You can get this effect, it's just a little weird looking in syntax. I should note that it's been set up to best reflect the distortion that your camera's “lens” produces and if you want things to pop out more, you should be looking at perspective().
setDivergence( float howMuch )
setDivergence() lets you set just how much pop your stereograph gets. The default is 1.0, setting this greater than one will have an increased effect, less than one for a decreased effect and setting this to 0.0 will totally flat. Negative if you're wearing your glasses upside-down.
import megamu.redblue.*;
void setup(){
size(216,216,"megamu.redblue.RedBlue");
}
void draw(){
background(0);
camera();
lights();
float alt = time(1234);
float asm = time(4321);
translate(width/2, height/2, -width/4);
pushMatrix();
rotate( time(567), sin(alt)*sin(asm), cos(alt), sin(alt)*cos(asm) );
box(40);
popMatrix();
for(int i=0; i<16; i++){
rotateX( 1.5*i );
pushMatrix();
rotateY( time(534+i*291) );
translate( map( sin(time(1200+300*i)), -1, 1, 30, 150 ), 0, 0 );
rotate( time(765), sin(alt)*sin(asm), cos(alt), sin(alt)*cos(asm) );
box(20);
popMatrix();
}
}
void mouseMoved(){
float diverge = map(mouseX,0,width,0,2);
((RedBlue)g).setDivergence( diverge );
}
float time(float scaleBy){
return (float)millis()/scaleBy;
}
Similiarily, you can also get back that divergence number in case you lost it somewhere.
getDivergence()
It works much like you would expect, and the syntax is again kinda wonky.
import megamu.redblue.RedBlue;
void setup(){
size(640, 480, "megamu.redblue.RedBlue");
}
void draw(){
float diverge = ((RedBlue)g).getDivergence();
}
RedBlue in OpenGL
This is something that I'm interested in doing. I fought it for a bit and stand defeated for now. If someone is a GL guru and knows how to make this integrate well with Processing, please drop me email. When it works, it'll go live right here.
Install
- Download RedBlue
- Unzip into Processing's libraries folder
- Sketch → Import Library → redblue
megamu.redblue.RedBlue
megamu.redblue.RedBlueOpenGL
- Coming someday...
