CodingStarlogo tng

10 Programming thoughts to hatch new thoughts in StarLogo TNG

This guide will show you how to program thoughts to grow as they eat other thoughts and hatch new ones when they get to a certain size.

 

breed die B 22

In the Blocks window, click on Edit Breeds to open the Breeds window.

Go to the Thoughts tab, select a 3D model of a thought and give it a name.

Click New to create another breed, select a 3D model of a thought and give it a name.

Repeat again so that you have three breeds and click OK to confirm.

 

Breed Die Two 03

Click and drag along the canvas until you can see the Setup page.

From the Setup and Run drawer, drag out a Setup block and place it on the Setup page.

From the Setup and Run drawer, drag out a Clear Everyone block and place it inside the Setup block.

 

trails factory

Click on the blue arrow to the right of the Factory.

 

breed die B 30

Open the blocks for the first of your breeds.

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 so that you have as many as you want, 5-20 is a good number for this activity.

Repeat this for each of the breeds you have created.

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 at the top of the SetUp block as shown.

From the Terrain drawer, drag out a Hide Skybox block and place at he bottom of the Setup block 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.

From the Traits drawer, drag out a Set Altitude block and place it in the Do socket of each of your breeds. We want our thoughts to be able to collide as they wander, so set each of your breeds to have the same altitude.

 

How to program thoughts to wander.

Breed Die Two 01

Click and drag along the canvas until you can see the Runtime page.

From the Setup and Run drawer, drag out a Forever block and place it on the Runtime page.

From the Movement drawer drag out a Forward, Left and Right blocks and place them in the runtime sockets for each breed.

Replace the numbers in the Left and Right blocks with Random blocks and set the value of the random number to a something around 10. The higher the random number the more random the movement of the thought will be.

 

How to program thoughts to eat and be eaten.

In the Blocks window drag the canvas along to the Collisions page.

trails factory

Click on the blue arrow to the right of the Factory.

breed die B 30

Open the Collisions drawer.

breed collide 01

Drag out a Collision block with the names of the breeds that you want to eat and be eaten and place it on the Collisions page. Collision blocks allow you to decide what happens when two thoughts collide.

breed collide 02

From the Logic drawer, drag out a Die block and place it in the socket of the breed that you want to be eaten.

breed collide 03

From the Traits drawer, drag out a Set Size block and place it in the socket of the breed of the thought that you want to eat the other thought.

From the Maths drawer, drag out a + block and a Number block. Place the Number block in the right had side of the + block.

From the Traits drawer, drag out a Size block and place it in the left hand side of the + block.

This code tells StarLogo that if these two breeds collide, then the Confused Memory will die and that the Happy Idea will increase in size by one.

 

How to program thoughts to hatch new thoughts if they reach a certain size.

breed die B 27

From the Logic drawer, drag out an If block and place it in the runtime socket of the breed that you want to program to eat, grow and reproduce

From the Logic drawer, drag out a Hatch Do block and place it in the Then socket of the If block.

From the Traits drawer, drag out a two Set Size blocks.

Place one in the Hatch Do socket; this sets the size of the new thought to 1 when it is first hatched.

Place the other inside the If Then socket but below the Hatch Do block; this sets the size of the parent thought to 1 once it has given birth.

Test

setup run

Run this program in the SpaceLand window by clicking the Setup and Forever blocks.