Wednesday, March 18, 2015

Programming 3D Anaglyph Approximations in TurtleArt

or Give Yourself a Headache Trying.

I have been playing with this idea in my head for a little while and sat down to try it. How about using TurtleArt to program approximations of 3D anaglyphs, those red and blue images that you wear the red and cyan glasses to view?

I say approximations because a quick google search suggests that to create a true anaglyph you need to use algorithms to figure out the displacement of the two images. However, you can write TurtleArt procedures that are pretty close approximations and do appear to float off the screen (or sink into the screen, depending on how you order your colors) when viewed with the anaglyph glasses.

Here is how I programmed my first anaglyph image in TurtleArt.

Start by programming a procedure to draw a square. I made mine 200 to a side. Name the procedure by adding the diamond-shaped block to the top of the procedure and typing its name.

For these anaglyphs we will program them so they appear to come off the screen. To make them recede into the screen, draw your blue object on the left and the same object in red on the right.

Create another master procedure. I start by clearing the screen. I set the color to red, and I set the shade to 75 to make it light red. Then I draw a square.

Next, we need to offset the turtle from where it was when it drew the first square. Use the setxy block to move the turtle slightly to the right and down.

Next, change the pen color to blue and set the shade back to 50. Draw another square, offset from the first and in blue.

Connect the procedures to create your master procedure. Put on your 3D glasses! Run your procedure by double-clicking the top of your stack of blocks.

Viewed through the red and cyan anaglyph glasses you should see a darker square floating slightly above the monitor. Success!

Next, remix your square procedure and make it do more.

Replace the square block in your master procedure with your new remixed block. Put on your 3D glasses. Run your procedure.


Here are some additional things to try.

  • Adjust how much offset the second drawing is from the first.
  • Reverse your colors so the turtle draws with blue on the left and red on the right. What happens?
  • Create multiple objects in a single project.

After tweeting about this experiment I got a very helpful reply.

Since I am subconsciously biased against left handed turtles, it would seem, I generally make the turtle turn right.

Turning the turtle 7.5 degrees left when you create the design is an optimal offset to work with the 3D anaglyph images you program.

If the turtle turns left, offset the turtle to the left and up.

The results are much more apparent when viewed through the red and cyan glasses.

Many, many thanks, Valeri, for your assistance!


Debby Acevedo said...

Love it, Josh! I have a 3rd grade Turtle Art buddy who is going to want to try this.

hakan gokyer said...

your method is amazing . I like it.