Category turtleSpaces Development Updates

Introducing Spaces

Spaces contain subsets of the broader turtleSpaces primitive (keyword) set dedicated to various types of creation. They also have restricted feature sets, to enable gradual exposure to everything turtleSpaces has to offer.

You can select a Space from the menu provided by clicking on the name of the current Space (eg omniSpace) in the top-left corner of the web IDE, or by clicking on the link in the following list:

welcomeSpace (2D) – a very simple Space with only basic turtle commands and no editor

penSpace (2D) – has a simple editor and the subset of turtle pen commands

wireSpace (2D) – like penSpace but in three dimensions

artSpace (2D) – adds the ability to create fills (arbitrary 2D shapes) and other goodies

designSpace (2D) – adds shapes and text fonts

animationSpace (2D) – adds movement capabilities

physiSpace (2D) – adds 2D physics functionality

actionSpace (2D) – adds missiles, objects and other game-related functionality

textSpace – dedicated to text / list manipulation

musicSpace – dedicated to MIDI music creation

omniSpace – everything!

To come:

modelSpace (3D) – assisted 3D model creation

motionSpace (3D) – 3D animation

(simulationSpace, virtualSpace…?)

Each Space also has its own published / example database containing projects that use the keywords available in the Space.

IDE now available in offline (downloaded) version

We are pleased to announce that turtleSpaces now supports offline use of the web-based Integrated Development Environment. Simply download turtleSpaces for your relevant platform, and once you’ve signed in to a local account, type IDE in the console.

Your default web-browser should then open with the IDE in a new window or tab. You can use this IDE to control your local copy of turtleSpaces. This means that execution of Logo programs will generally happen much faster. Loading and saving will happen to / from your local turtleSpaces folder (present in your home or User folder).

 

Bales, Missiles and Triggers, Oh My!

turtleSpaces is great for creating 3D models and animations, but we also want it to be great for games. Unfortunately, the interpreter is not the fastest thing around — but that’s okay! We can compensate by creating new commands that work ‘under the hood’ to take care of certain game elements.

Bales are groups of turtles that all execute the same code, for example alien attackers in a space battle game. They are declared similarly to turtles, using a NEWBALE declaration.

When each member of a bale is initialized, it executes the code in the bale’s INIT procedure. Then, it repeatedly executes the code in the MAIN procedure in sequence with the other members of the bale, that is each member of the bale executes the code in succession using the same thread. At the end of each cycle, when all bale members have executed, their ‘turtle tracks’ are rendered. This makes it seem like they’ve all moved at the same time.

Take for example this code from a Space Invaders-inspired game (you can try it out here: https://turtlespaces.org/weblogo/?pub=81)

NEWBALE "ships

TO init
  ;bales are groups of turtles that execute the same code in sequence,
  ;one after the other. They are useful for things like groups of
  ;enemies, to keep them in lock step, where hatchlings can end up
  ;executing at different rates of speed and fall out of sequence
  ;with each other.
  
  ;new bale members always execute the init procedure, after which
  ;they repeatedly execute the main procedure until they are
  ;removed or the entire bale is stopped.
  
  penup
  noaudiowait
  newmodel "bullet [setfillcolor 15 icosphere 1.5]
  setmodelscale 1.5
  setposition {
    (-150 + 30 * (remainder baleindex - 1 5))
    100 - (20 * (int ((baleindex - 1) / 5)))
    5
  }
  ;based on the number (index) of the bale member, place
  ;it in the attacking wave
  
  if 1 = remainder int (baleindex - 1) / 5 2 [setx xpos + 10]
  ;let's offset the turtles in alternating rows
  
  right 180
  ;turn to face down
  
  showturtle
  ;show the turtle
  
  rollright baleindex * 10
  ;set the default roll rotation
  
  output [dir 1]
  ;the pairs provided by output become variables in main
  ;in this case we're setting the default move direction, which
  ;is the same for all members in this bale
END

Each member of the bale is placed based upon its index number in the bale. Once we position the bale member, it moves on to the main execution loop:

TO main
  dosleep 10 [
    ;take at least 10 milliseconds to do the following:
    
    rollright 10
    ;roll right ten degrees
    
    if and xpos < 150 :dir = 1 [drift 5 [1 0 0] drift 1 [0 -1 0]] if and xpos = 150 :dir = 1 [make "dir 0 drift 10 [0 0 -1] drift 10 [0 -1 0]] if and xpos > -150 :dir = 0 [drift 5 [-1 0 0] drift 1 [0 -1 0]]
    if and xpos = -150 :dir = 0 [make "dir 1 drift 10 [0 0 1] drift 10 [0 -1 0]]
    ;we use drift to move the ships because we're rolling them for effect
    
    if 1 = random 20 [
      newmissile "missile "bullet [0 -1 0] 20 + random 20 [200]
      playsound "zap3
    ]
    ;fire a missile randomly
    
    if or ypos < -100 containsp "myrtle near position 20 [ make "hit true ] ;if an alien reaches the bottom of the screen it's over if baleindex = last balemembers balename [ if :delay > 0 [dec "delay]
      ;this increases the speed of the invaders 'music'
      ;once each time all the bale turtles have executed
      ;(each loop)
    ]
  ]
END

Each bale member moves across the screen, randomly firing missiles, until they are destroyed or reach the bottom of the screen, triggering a ‘game over’ condition.

newmissile "missile "bullet [0 -1 0] 20 + random 20 [200]

Missiles are simple elements that are controlled by the game engine. They move through 3D space, and are detected by primitives such as NEARMISSILEP and NEARMISSILES. They can also be detected by the nearmissile trigger. They are much more efficient than using turtles as projectiles.

Similarly, triggers are blocks of code that are executed when a certain condition occurs. These conditions are monitored by the underlying game engine, and are ‘triggered’ when these conditions are detected to be true. Once again, this is much more efficient then having a turtle constantly execute Logo code waiting for the condition to occur!

The following trigger belongs to the previously mentioned alien ships bale:

ON boom nearmissile block [missile2 10]
  hideturtle
  playsound "explosion
  inc "score
  show :score
  stopmissile flat list :boom :boomanim
  die
  ;this turtle is no more
END

This trigger increments the player’s score, disposes of the missile that triggered it, and then ends the turtle to whom the trigger belongs, in this case a member of the alien ship bale.

As you can see, bales, missiles and triggers all contribute to empowering turtleSpaces coders to create faster-paced, more engaging games.

 

Introducing Environments

Environments are a cool new way to get started with Logo. turtleSpaces now provides a variety of environments in different settings to inspire Logo creation:

Starry Night and Star Platform – Myrtle builds in space!

Winter Ice Pond – Myrtle goes skating!

Pyramid Desert – Build a monument to the Gods!

Under the Sea – Shelly swims with the fishes!

Forest Cabin – Myrtle’s hideaway in the woods.

City Park – Myrtle plays in Central Park!

Parking Lot – Myrtle learns to drive.

The Moon Base – Myrtle on the Moon!

Alien Trees – A ring of growing alien trees.

Environments are available in both the desktop application and the web application. In the web application, you can find them when you start a new project (under the file menu). On the desktop, you open them the way you open examples, in the environments folder.

Environments are written in Logo and are randomly created when they are opened, so some of them may take a minute or two to fully form. You can’t see the environment code in the built-in editors as they are managed by system turtles, which can be used to program the broader Logo environment for purposes such as environments, tutorials and games that use the Logo interpreter to interact with them.

But if you download the procedures, or look at them in an external text editor, you can see the code that makes up the environments, and tweak them, or use them as a template to create your own!

New WebAssembly Build of turtleSpaces Logo Now Available

To make turtleSpaces more accessible to our users, we’ve created a WebAssembly build of turtleSpaces and paired it with a new Javascript front-end UI that renders turtleSpaces output natively in the browser, and has a code editor with syntax highlighting.

It comes with a number of built-in examples, and a fairly complete set of features: loading from the local machine, saving to the local machine, exporting STL, exporting PNG (high-resolution), and sharing using the turtleSpaces model viewer (which unlike STL is in full color).

Obviously execution in the web interface is slower than if you download the native turtleSpaces binary for your operating system, but our webLogo still provides most of the functionality of turtleSpaces while making it available for other platforms such as Chromebooks, Raspberry Pi 4 and so forth (anything that can run a Chromium-based browser).

And, because it is 3D, and has dozens of shape primitives, our webLogo still offers far more creative opportunities than other Logos.

Check out the webLogo here!

turtleSpaces Model Web Viewer

On our journey to porting turtleSpaces to the Web (yes, that’s coming!), we’ve added a primitive, SHAREVECTORS “description (or |description|) that allows users to share their creations to the web. SHAREVECTORS will return a link to the turtleSpaces website where you can view a static model, as it was in turtleSpaces when you executed the SHAREVECTORS command.

Note that the camera in the web viewer is currently fixed to the Y axis and is oriented upward, and so you need to ensure your models are oriented that way (they should look correct if you issue a CAM:CS to return the camera turtle to its home position).

You can also embed the viewer (and your creation) into your own web page if you use the following bit of code:

<iframe src="https://turtlespaces.org:9876/embed?pict=YourSceneHere" frameBorder="0" width="720" height="512" scrolling="no">

replacing YourSceneHere with the ID of your scene (the bit in the share URL after pict= and before the ” that follows it) which looks something like 8970c41a0c9a35553e6a2613f8b0516c67381e9a556beb647de84c09

Note: Due to limitations with WebGL, pen width is not currently supported.

You can click and drag to rotate the model, or use the scroll wheel to zoom in and out.

Here’s a few embedded examples:

Release Notes: New SKEW* and TRAPE* shape primitives + SAVEPNG high-res export

We’ve added a number of new 3D shape primitives in the latest release:

skewfiso
skewiso
skewpyramid
skewpyramoid
skewquad
skewrect
skewtraperect
skewtrapevoxeloid
skewtrapezoid
skewvoxeloid
traperect
trapevoxeloid
trapezoid

These allow you to “skew” (or slant) the created shape and / or compress or expand one “end” of it (trape, or trapezoidal). This allows for a large increase in the number of possible shapes you can create in turtleSpaces.

Also, you can export an arbitrarily-sized render of the current scene using the new SAVEPNG primitive:

SAVEPNG [width height] “filename.png

Note that if you specify a really large size (> 10000 pixels per side) you can cause the application and even your operating system to crash! This is because the rasterisation needs to be done in memory.

The image is saved in the current “working directory”, usually a turtleSpace TSP folder inside of your user folder (inside of the turtleSpaces folder in your home directory).

We’ve also created a lot of short-hand primitives for shapes. You can find them listed in the shapes and graphics reference.

Myrtlebot: A turtleSpaces Twitter Bot

Don’t want to download the turtleSpaces client just yet? Well, you can take turtleSpaces for a bit of a spin using Myrtlebot, our turtleSpaces Twitter Bot! Myrtlebot executes whatever Logo code (not procedures yet) you tweet at her, and then returns an image of the results. In the future, we plan to allow for the recording of movies, but for now it’s just a still image. If your code runs for more than 60 seconds, it will be cut off at the 60 second mark.

Head on over to Twitter and check it out!

We’ve created a number of ‘short codes’ for various graphics primitives so that you can put more into a tweet. Here are the new ‘short codes’ (along with the typical logo rt, lt, fd, bk, up, dn etc.) See the documentation for a fuller description of each primitive:

AB = AMIGABALL
ABO = AMIGABALLOID
CAM = CURRENT CAMERA TURTLE
CB = CUBE
CBO = CUBOID
CC = CUTCONE
CCO = CUTCONOID
CCOS = CUTCONOIDSLICE
CCS = CUTCONESLICE
CF = CUTFUNNEL
CFO = CUTFUNNELOID
CFOS = CUTFUNNELOIDSLICE
CFS = CUTFUNNELSLICE
CIR = CIRCLE
CN = CONE
CNO = CONOID
COSL = CONOIDSLICE
CSL = CONESLICE
CSO = CUTSPHEROID
CSOS = CUTSPHEROIDSLICE
CSP = CUTSPHERE
CSS = CUTSPHERESLICE
CY = CYLINDER
CYA = CYLINDERARC
CYAS = CYLINDERARCSLICE
CYO = CYLINDROID
CYOA = CYLINDROIDARC
CYOAS = CYLINDROIDARCSLICE
CYOS = CYLINDROIDSLICE
CYS = CYLINDERSLICE
DCC = DUOCUTCONOID
DCFO = DUOCUTFUNNELOID
DCO = DUOCYLINDROID
DIVP = DIVISORP
DM = DOME
DMO = DOMOID
DOD = DODECAHEDRON
DODO = DODECAHEDROID
DTO = DUOTUBOID
ELL = ELLIPSE
FIX = FIXATE
FU = FUNNEL
FUO = FUNNELOID
FUOS = FUNNELOIDSLICE
FUS = FUNNELSLICE
HD = HEADING
ICD = ICOSPHEROID
IT = ITEM
NTWS = NOTWOSIDED
OCT = OCTAHEDRON
OCTO = OCTAHEDROID
PK = PICK
POPT = POPTURTLE
PRI = PRISM
PS = POLYSPOT
PT = PITCH
PUSHT = PUSHTURTLE
PY = PYRAMID
PYO = PYRAMOID
QD = QUAD
QUO = QUOTIENT
RBG = RANDBG
RBS = RANDBS
RCT = REPCOUNT
RD = RANDOM
RE = REMAINDER
RFC = RANDFC
RFS = RANDFS
RO = ROLL
RP = ROPE
RPA = REPABOVE
RPC = RANDPC
RPS = RANDPS
RPT = REPEAT
SBDS = SETBOUNDS
SBG = SETBG
SBS = SETBS
SFC = SETFC
SFS = SETFS
SHD = SETHEADING
SISI = SETICOSPHEREITERATIONS
SKF = SKEWFISO
SKI = SKEWISO
SKP = SKEWPYRAMID
SKPO = SKEWPYRAMOID
SKQ = SKEWQUAD
SKR = SKEWRECT
SKT = SKEWTRAPEZOID
SKTR = SKEWTRAPERECT
SKV = SKEWVOXELOID
SKVO = SKEWTRAPEVOXELOID
SMW = SETMARKERWIDTH
SP = SPOT
SPC = SETPC
SPD = SPHEROID
SPDS = SPHEROIDSLICE
SPH = SPHERE
SPHS = SPHERESLICE
SPI = SETPITCH
SPN = SETPOSITION
SPO = SETPOS
SPS = SETPS
SPW = SETPENWIDTH
SSA = SETSPHEROIDAXIS
SQ = SQUARE
SRO = SETROLL
SSPD = SETSPEED
STD = SETTYPEDEPTH
STDE = SETTYPEDELAY
STF = SETTYPEFONT
STFI = SETTYPEFILLED
STR = SETTYPESTRETCH
STS = SETTYPESIZE
TB = TUBE
TBA = TUBEARC
TBAS = TUBEARCLICE
TBO = TUBOID
TBOA = TUBOIDARC
TBOAS = TUBOIDARCSLICE
TBOS = TUBOIDSLICE
TBS = TUBESLICE
TH = TETRAHEDRON
THO = TETRAHEDROID
TR = TORUS
TRE = TRAPERECT
TRI = TRIANGLE
TRO = TOROID
TROS = TOROIDSLICE
TRS = TORUSSLICE
TVO = TRAPEVOXELOID
TWS = TWOSIDED
TZ = TRAPEZOID
VX = VOXEL
VXO = VOXELOID

Export STL format 3D models created in turtleSpaces 3D Logo using the SAVESTL primitive

turtleSpaces has a new primitive, SAVESTL, which can be used to export 3D models of the current turtleSpace.

savestl "modelname

creates a new folder in the current project folder (TSP) with the extension MDL (eg modelname.mdl), inside which contains STL format files, one for each color used in the space. These files can be used with other 3D applications (such as the pictured viewstl.com website), and can be 3D printed (although the sides of objects may need to be extruded using another application first, if the desire is for the objects to be hollow).

Another primitive, SETSTLLINETHICKNESS, is used to set the radius of the ropes used to represent lines in exported STL files. It takes a number.

setstllinethickness 10

Happy 3D printing!

 

Control turtleSpaces from other applications with its API

You can communicate with turtleSpaces over a socket (telnet) connection to port 1967.

First you need to issue the API command inside of turtleSpaces to enable API connections, or use the -enable-api flag when starting up.

Then connect to turtleSpaces from an external application or terminal. You can issue instructions to affect turtles and the environment just like you would do inside the turtleSpaces application.

The API connection executes as its own worker. You can also redirect input and output to the API instance by using setread “api and setwrite “api – but these must be issued by the API worker itself to redirect to that worker (if you use another API connection, reading and writing will be redirected to that API instance, for example).

Using the API, you can use turtleSpaces as a visualiser for another application, and have it act as a light organ, or create charts and graphs.