1.3. The basics

This chapters explain the basic structure of Anableps: canvases and scenes, and how to print and display them.

1.3.1. Two worlds (actually, many more)

As you see, in the first example (hello1), we were working in 2D whereas for the second we created a 3D scene. In Anableps, there are objects and commands that apply to 2D while others operate in 3D. To deal with this, Anableps keeps all the time an active canvas and an active scene. They are appropriately called canvas and scene.

In most cases, the context is enough for the interpreter to know where are we working:

circle c1 : .from 10 10 .to 20 20

Note that in other situations, it is not. For example, in the following code:

line l: .from p1 .to p2
rectangle r:

Line l will be used in a canvas or the scene, depending whether the points are R2 or R3 points. However, if we just create rectangle r as it is, without giving any extra hint, it could belong to the current canvas or the current scene. In those (rare) cases, use the sufixes 2 and 3 when creating objects

line2 l: .from 10 10 .to 20 20

and:

line3 l: .from 10 10 10 .to 10 20 20

1.3.1.1. Back to canvas and scene

We just said that the canvas and scene variables hold the current surface and volume to work, but you are not limited to these two: they are just the default ones, in the sense that everything that is produced is added to them implicitly, but you can:

  1. Change the scene, so you write onto different scenes, by setting the parameter scene to different objects:

    scene = myScene
    
  2. Explicitly define to which scene/canvas the object belongs:

    cube c: .scene scene2 # this cube is created in scene2
    
  3. Set which reference will be the default scene or canvas:

    ????
    

Let’s see the following examples:

cube c .size 20cm
cube d .size 30cm
oldscene = scene
scene = new scene :
cube e .size 40cm

Cube e is in a different scene to cube c and cube d. We have stored the old one in the variable oldScene and created a new empty one, where we place the cube e. The sames goes for canvases:

line l : .from 10 10 .to 20 20
oldCanvas = canvas
canvas = new Canvas: .size 40 40
line m: .from l.p1 .to 20 20   ## ERROR! l1 is not on this canvas!

The other choice is, when working with different scenes, to define explicitly to which scene an object belongs:

scene myNewScene:   ## we create a new scene
cube c: .size 20cm  ## this goes to the default scene
cube d: .size 40cm .scene myNewScene
place d: .right@c.left
                    ## !!ERROR d and c are not in the same world!!
Note:There is absolutely no connection among different scenes… well, unless you decide to place a scene into other. That is used, for example in diorames.

As you’ll see, in Anableps, there are lots of default objects that sit there, silently, taking care of the ropes and cranks of the mechanism, so the user doesn’t have to define it all every time (in the old java style). The advanced user, on the contrary, can start playing with them to harness all the power available.

1.3.2. Basics of drawing

Drawing in Anableps is done by PLACING shapes on a canvas, or objects on a scene.

1.3.2.1. The silk layer in 2D

1.3.2.2. Displaying the pictures

1.3.3. Basics of 3D drawing

asdfsa

1.3.3.1. Silk layer in 3d

1.3.3.2. Rendering the pictures

Once we have created our picture, there are several ways to display. We can display it in a window, or we can render to a file