My first element - IODN

  • ChemGuy
    21st Jul 2014 Member 7 Permalink

    Hi there!

     

    Let me introduce myself a bit. I've been playing around with the Powder Toy for at least 3 years now. However, I always hesitated to make an account here for some strange reason, until now.

     

    That would be enough about me, time to get to the point.

    In the link below I present the Lua code for my first element - IODN (technically speaking, it's 2 elements, but they refer to the same substance in different states). It bases off the real element Iodine (hence the name and properties).

    When coding this element, I took a peek at a few other element codes for reference (I'm just a beginner), but I tried to write my own, I didn't simply copy-paste everything as it goes. I hope this isn't an issue.

     

    Edit: The code has been improved!

     

    http://pastebin.com/M1e34cVA

     

    Properties:

     

    - Doesn't melt/freeze, it sublimes/deposits (113.7°C) instead, i.e. goes directly from solid to gas phase and vice-versa*

     

    - Undergoes a solid-gas phase equilibrium. It depends on the given temperature, and at room temp. it will be roughly equal to 75% solid / 25% gas. Below -6°C and above 113.7°C it'll cease to change phases.**

     

    - Will heat up and vigorously react with some metals, to be specific, BRMT and IRON, to form SALT. The former is more violent (for best results, mix the two powders evenly), while with the latter GIOD has to be heated to at least 400 degrees to initiate the reaction. The reaction now also proceeds at room temperature, but it's still comparatively slower than the BRMT reaction.

     

    - On contact with NEUT will turn into its radioactive isotope, which in turn will decay into NBLE and ELEC over time.***

     

    I experienced some lagging when adding a sized amount of either element (solid or gas). This may be due to some unnecessarily complex scripts involved (I'm a noob, so this is quite possible) or my ancient PC, or perhaps both.

    I also wanted to assign a slightly different color (lighter/darker) to each particle, but I didn't know how to script it, none of my attempts have resulted in the desired effect. I've now implemented this in the new code.

     

    If you have any ideas how to improve the script, suggestions, comments, criticism, feel free to tell me.

     

    Changes:

     

    - added graphics function for random particle colour

     

    - reaction with IRON, as stated above, is now slightly more energetic.

     

    - changed code layout a bit, made it more compact and simpler in places

     

    - electrons from radioactive decay have a more randomized speed

     

     

    * Actually, there is a liquid phase of the real element - well, leaving it out saved some scripting for me, as in real life it appears very briefly under standard pressure and almost immediately vaporises.

     

    ** I don't know if the lower temp. threshold is correct, I wasn't able to find any documentation on this.

     

    *** There is a small problem with this, the NEUTs will react with the emitted ELECs to form HYGN. This sort of ruins the effect. Is there a way to disable certain reactions from the update function without changing the source?

    Edited 9 times by ChemGuy. Last: 14th Sep 2014
  • xetalim
    21st Jul 2014 Member 0 Permalink
    Nice element, but beware, mniip will come here and [POTATO] all over your code.
    Edited once by jacob1. Last: 21st Jul 2014
  • jacob1
    21st Jul 2014 Developer 2 Permalink
    @ChemGuy (View Post)
    The code and the element look really nice, it actually seems like you know what you are doing. You put an extra space of indentation in some places but maybe that's just your style.

    -6C should be 267.15K, so the temperature in the script is about right. Also I can't see any simple way to stop NEUT from reacting with ELEC besides disabling ELEC's update function. If it was any other reaction (ELEC+PROT) you would be able to use a hack I inserted for fusion and set the .tmp2 to 1 ...

    I didn't think it was that slow at all, but sim.neighbors is a nice function to speed things up: for i in sim.neighbors(100,100,1,1) do print(tpt.get_property("type", i)) end. 1 and 1 are the x/y radiuses to look for neighbor particles in
  • ChemGuy
    21st Jul 2014 Member 0 Permalink

    I will look into this sim.neighbors function, thanks!

  • Robinfox
    22nd Jul 2014 Member 0 Permalink

    nice script but it eats my fps realy fast

  • ChemGuy
    22nd Jul 2014 Member 0 Permalink

    Yeah, I had the exact same problem with it. I'll try to improve the script so it runs more smoothly.

  • FM22
    29th Jul 2014 Member 0 Permalink

    Nice element

  • edza101
    29th Jul 2014 Member 0 Permalink
    its sumblime both ways. You can get rid of "/deposits"
  • tmo97
    13th Aug 2014 Banned 2 Permalink
    This post is hidden because the user is banned
  • ChemGuy
    19th Aug 2014 Member 0 Permalink

    Thanks!

     

    The code has been changed a bit, more info in the OP.

     

    @edza101 (View Post)

     I'm pretty sure the counter-process is called either desublimation or depositing.

    Edited once by ChemGuy. Last: 19th Aug 2014