This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-04-12 11:35:36

courtneyfay
New Scratcher
Registered: 2011-04-12
Posts: 1

chemistry gaseous molecules simulation

Hi,

I'd like to make a gas simulation similar to the one found on this site http://intro.chem.okstate.edu/1314f00/laboratory/glp.htm
where the molecules bounce off the walls and off each other.

I know how to make them avoid each other (with the sensing options) but so far in order to get them to move I had to program them on particular paths. What I'd really like is for them to move more randomly.

Any suggestions?

Offline

 

#2 2011-04-12 13:57:48

The_Dancing_Donut
Scratcher
Registered: 2010-08-03
Posts: 1000+

Re: chemistry gaseous molecules simulation

On each particle...

[blocks]<when green flag clicked>
<forever>
<turn cw( <pick random(  )to(  )degrees>
<move( <pick random(  )to(  )steps>
<if on edge, bounce>

<when green flag clicked>
<forever>
<if><touching color[ Colour of the other particles
<turn cw( <pick random(  )to(  )degrees>
<move( <pick random(  )to(  )steps>[/blocks]


That should work...
If your particles are all different colours, then you will need to do it like

[blocks]
<when green flag clicked>
<forever>
<if><touching[ the particle sprite[blocks]
As above.
Make sure you list all the particles that each particle needs to repel using this block, [blocks]<<  <and>  >>[/blocks] . Hope this helped!


Offending strangers since 2010.

Offline

 

#3 2011-04-12 14:51:51

yoshidude56
Scratcher
Registered: 2010-01-12
Posts: 100+

Re: chemistry gaseous molecules simulation

The_Dancing_Donut wrote:

On each particle...

[blocks]<when green flag clicked>
<forever>
<turn cw( <pick random(  )to(  )degrees>
<move( <pick random(  )to(  )steps>
<if on edge, bounce>

<when green flag clicked>
<forever>
<if><touching color[ Colour of the other particles
<turn cw( <pick random(  )to(  )degrees>
<move( <pick random(  )to(  )steps>[/blocks]


That should work...
If your particles are all different colours, then you will need to do it like

[blocks]
<when green flag clicked>
<forever>
<if><touching[ the particle sprite[blocks]
As above.
Make sure you list all the particles that each particle needs to repel using this block, [blocks]<<  <and>  >>[/blocks] . Hope this helped!

This idea sounds pretty good. Donut's got it perfect!


http://i46.tinypic.com/2ut2ir4.png

Offline

 

Board footer