# Cross-eyed stereoscopy

**URL:** <https://discourse.processing.org/t/cross-eyed-stereoscopy/38637>\
**Category:** Gallery\
**Created:** [September 3, 2022, 11:19pm UTC](https://discourse.processing.org/t/cross-eyed-stereoscopy/38637 "2022-09-03T23:19:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![scudly](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/scudly/32/5597_2.png) [@scudly](https://discourse.processing.org/u/scudly)\
**Post date:** [September 3, 2022, 11:19pm UTC](https://discourse.processing.org/t/cross-eyed-stereoscopy/38637/1 "2022-09-03T23:19:26Z")

</div>

Here is some code for rendering cross-eyed stereo images of 3-D scene with some simple `camera()` and `frustum()` calls. It creates images such as this one:

 ![stereo](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/e/2/e2171a38fd21014c3b8f7e3f49f00fd5311f35f2.png)

To view the image, gently cross your eyes until you see three images. Focus on the center one and let it come into focus. Sadly, not all people are able to focus the images this way.

For other examples, see [https://gfycat.com/giftedrichharpyeagle](https://gfycat.com/giftedrichharpyeagle) and [https://gfycat.com/alertgrizzledcrab](https://gfycat.com/alertgrizzledcrab).

Here’s the code. Press ENTER to cycle through different terrains.

```auto
float seed;
PGraphics img;
boolean bSaveFrame = false;

void setup() {
  size( 1200, 600, P3D );
  img = createGraphics( width/2, height, P3D );
  seed = random(1000000);
}

void draw() {
  float d = 0.1;
  drawScene( img, d, seed );
  image( img, 0, 0, width/2, height );
  drawScene( img, -d, seed );
  image( img, width/2, 0, width/2, height );
  if( bSaveFrame ) {
    save("stereo.png");
    bSaveFrame = false;
  }
}

void drawScene( PGraphics pg, float offset, float seed ) {
  pg.beginDraw();
  pg.colorMode( HSB, 1, 1, 1, 1 );
  pg.background( 0 );

  float s = 1.0/sqrt(3); // scaling for a 60 degree camera angle
  pg.camera( offset, 0.0, 2., offset, 0.0, 0.0, 0, 1, 0 );
  pg.frustum( -s-offset*0.666, s-offset*0.666, -s, s, 1, 4 );

  // Create your scene here within 1 unit of the origin
  randomSeed( (long)seed );
  noiseSeed( (long)seed );
  pg.rotateX( TAU/6 );
  pg.rotateZ( TAU*frameCount/600. );
  pg.scale( 0.98 );
  pg.strokeWeight( 5 );
  pg.beginShape(LINES);
  for( float x = -1; x<=1; x+= 0.02 )
    for( float y = -1; y<=1; y += 0.02 ) {
      float z = noise( x+17, y-5 )-0.5+random(0.01);
      pg.stroke( .5-2.*z, 0.7, 1 );
      pg.vertex( x, y, -0.25 );
      pg.vertex( x+random(0.01), y+random(0.01), z );
    }
  pg.endShape(CLOSE );

  pg.endDraw();
}

void keyPressed() {
  if( keyCode == ENTER )
    seed = random(1000000);
  else if( key == '+') bSaveFrame = true;
}

```

If you want more, there is also a reddit group with mostly still images: [https://reddit.com/r/CrossView/](https://reddit.com/r/CrossView/)
