Change color with laser collision.
			3 posts			 • Page 1 of 1		
	
Change color with laser collision.
How would one go about using a laser to change the color of an object. like for example a car tail light. 
What I'm trying to do is using a laser to toggle something from being transparent to not transparent.
			
		What I'm trying to do is using a laser to toggle something from being transparent to not transparent.
- 
				

lethalsquirrel - [ex-squirl]
 - Posts: 54
 - Joined: Fri Sep 11, 2009 5:03 am
 
Re: Change color with laser collision.
Try this code in either the laser or the geom:
in the onLaserHit or onHitByLaser variable, depende on whether you put the code in the laser or the geom.
However, this code should cause the geom to toggle between being white and opaque to being transparent with a black border about 50 times a second- probably less than ideal. So, you could try preventing the geom from toggling if not enough time has elapsed since the laser last hit it. Note that for this code, you'll need to type _lastHit = 0 into the box at the top left of the geom's script menu. Instead, you could edit the code to use an otherwide unused variable, such as controllerAcc.
If I didn't mess up while writing the above code, the geom should toggle so long as at least a tenth of a second has passed in real time since the last laser hit- I'm not sure if this has been changed in the past few years, but I do know that lasers used to run closer to realtime than to simulation time. I can't guarantee that lag won't mess anything up, but at least changing the sim speed or frequency shouldn't be a problem.
Every object in Algodoo has a variable called "color", which stores the color of the object in RGBA form. It goes something like this:
[red, green, blue, opacity]
Each number in this array ranges from 0 to 1. Color [0, 0, 0, 1] is black, [1, 1, 1, 1] is white, [1, 0, 0, 1] is red, [1, 1, 0, 1] is yellow, [1, 0.5, 0, 1] is orange, etc.
If the last number is 0 instead of 1, then the object will be transparent, except for its border.
As with any variable, you can change the color using e.this.color or e.other.color in an onCollide script, e.geom.color or e.laser.color in a laser-triggered script, or by declaring scene.my.color = [0, 0, 0, 1] in the console and running from there.
Instead of the above codes, you could have one laser set the geom's color to, say, green ((e)=>{e.geom.color = [0, 1, 0, 1]}), and another laser set the color to something else.
I'm not completely certain that I know what you're trying to do here, so I made a few guesses.
			- Code: Select all
 (e)=>{e.geom.color == [1, 1, 1, 1]} ? {e.geom.color = [0, 0, 0, 0]} : {e.geom.color = [1, 1, 1, 1]}
in the onLaserHit or onHitByLaser variable, depende on whether you put the code in the laser or the geom.
However, this code should cause the geom to toggle between being white and opaque to being transparent with a black border about 50 times a second- probably less than ideal. So, you could try preventing the geom from toggling if not enough time has elapsed since the laser last hit it. Note that for this code, you'll need to type _lastHit = 0 into the box at the top left of the geom's script menu. Instead, you could edit the code to use an otherwide unused variable, such as controllerAcc.
- Code: Select all
 (e)=>{
{system.time >= (e.geom._lastHit + 0.1)} ? {
{e.geom.color == [1, 1, 1, 1]} ? {e.geom.color = [0, 0, 0, 0]} : {e.geom.color = [1, 1, 1, 1]}
} : {};
e.geom._lastHit = system.time}
If I didn't mess up while writing the above code, the geom should toggle so long as at least a tenth of a second has passed in real time since the last laser hit- I'm not sure if this has been changed in the past few years, but I do know that lasers used to run closer to realtime than to simulation time. I can't guarantee that lag won't mess anything up, but at least changing the sim speed or frequency shouldn't be a problem.
Every object in Algodoo has a variable called "color", which stores the color of the object in RGBA form. It goes something like this:
[red, green, blue, opacity]
Each number in this array ranges from 0 to 1. Color [0, 0, 0, 1] is black, [1, 1, 1, 1] is white, [1, 0, 0, 1] is red, [1, 1, 0, 1] is yellow, [1, 0.5, 0, 1] is orange, etc.
If the last number is 0 instead of 1, then the object will be transparent, except for its border.
As with any variable, you can change the color using e.this.color or e.other.color in an onCollide script, e.geom.color or e.laser.color in a laser-triggered script, or by declaring scene.my.color = [0, 0, 0, 1] in the console and running from there.
Instead of the above codes, you could have one laser set the geom's color to, say, green ((e)=>{e.geom.color = [0, 1, 0, 1]}), and another laser set the color to something else.
I'm not completely certain that I know what you're trying to do here, so I made a few guesses.
Matthias Wandel is epic, in my humble opinion.
I love my brain...
ARE YA HAPPY NOW?????
Thymechanic/Phundamentalist
Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
		I love my brain...
TC42 wrote:Also, your sig is too big, please change it.
ARE YA HAPPY NOW?????
Thymechanic/Phundamentalist
Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
- 
				

Someone Else - Posts: 1147
 - Joined: Sun Nov 21, 2010 10:53 pm
 - Location: The Milky Way Galaxy
 
Re: Change color with laser collision.
Thanks for the reply! That was a lot of info you typed out. I really appretiate you taking your time to do so! 
 
And I agree, Matthias Wandel is awesome indeed!
			
		And I agree, Matthias Wandel is awesome indeed!
- 
				

lethalsquirrel - [ex-squirl]
 - Posts: 54
 - Joined: Fri Sep 11, 2009 5:03 am
 
			3 posts			 • Page 1 of 1		
	Who is online
Users browsing this forum: No registered users and 7 guests



