Script to make two circles appear on collide?

About advanced scenes, and the Thyme scripting language used in Algodoo.

Script to make two circles appear on collide?

Postby Gildon » Thu Aug 15, 2013 10:32 am

I would like to simulate a sort of nuclear chain reaction. My idea is to have a circle acting as the atom programmed with a certain script. Then, have another circle slightly smaller to act as the neutron. Upon collision between the neutron and atom, I want the atom to be deleted and I want two more neutrons to be made going off in different, random directions and velocities. Is this possible and if so, could you please explain how to make it so. Thanks.
Gildon
 
Posts: 4
Joined: Thu Aug 15, 2013 10:17 am

Re: Script to make two circles appear on collide?

Postby MrGlinzz » Wed Oct 23, 2013 2:26 pm

Bear in mind I'm clueless on nuclear reactions, but I'll try my best here! Does both the neutron and the atom get deleted?

First off, to delete the atom, simply set its density to 0, you can do this in either of the onCollide's.
If its in the atoms onCollide [the one being deleted] then the script would go:

Spoiler: show
Code: Select all
onCollide = (e)=>{
    e.this.density = 0
}


If its in the neutons script then:

Spoiler: show
Code: Select all
onCollide = (e)=>{
    e.other.density = 0
}


Then to execute the spawning of the two new neutrons, this is probably best done in the atoms script.
A simple way to spawn two of the same object is to do this:

Spoiler: show
Code: Select all
for(2, (i)=>{})


Then, you can just select your neutron. press cntrl + c [copy], and in the middle of the two {}, press cntrl + v [paste]
So essentially it would look something like:

Spoiler: show
Code: Select all
for(2, (i)=>{"Your script for the neutrons here"});


The number simply says how many of the same one you want spawned.
If they need to be different then you have to put the 'scene.addCircle' twice.

Kind of a bad explanation from me so fire away with questions :lol:
Hope this helps!!!
MrGlinzz
 
Posts: 13
Joined: Tue Mar 19, 2013 11:51 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 5 guests