addCircles with different radius

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

addCircles with different radius

Postby Andwari » Thu Mar 08, 2012 4:24 pm

Hi!
My Question is: Is it possible to give a script a range in which a value lies? For Example:

onHitByLaser = (e)=>{ addCircle({ radius = "1 - 2"; pos = e.pos }) }

so that the Radius is a Value between 1 and 2.
Andwari
 
Posts: 4
Joined: Wed Dec 01, 2010 1:47 pm

Re: addCircles with different radius

Postby KarateBrot » Thu Mar 08, 2012 9:25 pm

what should that be like? you need to tell the computer exactly what you want. something like 1-2 is definitely impossible.
but you can say "spawn a circle with a random radius between 1 and 2" or you need to define a rule to tell which radius you want it to be between two values.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: addCircles with different radius

Postby Kilinich » Fri Mar 09, 2012 9:14 am

search for "random" in thyme forum
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: addCircles with different radius

Postby Andwari » Mon Mar 12, 2012 1:58 pm

Hi, thx for the answer.
I thought there might be a direct way. For example the color of a newly created object is somehow generated randomly too. So I thougt there might be a command for some kind of range like 1-2.

But this thought about the random color gave me an idea, so I designed a Random Number Generator by myself:

At first I place a laser far away from the Scene via script:

Scene.my.addLaserPen( { pos := [500 , 500] } )

Then I add a circle next to the laser an give it a onHitByLaser script, which writes a number of the randomly generated color to a variable and than deletes the circle by setting its density to 0.

Scene.my.addCircle( { pos := [502,500] ; onHitByLaser = (e) => {Scene.my.random = e.geom.color(1) ; density := 0 } } )

Now I have a random number between 0 and 1 stored in the variable Scene.my.random
Andwari
 
Posts: 4
Joined: Wed Dec 01, 2010 1:47 pm

Re: addCircles with different radius

Postby Andwari » Fri Mar 23, 2012 2:52 pm

I have another question. When I place an object via onHitByLaser and give it some properties, the hit-object gets those properties too ...

Example: I create a circle and give the script:
Code: Select all
onHitByLaser = (e)=>{
Scene.my.addCircle( {color = [1.0000000, 0.00000000, 0.00000000, 1.0000000]})}


Then the first circle which is hit by the laser, also turns red. Why is this? And how can I stop this?
Andwari
 
Posts: 4
Joined: Wed Dec 01, 2010 1:47 pm

Re: addCircles with different radius

Postby TC42 » Fri Mar 23, 2012 9:17 pm

Should be color := rather than color =.

It's a very common and easily made mistake.
Image
Spambot wrote:Nowadays, memes usually are studied less in the field of biology, but more with the arena of psychology along with sociology. But, the major area of a meme, getting embraced and imitated all the time is what’s at any core connected with any meme.
User avatar
TC42
 
Posts: 984
Joined: Sun Jan 09, 2011 1:53 pm
Location: $ sudo apt get-install sandwich_

Re: addCircles with different radius

Postby Nxdt » Sun Mar 25, 2012 7:44 pm

I think you also have to give essential variables as well, radius & position.
User avatar
Nxdt
 
Posts: 1019
Joined: Mon Aug 31, 2009 6:32 pm
Location: Scotland!

Re: addCircles with different radius

Postby Andwari » Mon Mar 26, 2012 4:35 pm

@Nxdt: No, that's not necessary. Algodoo gives them default values. The radius for example would be 1.

@TC42: Thx for the answer! But can someone explain the difference between those two to me? I just don't get it and I don't understand this part in the Thyme Tutorial.
And why does a simple = change both the colors??
Andwari
 
Posts: 4
Joined: Wed Dec 01, 2010 1:47 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 6 guests