Color mixing
9 posts • Page 1 of 1
Color mixing
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:
The problem is, that both boxes are getting complete black
Script 2:
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!
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!
-

Username? - Posts: 65
- Joined: Sun Sep 20, 2009 8:06 pm
Re: Color mixing
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]}
-

TC42 - Posts: 984
- Joined: Sun Jan 09, 2011 1:53 pm
- Location: $ sudo apt get-install sandwich_
Re: Color mixing
Exactly the same problem like in script 2
and algoodo shows your code as incompatible, it have to be:
or is there any secret about the code, I don' know? XD
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
-

Username? - Posts: 65
- Joined: Sun Sep 20, 2009 8:06 pm
Re: Color mixing
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.
-

TC42 - Posts: 984
- Joined: Sun Jan 09, 2011 1:53 pm
- Location: $ sudo apt get-install sandwich_
Re: Color mixing
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.
Then I can analyze that problem.
-

Username? - Posts: 65
- Joined: Sun Sep 20, 2009 8:06 pm
Re: Color mixing
script can be much simpler: color = (e.this.color + e.other.color) /2

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

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.
red block + green block = both blocks green
red block + blue block = both blocks blue
green block + blue block = both blocks blue
WHY????
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.
-

Username? - Posts: 65
- Joined: Sun Sep 20, 2009 8:06 pm
Re: Color mixing
try this:
1) set controllerAcc of all geoms to 0
2) set onCollide to:
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...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Color mixing
I've found an easyer way:
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.
- 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.
-

Username? - Posts: 65
- Joined: Sun Sep 20, 2009 8:06 pm
9 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 5 guests




