Color mixing

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

Color mixing

Postby Username? » Sun Mar 27, 2011 11:58 am

I tryed to make objects, who are mixing their color onCollide.
I've tested it with a pure green box and a pure red box.

Script 1:
Code: Select all
e.this.color = [(e.other.color(0) + e.this.color(0)) / 2, (e.other.color(1) + e.this.color(1)) / 2, (e.other.color(2) + e.this.color(2)) / 2]


The problem is, that both boxes are getting complete black

Script 2:
Code: Select all
e.this.A = (e.other.color(0) + e.this.color(0)) / 2;
        e.this.B = (e.other.color(1) + e.this.color(1)) / 2;
        e.this.C = (e.other.color(2) + e.this.color(2)) / 2;
        e.this.color = [e.this.A, e.this.B, e.this.C, 1.0]


At this, the red box will become color = [0.0, 0.66666665, 0.0]
and the green box color = [0.0, 0.75, 0.0]

I really don't know why! :crazy:
Check my most scripted scene
Code: Select all
       /^°>#
____.<=/`°`    #<°^==>._____
     ``         ´´  ´´
User avatar
Username?
 
Posts: 65
Joined: Sun Sep 20, 2009 8:06 pm

Re: Color mixing

Postby TC42 » Sun Mar 27, 2011 1:22 pm

Username? wrote:
Script 1:
Code: Select all
e.this.color = [(e.other.color(0) + e.this.color(0)) / 2, (e.other.color(1) + e.this.color(1)) / 2, (e.other.color(2) + e.this.color(2)) / 2]


The problem is, that both boxes are getting complete black


That's because color has 4 values--it's an RBGA array; you forgot to put the fourth value into the code. I just found that
Code: Select all
(e)=>{color=((e.this.color(0) + e.other.color(0)) / 2), ((e.this.color(1) + e.other.color(1)) / 2), ((e.this.color(2) + e.other.color(2)) / 2), 1]}
will work (paste it into both boxes' oncollide).
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: Color mixing

Postby Username? » Sun Mar 27, 2011 2:28 pm

Exactly the same problem like in script 2
and algoodo shows your code as incompatible, it have to be:
Code: Select all
(e)=>{e.this.color = [(e.this.color(0) + e.other.color(0)) / 2, (e.this.color(1) + e.other.color(1)) / 2, (e.this.color(2) + e.other.color(2) / 2), 1]}

or is there any secret about the code, I don' know? XD
Check my most scripted scene
Code: Select all
       /^°>#
____.<=/`°`    #<°^==>._____
     ``         ´´  ´´
User avatar
Username?
 
Posts: 65
Joined: Sun Sep 20, 2009 8:06 pm

Re: Color mixing

Postby TC42 » Sun Mar 27, 2011 2:45 pm

Try dividing by less than 2; it probably won't be the correct color on the first collide due to rounding errors, so remember to correct for that.
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: Color mixing

Postby Username? » Sun Mar 27, 2011 4:24 pm

I'll make it with ABC for the other colors, DEF for the own colors and GHJ for the /2.
Then I can analyze that problem.
Check my most scripted scene
Code: Select all
       /^°>#
____.<=/`°`    #<°^==>._____
     ``         ´´  ´´
User avatar
Username?
 
Posts: 65
Joined: Sun Sep 20, 2009 8:06 pm

Re: Color mixing

Postby Kilinich » Sun Mar 27, 2011 5:20 pm

script can be much simpler: color = (e.this.color + e.other.color) /2

:thumbup:
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: Color mixing

Postby Username? » Sun Mar 27, 2011 8:23 pm

Damn, same problem. maybe that is a bug:
red block + green block = both blocks green
red block + blue block = both blocks blue
green block + blue block = both blocks blue

WHY???? :crazy: :wtf: :shock:

Or does that work for you?

EDIT2:
the problem is, that both scripts are running one after another, so that one block will change his color faster. My red block is the fastest.
Check my most scripted scene
Code: Select all
       /^°>#
____.<=/`°`    #<°^==>._____
     ``         ´´  ´´
User avatar
Username?
 
Posts: 65
Joined: Sun Sep 20, 2009 8:06 pm

Re: Color mixing

Postby Kilinich » Sun Mar 27, 2011 9:34 pm

try this:

1) set controllerAcc of all geoms to 0
2) set onCollide to:

Code: Select all
onCollide = (e) => {
   e.this.controllerAcc < sim.time ? {
      mixColor := (e.this.color + e.other.color) /2;
      e.this.color = mixColor;
      e.other.color = mixColor;
      e.other.controllerAcc = sim.time;
   } : {}
}
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: Color mixing

Postby Username? » Mon Mar 28, 2011 2:06 pm

I've found an easyer way:
Code: Select all
(e)=>{
    e.other.text == "42-the_answer" ? {
        mixColor := (e.this.color + e.other.color) / 2;
        e.this.color = mixColor;
        e.other.color = mixColor
    } : {}
}


If one code does everything for both boxes, they'll mixed correctly.
Then the other box runs it's code. That code won't change everything, because it's already done.
Thx guys. :thumbup:
Check my most scripted scene
Code: Select all
       /^°>#
____.<=/`°`    #<°^==>._____
     ``         ´´  ´´
User avatar
Username?
 
Posts: 65
Joined: Sun Sep 20, 2009 8:06 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 8 guests