Assign a random colour to each particle?

  • ChemGuy
    7th Aug 2014 Member 0 Permalink

    Yes, something like TRON would be great, I could then work upon it to customise it for my element.

    I'm not interested in modifying the source just yet, though, so I'm currently looking for a Lua solution.

  • boxmein
    7th Aug 2014 Former Staff 0 Permalink
    @iamdumb (View Post)
    Working on writing it to a better form, give me time...
  • ChemGuy
    18th Aug 2014 Member 0 Permalink

    Okay, I've figured out how to achieve this in Lua. Turns out it's really simple, it just required a bit of thinking outside the box...

     

    function graphiod(i, colr, colg, colb)

             if tpt.get_property("tmp2", i) == 0 then
                      tpt.set_property("tmp2", math.random(1,5) * 4, i)
             end
             local colfact = tpt.get_property("tmp2", i)
             return 1, 0x00000001, 255, 24+colfact, 20+colfact, 40+colfact, 0, 0, 0, 0
    end

    Edited 3 times by ChemGuy. Last: 18th Aug 2014
  • NDR149
    3rd Oct 2016 Member 0 Permalink

    @PTuniverse (View Post)

     TRON's color code is certainly neglected. If you look here, you'll find a bit of info about TRON's color in relation to tmp. That said, perhaps a similar function could be written in lua to generate a random number and convert into a hex color for each particle

  • Alexwall
    4th Oct 2016 Member 0 Permalink

    ChemGuy:

    Okay, I've figured out how to achieve this in Lua. Turns out it's really simple, it just required a bit of thinking outside the box...

     

    function graphiod(i, colr, colg, colb)

             if tpt.get_property("tmp2", i) == 0 then
                      tpt.set_property("tmp2", math.random(1,5) * 4, i)
             end
             local colfact = tpt.get_property("tmp2", i)
             return 1, 0x00000001, 255, 24+colfact, 20+colfact, 40+colfact, 0, 0, 0, 0
    end

     eh what does this do

  • jacob1
    4th Oct 2016 Developer 0 Permalink
    @ajloveslily (View Post)
    It starts by checking if tmp2 is initialized, if not it initializes it (necessary because lua api has a major hole and has no way to initialize element properties)
    Then it uses a lua graphics function, which is documented here: https://powdertoy.co.uk/Wiki/W/Lua.html#tpt.graphics_func

    Although it is returning 1 for cache, which probably makes it cache the first one it sees and never run the lua function again.
  • TPT_PL
    4th Oct 2016 Member 0 Permalink
    Post time: August 2014