Dynamic Color Changing (Mixing Liquid Simulation)

0 favourites
  • 13 posts
From the Asset Store
Color all tiles with the same color in 22 moves or less!
  • Hello all! I have run smack into a roadblock trying to create my first Construct2 project and I was hoping someone out there could guide me to a solution.

    My Goal:

    I am trying to create a basic simulation where you have a cup with a liquid of a known color (Color A) and you are pouring a second liquid of a different known color (Color B) into the cup. What I hope to achieve here is turning the liquid in the cup into a new color (Color C) which would be the interpolated mid-point of Color A and Color B.

    My Problem:

    The full scale of my project will include dozens of different liquids and you could combine any number of them into the cup in a given round so creating sprite animations of the color shift for every combination of liquids is far from ideal if not all together impossible.

    I understand that a sprite object doesn't exactly have a color of its own and therefore I can't just set read and set the RGB/HSL values of a sprite object the way I'd like. Can anyone suggest a good way to approach this?

    Thanks in advance,

    -Mike

  • Create a white sprite and use the tint effect. Store the RGB values in variables and use them to read/write the colours.

  • What thehen said is applicable, if you want computer-color blending.

    HOWEVER.

    I suppose you want to blend liquids as liquids should blend - i.e. as we all learned in 3rd grade art class (yellow and cyan = green, white + color = lighter color).

    I was actually researching this a few weeks ago. It turns out that as far as I can see, nobody has even discovered a reasonable algorithm to accomplish this. It goes into the terrible realm of color spaces.

    Let me know if you get it to work!

  • There was this iOS game that did this perfectly...can't...remember...name...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • CrudeMik, that's good! I googled the problem and found nothing, but if one game has done it, that's a start. I wonder if they'd be willing to share their algorithm...

  • I was actually hoping to add something like this in my game, and was using this thread at stackoverflow as a base. Might point you in the right direction.

    If you get to it before I do (lots of stuff to do before then) let us know!

  • Mulkaccino, that's all well and good for additive color mixing. Real-life liquids and paints use subtractive color mixing, which is a different beast altogether.

  • Ahh, missed that entirely.

  • Create a white sprite and use the tint effect. Store the RGB values in variables and use them to read/write the colours.

    This was much easier than trying to use the AdjustHSL effect and seems to be giving me the control over the colors that I was looking for. Thanks!

  • Thanks for all the replies!

    I'm putting the Tint effect to work for me now and I've started working on the problem of gradually changing the color of my liquid object as new colors are added but, alas, it got late and I had a long day at work so my head is getting kinda fuzzy. I'll be back tomorrow night with a status update and if all goes well a sample of my progress.

  • For a smooth transition between colors you can use lerp on each color component.

    If you convert from rgb color to another color space before lerping you can get different results.

    Top down: rgb, ryb, hsl

    <img src="http://dl.dropbox.com/u/5426011/examples15/cool.png" border="0" />

  • Sorry for the long delay. I haven't had as much time to work on this as I would have liked.

    Taking some of your suggestions I have worked up a simple example project that simulates in a very simple way the mixing of colored liquids.

    Example file: dropbox.com/s/xodgrvqxeq9k2jr/TestFillRGB.capx

    The buttons at the bottom are click and hold. I left a lot of my debugging output in place so you can track what is going on. There are also more variables being used than are strictly necessary but I did this on purpose to make the example more understandable (I hope).   <img src="smileys/smiley2.gif" border="0" align="middle" />

    If anyone has any questions, comments, or constructive criticisms I welcome them! Next up I will be trying to add density and opacity to my liquids. Stay tuned!

  • Somebody knows as I make it?: youtube.com/watch

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)