CodingStarlogo tng

05 Programming thoughts to eat each other and be eaten in StarLogo TNG

As thoughts move around spaces they sometimes collide.

It is useful to be able to program them to change in some way when they do this.

This guide shows how to change thoughts when they collide in StarLogo TNG.

You can use this to make thoughts eat and be eaten by one another, by killing them and making them grow.

When two thoughts collide you can change any of their traits, e.g. size,  altitude, shape, heading etc..

 

Before you start this you should have a look at..

Getting Started with StarLogo TNG

Setting up a Room of Flunstellas with StarLogo TNG

Programming Thoughts to Wander using StarLogo TNG

 

Instructions

In the Blocks Window

starlogo collisions 00

– Start a new project bringing in at least 2 different breeds of Flunstellas.

See Setting up a Room of Flunstellas with StarLogo TNG to find out how to import 3D Flunstella models.

 

starlogo collisions 03

– Drag out a red ‘Setup’ block from the ‘Setup and Run’ drawer and place it on the Setup page of the Canvas.

– Drag out a red ‘Clear All’ block from the ‘SetUp and Run’ drawer and place it inside the ‘Setup’ block.

 

starlogo collisions

– At the top of the Blocks Factory, click on the blue ‘My Blocks’ arrow, to open the ‘My Blocks’ drawers.

starlogo collisions 05

– Open the drawers for each of the Flunstellas breeds you have created and drag out a red ‘Setup Do’ block for each breed.

– Drag out a ‘Scatter Breed’ block out for each breed and place them inside the ‘SetUp’ block, underneath the ‘Clear All’ block.

– At the top of the ‘My Blocks’ drawers click on the blue ‘Factory’ arrow to return to the ‘Blocks Factory’.

starlogo collisions 06

– Set the size of the Flunstellas to a random size by dragging out a blue ‘Set Size’ block from the Traits drawer and connecting it to the Do hook of each Create Do block. Then drag out a blue Random block from the ‘Maths’ drawer and drag it into the number block of the ‘Size’ block. Change the number block of the ‘Random’ blocks.

starlogo collisions 08

– Set the Altitude by dragging out blue ‘Altitude’ blocks and placing them inside the Do hook of each breeds ‘Create Do’ block. Set both breeds to have the same altitude.

In the SpaceLand window

eat be beaten

-Click on the Setup blocks at the bottom of the SpaceLand window, you should see Flunstellas of different sizes scattered around SpaceLand.

eat be eaten

 

Program the thoughts to move

In the Blocks Window

– Drag out a red ‘Forever’ block and place it on the Runtime page of the Canvas.

– Create a movement program for each breed.

starlogo collisions 09

– This example shows the ‘Red and Black’ moving forwards in a straight line and the ‘Creative Idea’ wandering randomly. For more on programming how to program random wandering behaviours see this guide.

– Open the My Blocks drawer again by clicking on the blue ‘My Blocks’ arrow at the top of the ‘Blocks Factory’.

 

Program the thoughts to change when they collide

starlogo collisions 11

 

starlogo collisions 11

– Open the ‘Collisions’ drawer, drag out the grey ‘Collision’ block that features both of your Flunstella breeds and place it in the Collisions page of the Canvas.

 

starlogo collisions 12

– Drag an orange ‘Die’ block from the Logic drawer and place it in the hook of one of the breeds in the collision block to make agents of that breed die (or disappear) if they come into contact with agents of the other breed.

 

starlogo collisions 13

– You can change any trait that can be found in the trait drawer, size, shape, breed, altitude, transparency etc. To make the Flunstella grow, drag a blue ‘Set Size’ from the trait drawer and place it in the hook of the Flunstella that you want to grow. Drag out a blue ‘+’ block from the ‘Maths’ drawer and place a ‘Size’ block and a number block of the amount that you want it to grow.

 

starlogo collisions 14

– Set a thought to change shape when it collides with another, by dragging out a blue ‘Set shape’ block from the traits drawer and a ‘Shape’ block from the shapes drawer.

 

starlogo collisions 15

– Set a thought to make a noise when it collides with another by dragging out a green ‘Play Sound’ block and placing it in that breeds hook in the ‘Collision’ block.

 

Experiment by changing different traits as different thoughts collide with each other.