08 Program thoughts to leave trails in StarLogo TNG
This guide will show you how to program thoughts to leave trails as they move around.
Before you try this, you should learn how to..
Import 3D shapes into StarLogo TNG
Program Thoughts to Wander in StarLogo TNG
Selecting Breeds
In the Blocks window, click on Edit Breeds to open the Breeds window.
Go to the Flunstellas tab, select a 3D model of a thought and give it a name.
Go to the Basic Shape tab and select a basic shape to create a trail with.
Setting Up
In the Blocks Window.
Open the Setup drawer, drag out a Set up block and place it on the Set Up page of the canvas.
Click on the blue arrow to the right of the Factory.
Open the blocks for the Thought Breed.
Drag out a Create [Your ThoughtName] Do block.
Drag out a Scatter [Your ThoughtName] and place it below the Create Do block.
Change the number of thoughts.
Click on the blue left arrow to return to the Blocks Factory.
From the Setup and Run drawer, drag out a Clear Everyone block and place as shown.
From the Terrain drawer, drag out a Hide Skybox block and place as shown.
From the Traits drawer, drag out a Set Size block and place it in the Do socket of each of your breeds, change the breeds starting size if you want to.
Programming the Runtime behaviour
First we need to program a basic wandering behaviour.
From the Setup and Run drawer drag out a Foreever block and place it on the Runtime page of the canvas.
From the Movement drawer drag out a Forwards, Left and Right blocks and place them in the socket for the thought breed.
From the Maths drawer drag out two Random blocks and replace the number value of the Left and Right blocks with random values as shown.
From the Setup and Run drawer drag out a Hatch Do block and place it underneath the movement blocks.
From the Traits drawer, drag out a Set Breed block and place it in the Do socket of the Breed Do block.
Go to your Breeds Blocks by clicking the arrow to the right of the Factory.
Drag out a Breed Block for the breed you created to make the trail with and place it in the Set Breed block.
Go back to the Blocks Factory and open the Traits drawer.
Drag out a Set Size block and set the value to 0.5.
Drag out a Model Skin Off block and place it inside the Create Do socket.
If you run this code the Thoughts should wander randomly, creating a trail by hatching a small trail breed every time they move.
Programming the trail to fade
From the Traits drawer drag out a Set Transparency block and place it in the Trail breeds socket in the Runtime block.
From the Maths drawer, drag out a + (Plus) block and connect it to the Set Transparency block.
From the Traits drawer drag out a Transparency block and place it in the first socket of the + (Plus) block.
Set the Transparency to + 1.
In StarLogo TNG opaque (solid looking) objects have a transparency value of 0, fully transparent objects have a transparent value of 100.
From the Logic drawer drag out an If block.
From the Maths drawer drag out a > (More Than) block and connect it as shown.
From the Traits drawer drag out a Transparency block and place it in the first socket of the > (More Than) operator.
From the Maths drawer drag out a Number block, place it in the second socket of the > (More Than) block and change the value to 98.
From the Logic drawer drag out a Die block and place it in the then socket of the If block.
The If statement is now testing if the transparency of the trail breed is over 98 and killing it if it is.
Run this program in the SpaceLand window by clicking the Setup and Forever blocks.