Color according to density

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

Color according to density

Postby monstertje3 » Sun Jul 17, 2011 5:31 pm

I have a cannon wich takes away density from the target, is it also possible to see a different color according to density?

i tried {e.this.density} at the color in the script menu, but it just turns red :wtf: (the script box, not the target)
Basically, there are only 10 types of people in the world. Those who know binary, and those who don't.
Light travels faster than sound. That's why some people appear bright until they open their mouths.
User avatar
monstertje3
 
Posts: 343
Joined: Sat Sep 05, 2009 4:29 pm
Location: N-H, NL

Re: Color according to density

Postby hiltropper » Sun Jul 17, 2011 6:36 pm

thats because the color hsas 4 values (as colrHSVA has too)
so if you give the color just one value (what density is) , it wont work right
make an oncollide script where you let it act like
Code: Select all
density==2?{color=color}:{color=[what,ever,you,want]}

if its default (set to density 2) it will stay in its color but if you change the density (like trough a projectile) it will change to what color you want
yup yup
yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
hiltropper
 
Posts: 85
Joined: Mon Dec 20, 2010 12:02 pm
Location: Germany

Re: Color according to density

Postby monstertje3 » Sun Jul 17, 2011 7:35 pm

but then it is color A or B, isn't it possible to make it a gradual change?
Basically, there are only 10 types of people in the world. Those who know binary, and those who don't.
Light travels faster than sound. That's why some people appear bright until they open their mouths.
User avatar
monstertje3
 
Posts: 343
Joined: Sat Sep 05, 2009 4:29 pm
Location: N-H, NL

Re: Color according to density

Postby bozbez » Sun Jul 17, 2011 7:43 pm

That would look more like this: color = [{e.this.density/2}, something, something, something]. The /2 is to get the value between 1 and 0.
Image

Go here. Now. That's Now. Not in 5 minutes. Now.
User avatar
bozbez
 
Posts: 149
Joined: Tue Apr 12, 2011 7:01 pm

Re: Color according to density

Postby Someone Else » Mon Jul 18, 2011 1:25 am

I think this is closer to the script you want (at least the script I'd want):
Code: Select all
(e.other) -> {
    drawBorder = false;
    drawCake = false;
    controllerAcc = sim.time;
    density = {(sim.time - controllerAcc) + 0.00010000000000000000};
    color = {[density, density - 8, density - 16, 10] / 10}
}

An odd syntax, I know, but it works. Credit to Gear97.

It initially sets density to very low, then gradually increases it over time. Color is bound to this in that as density increases, color fades from black to red to orange to yellow to white. This simulates the object heating up, as far as color goes.
Matthias Wandel is epic, in my humble opinion.
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.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy

Re: Color according to density

Postby monstertje3 » Mon Jul 18, 2011 11:47 am

yay this works, when i put this in the color place, it still turns red (scriptbox), but the target does too, en on lower density it turns black! :clap:
Code: Select all
{[density, density - 8, density - 16, 10] / 10}


Thank you guys! :thumbup:

Edit: it turns red because i selected tracers too (fail)
Basically, there are only 10 types of people in the world. Those who know binary, and those who don't.
Light travels faster than sound. That's why some people appear bright until they open their mouths.
User avatar
monstertje3
 
Posts: 343
Joined: Sat Sep 05, 2009 4:29 pm
Location: N-H, NL

Re: Color according to density

Postby Someone Else » Tue Jul 19, 2011 12:51 am

Hmm... The code in my post is intended to be an onCollide script.
Code: Select all
(scene.addCircle({pos := e.pos})) -> {
    drawBorder = false;
    drawCake = false;
    controllerAcc = sim.time;
    density = {(sim.time - controllerAcc) + 0.00010000000000000000};
    color = {[density, density - 8, density - 16, 10] / 10}
}
This would be used in spawning. Note that it spawns a circle in the actual code.
This, however, does not work:
Code: Select all
scene.addCircle({
    pos := e.pos;
    drawBorder := false;
    drawCake := false;
    controllerAcc := sim.time;
    density := {(sim.time - controllerAcc) + 0.00010000000000000000};
    color := {[density, density - 8, density - 16, 10] / 10}})
When you use this code, the color and density stop changing as soon as you spawn a new circle.

Also, I suggest you fool around with my code to see how it works- the color bit anyway.

Keep this in mind: the color array is composed of four parts: [red, blue, green, alpha/transparency].

Each value ranges between 0 and 1. Examples:
[0, 0, 0, 1] = black
[1, 1, 1, 1] = white
[0.5, 0.5, 0.5, 1] = gray
[1, 0, 0, 1] = red
[0.5, 0, 0, 1] = dark red
[1, 0.5, 0.5, 1] = light red
Matthias Wandel is epic, in my humble opinion.
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.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 0 guests