From a9bf59c08fdf3e9f7ac39807f8d5bacf053c8ec6 Mon Sep 17 00:00:00 2001 From: Tangent Date: Thu, 3 Oct 2019 19:57:29 -0700 Subject: [PATCH] init version..sort of --- .gitignore | 1 + nuclear_notes.txt | 19 +++++++ src/main.moon | 129 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 .gitignore create mode 100644 nuclear_notes.txt create mode 100644 src/main.moon diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d907c43 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.lua diff --git a/nuclear_notes.txt b/nuclear_notes.txt new file mode 100644 index 0000000..e289bb6 --- /dev/null +++ b/nuclear_notes.txt @@ -0,0 +1,19 @@ + Z N s + odd odd 0.015 + odd even 0.18 +even odd 0.205 +even even 0.6 + +Z > 82 -> unstable +Z <= 20 -> stable n/p is nearly 1 (0.775 - 1.29) +Z > 20 & Z <= 82 -> stable n/p between 1:1 and 1.5:1 +Z > 92 -> spontaneous fission +Z > 52 -> alpha rays possible + +Can induce fission by neutron bombardment. +Too many neutrons -> beta decay, neutron emission +Too few neutrons -> electron capture, positron emission, proton emission + +Alpha: Emits 2Z-2N +Beta: Emits e, 1N -> 1Z +Electron capture & Positron emission: Emits e+, 1Z -> 1N diff --git a/src/main.moon b/src/main.moon new file mode 100644 index 0000000..90d4fc7 --- /dev/null +++ b/src/main.moon @@ -0,0 +1,129 @@ +class Isotopes + new: (@seed=0) => + @rng = love.math.newRandomGenerator(@seed) + @randoms = {} + @normals = {} + get: (z, n) => + @[z] = {} unless @[z] + @generate(z, n) unless @[z][n] + return @[z][n] + normal: (z, n) => + i = n^2 - (z - 1) + if z > n + i -= (z - n) + while #@normals < i + @normals[#@normals+1] = @rng\randomNormal 0.25, 1 + return @normals[i] + random: (z, n) => + i = n^2 - (z - 1) + if z > n + i -= (z - n) + while #@randoms < i + @randoms[#@randoms+1] = @rng\random! + return @randoms[i] + generate: (z, n) => + @[z] = {} unless @[z] + isotope = {} + + -- isotopes only exist in this range + if n/z > 0.9 and n/z < 1.2 + v = 2 / math.abs(n - z) -- base stability is proximity to n == z + -- v /= @rng\randomNormal 0.25, 1 -- a slight random variation + v /= @normal(z, n) + local odd_even -- based on statistics from real isotopes + if z % 2 == 0 + if n % 2 == 0 + odd_even = 0.6 + else + odd_even = 0.205 + else + if n % 2 == 0 + odd_even = 0.18 + else + odd_even = 0.015 + -- if @rng\random! <= v * odd_even -- more random variation based on stats + if @random(z, n) <= v * odd_even + v *= odd_even + if v > 1 -- maximum stability should be close to 1 + v = 1.05 + v -= z / 1000 -- lighter elements should have a higher stability + isotope.stability = v + else + isotope.stability = 0 -- this isotope cannot exist + + if isotope.stability < 1 + isotope.half_life = 0.69314718056 / (1 - isotope.stability) + -- isotope.half_life = 0.69314718056 / isotope.stability + else + isotope.half_life = math.huge + + @[z][n] = isotope + +-- Z > 82 -> unstable +-- Z <= 20 -> stable n/p is nearly 1 (0.775 - 1.29) +-- Z > 20 & Z <= 82 -> stable n/p between 1:1 and 1.5:1 +-- Z > 92 -> spontaneous fission +-- Z > 52 -> alpha rays possible +-- Can induce fission by neutron bombardment. +-- Too many neutrons -> beta decay, neutron emission +-- Too few neutrons -> electron capture, positron emission, proton emission +-- Alpha: Emits 2Z-2N +-- Beta: Emits e, 1N -> 1Z +-- Electron capture & Positron emission: Emits e+, 1Z -> 1N + +export showUnstable = true +w, h = love.graphics.getDimensions! + +isotopes = Isotopes! + +love.load = -> + above_0 = 0 + above_1 = 0 + min_half_life = math.huge + max_half_life = 0 + min_z, min_n = 0, 0 + max_z, max_n = 0, 0 + min_s = 0 + max_s = 0 + for z = 1, w + for n = 0, h + isotope = isotopes\get z, n + if isotope.stability > 0 + above_0 += 1 + if isotope.half_life < min_half_life + min_half_life = isotope.half_life + min_z = z + min_n = n + min_s = isotope.stability + if isotope.stability < 1 + if isotope.half_life > max_half_life + max_half_life = isotope.half_life + max_z = z + max_n = n + max_s = isotope.stability + else + above_1 += 1 + print "#{above_0} isotopes", "#{above_1} stable isotopes" + print "Shortest half life:", "#{min_half_life}", "#{min_z}P#{min_n}N", min_s + print "Longest half life:", "#{max_half_life}", "#{max_z}P#{max_n}N", max_s + +-- decay constant (probability of decay per second): 1 - stability +-- half life: 0.69314718056 / decay constant +-- I have redefined stability to equal the decay constant + +love.draw = -> + scale = 3 + for z = 1, w + for n = 0, h + isotope = isotopes\get z, n + s = isotope.stability + if s >= 1 or showUnstable + -- c = 1 - s -- side effect -> stable isotopes are now invisible + love.graphics.setColor s, s, s, 1 + love.graphics.rectangle "fill", (z - 1) * scale, (h / scale - n - 1) * scale, scale, scale + +love.keypressed = (key) -> + love.event.quit! if key == "escape" + switch key + when "s" + showUnstable = not showUnstable