addCircles with different radius
8 posts • Page 1 of 1
addCircles with different radius
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.
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
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.
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.

-

KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: addCircles with different radius
search for "random" in thyme forum
Dream of Algodoo as game development engine...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: addCircles with different radius
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
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
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:
Then the first circle which is hit by the laser, also turns red. Why is this? And how can I stop this?
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
Should be color := rather than color =.
It's a very common and easily made mistake.
It's a very common and easily made mistake.
-

TC42 - Posts: 984
- Joined: Sun Jan 09, 2011 1:53 pm
- Location: $ sudo apt get-install sandwich_
Re: addCircles with different radius
I think you also have to give essential variables as well, radius & position.
-

Nxdt - Posts: 1019
- Joined: Mon Aug 31, 2009 6:32 pm
- Location: Scotland!
Re: addCircles with different radius
@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??
@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
8 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 6 guests




