Java-Gaming.org
 Featured games (81) games approved by the League of Dukes Games in Showcase (497) Games in Android Showcase (114) games submitted by our members Games in WIP (563) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Collisions between Planets[solved]  (Read 1255 times) 0 Members and 1 Guest are viewing this topic.
trvcic

Senior Newbie

 « Posted 2013-09-09 20:46:48 »

For a 2d sprite simulation I have a grouping of different sized planets. Their size represents their mass. The each have a randomly generated color. When they collide I would like to mix the colors based on their mass, ie a small black + a big white should be slightly gray. How can I do this in a RGB system?

while(true) { be awesome; }
Zhon

Junior Member

Medals: 4

 « Reply #1 - Posted 2013-09-09 20:59:05 »

Not sure if I got the question right but... maybe add the colors and divide by two?

color.r = (color1.r + color2.r)/2
color.g = (color1.g + color2.g)/2
color.b = (color1.b+ color2.b)/2
Riven
« League of Dukes »

JGO Overlord

Medals: 799
Projects: 4
Exp: 16 years

 « Reply #2 - Posted 2013-09-09 21:01:39 »

 1  2  3  4 `int totalMass = a.mass + b.mass;int r = ((a.r * a.mass) + (b.r * b.mass)) / totalMass;int g = ((a.g * a.mass) + (b.g * b.mass)) / totalMass;int b = ((a.b * a.mass) + (b.b * b.mass)) / totalMass;`

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
ags1

JGO Ninja

Medals: 62
Projects: 3
Exp: 5 years

Make code not war!

 « Reply #3 - Posted 2013-09-09 21:02:45 »

It is just a weighted average:

(color1 * diameter1 * diameter1) + (color2 * diameter2 * diameter2) / (diameter1 * diameter1 + diameter2 * diameter2)

Er, yes, as per riven's post, my method is 2D which can be considered wrong. Of course the color derives from the surface layer so considering diameter squared is arguably better than considering mass.

Riven
« League of Dukes »

JGO Overlord

Medals: 799
Projects: 4
Exp: 16 years

 « Reply #4 - Posted 2013-09-09 21:03:29 »

It is just a weighted average:

(color1 * diameter1 * diameter1) + (color2 * diameter2 * diameter2) / (diameter1 * diameter1 + diameter2 * diameter2)
Planets are spheres, not circles.

Er, yes, as per riven's post, my method is 2D which can be considered wrong. Of course the color derives from the surface layer so considering diameter squared is arguably better than considering mass.
When planets collide, their original surfaces won't be very important

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
ags1

JGO Ninja

Medals: 62
Projects: 3
Exp: 5 years

Make code not war!

 « Reply #5 - Posted 2013-09-09 21:07:41 »

But they aren't the same color the whole way through... :-) And the light crust will rise to the top regardless. If the small black planet is pure iron, and the white planet is mostly quartz, the new planet is going to be white.

trvcic

Senior Newbie

 « Reply #6 - Posted 2013-09-09 21:11:07 »

thanks this is what I needed. I was near doing this, but was confusing the area/ mass with the diameter.

while(true) { be awesome; }
ags1

JGO Ninja

Medals: 62
Projects: 3
Exp: 5 years

Make code not war!

 « Reply #7 - Posted 2013-09-09 21:13:11 »

Actually, if the planets are anywhere near equal in size, the color of the new planet will be glowing red lava! (assuming rocky planets)

Maybe make the planets go red on impact, and then let them cool down over time to the weighted average color?

Abuse

JGO Knight

Medals: 12

falling into the abyss of reality

 « Reply #8 - Posted 2013-09-22 11:29:58 »

Unless the orbits are almost identical, the two planets wouldn't coalesce anyway

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 Add your game by posting it in the WIP section, or publish it in Showcase. The first screenshot will be displayed as a thumbnail.
 BurntPizza (7 views) 2014-09-21 01:30:30 BurntPizza (9 views) 2014-09-21 00:34:41 moogie (9 views) 2014-09-21 00:26:15 UprightPath (23 views) 2014-09-20 20:14:06 BurntPizza (27 views) 2014-09-19 03:14:18 Dwinin (40 views) 2014-09-12 09:08:26 Norakomi (70 views) 2014-09-10 13:57:51 TehJavaDev (96 views) 2014-09-10 06:39:09 Tekkerue (49 views) 2014-09-09 02:24:56 mitcheeb (70 views) 2014-09-08 06:06:29
 BurntPizza 37x Riven 18x Rayvolution 18x basil_ 16x ags1 16x princec 16x KevinWorkman 15x LiquidNitrogen 12x deathpat 11x kevglass 11x nsigma 11x theagentd 11x HeroesGraveDev 8x Gibbo3771 6x cylab 6x EgonOlsen 6x
 List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27Resources for WIP games2014-08-01 16:20:17Resources for WIP games2014-08-01 16:19:50List of Learning Resources2014-07-31 16:29:50List of Learning Resources2014-07-31 16:26:06List of Learning Resources2014-07-31 11:54:12HotSpot Optionsby dleskov2014-07-08 01:59:08
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org