Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --]] table of atom parts
- --]] DISCLAIMER: This program does not YET work with all atoms
- --]] The current atoms it doesnt work with are,
- --]] Doesnt work with group 9
- --]] Doesnt work with group 10: 2vE (All atoms in this group have n valence electrons)
- --]] Doesnt work with most lanthanides or actinides.
- --]] Doesnt work with Iron atom
- local particles = {
- ['-'] = {name="electron",graphic="-",tc=colors.white,bc=colors.blue},
- ['+'] = {name="proton",graphic="+",tc=colors.white,bc=colors.red},
- [' '] = {name="neutron",graphic=" ",tc=colors.white,bc=colors.yellow},
- }
- function newAtom(atomicnumber,huge)
- --if(velectrons <= 0 or velectrons > 8)then error("Invalid number of valence electrons. ") end
- local atom = {
- nucleus = {
- protons = atomicnumber,
- neutrons = atomicnumber + math.max(math.random(0,1)),
- },
- electrons = atomicnumber,
- shells = {
- {max=2,have=0},
- {max=8,have=0},
- {max=18,have=0},
- {max=32,have=0},
- {max=32 or 50,have=0},
- {max=32 or 72,have=0},
- },
- rings = {},
- maxpool = function(self)
- print("Maximizing Possible electron shells...")
- for i = #self.shells, 500 do
- --]] 2n^2 = max electrons per shell
- self.shells[#self.shells+1] = {max= 2 * (math.pow(i,2)),have=0}
- end
- end,
- outermost = 1,
- init = function(self)
- local nextorbit = 0
- print("electrons - " .. self.electrons)
- for i = 1, #self.shells do
- if(self.electrons >= self.shells[i].max)then
- self.shells[i].have = self.shells[i].max
- self.rings[#self.rings+1] = self.shells[i].have
- print("shells - " .. self.shells[i].max)
- self.electrons = self.electrons - self.shells[i].max
- print("electrons - " .. self.electrons)
- elseif(self.electrons <= 8 and self.shells[i].max >= 8)then
- self.shells[i].have = self.electrons
- self.rings[#self.rings+1] = self.shells[i].have
- print("shells - " .. self.shells[i].have)
- self.electrons = 0
- self.outermost = i
- if(self.shells[self.outermost].have == 0)then
- print("Sorry atom could not be built. ")
- else
- print("done!")
- end
- break
- elseif(self.electrons > 8)then
- for x = 1, i do
- if(self.shells[#self.shells-x] == nil)then break end
- if(self.shells[#self.shells-x].max <= self.electrons)then
- if(self.electrons < 2)then break end
- if(self.electrons < 8 and self.shells[#self.shells-x].max == 2)then
- self.shells[#self.shells-x].have = self.electrons
- self.rings[#self.rings+1] = self.electrons
- self.electrons = 0
- print("shells - " .. self.shells[#self.shells-x].have)
- print("electrons - " .. self.electrons)
- break
- end
- self.shells[#self.shells-x].have = self.shells[#self.shells-x].max
- self.rings[#self.rings+1] = self.shells[#self.shells-x].have
- self.electrons = self.electrons - self.shells[#self.shells-x].max
- print("shells - " .. self.shells[#self.shells-x].have)
- print("electrons - " .. self.electrons)
- end
- end
- elseif(self.electrons < 2)then
- self.shells[i].have = self.electrons
- self.rings[#self.rings+1] = self.shells[i].have
- print("shells - " .. self.shells[i].have)
- --self.electrons = 0
- self.outermost = i
- if(self.shells[self.outermost].have == 0)then
- print("Sorry atom could not be built. ")
- else
- print("done!")
- end
- break;
- end
- end
- end,
- draw = function(self)
- local map = ""
- print("Protons: " .. self.nucleus.protons)
- print("Neutrons: " .. self.nucleus.neutrons)
- print("Predicted electron orbits: ")
- for i = 1, #self.rings do
- map = map .. tostring(self.rings[i])
- if(i < #self.rings)then map = map .. ", " end
- end
- print(map)
- --return map
- end,
- }
- if(huge)then atom:maxpool() end
- atom:init()
- return atom
- end
- --]] Shell and sub shells shell holds - 2n^2
- --]] EXAMPLE - K is n-1 so, it would have 2*1^2 maximum electrons. so, 2
- -- KEEP IN MIND MAX VALENCE ELECTRONS IS 8!
- -- K = 1s : 2
- -- L = 2s2p : 8
- -- M = 3s3p3d : 18
- -- N = 4s4p4d4f : 32
- -- O = 5s5p5d5f5g : 50
- -- P - 6s6p6d6f6g : 72
- --]] sub shell electrons - orbitals
- -- s = 1 orbital : 2
- -- p = 3 orbitals : 6
- -- d = 5 orbitals : 10
- -- f = 7 orbitals : 14
- -- g = 9 orbitals : 18
- -- Electron distribution
- -- electrons = 12 so,
- -- atom would have 3 shells
- -- KLM and would have 2 valence electrons
- -- Electron distribution filling 3 shells or more
- -- first fill K so e-2
- -- then fill L so e-8
- -- then fill M if M cant be filled then fill it with 8
- -- and move the remaining electrons into the N shell do this
- -- with other shells aswell.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement