From bb7ca4d19d501b211d6479eed3cfadf7d52a2f71 Mon Sep 17 00:00:00 2001 From: kbraught <kbraught@iastate.edu> Date: Thu, 31 Mar 2022 15:45:27 -0500 Subject: [PATCH] add python input example --- toythermo.py | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 toythermo.py diff --git a/toythermo.py b/toythermo.py new file mode 100644 index 00000000..e06a0ba5 --- /dev/null +++ b/toythermo.py @@ -0,0 +1,135 @@ +#python logic toy code: + +from enum import Enum, auto +from ssl import VERIFY_X509_PARTIAL_CHAIN +from statistics import mode +from termios import VSTART + + +class Modes(Enum): + NormalA = auto() + NormalB = auto() + NormalC = auto() + NormalD = auto() + +class State: + posx = 0.0 + posy = 0.0 + vx = 1.0 + vy = 1.0 + mode = Modes.NormalA + + def __init__(self): + self.data = [] + + + +#todo: how would this actually be given +s = State() + +posx = s.posx +posy = s.posy +vx = s.vx +vy = s.vy +state = s.mode +if (state ==Modes.NormalA): + if posy<0 and posy>=-0.01: + vy=-vy + posy=0 + state=Modes.NormalA + + if (posx<0 and posx>=-0.01) : + vx=-vx + posx=0 + state=Modes.NormalB + + if (posx<=5.01 and posx>5) : + vx=-vx + posx=5 + state=Modes.NormalC + + if (posy>5 and posy<=5.01) : + vy=-vy + posy=5 + state = Modes.NormalD + + + +if (state ==Modes.NormalB) : + if (posy<0 and posy>=-0.01) : + vy=-vy + posy=0 + state=Modes.NormalB + + if (posx<0 and posx>=-0.01) : + vx=-vx + posx=0 + state=Modes.NormalA + + if (posx<=5.01 and posx>5) : + vx=-vx + posx=5 + state=Modes.NormalC + + if (posy>5 and posy<=5.01) : + vy=-vy + posy=5 + state = Modes.NormalD + + + +if (state ==Modes.NormalC) : + if (posy<0 and posy>=-0.01) : + vy=-vy + posy=0 + state=Modes.NormalC + + if (posx<0 and posx>=-0.01) : + vx=-vx + posx=0 + state=Modes.NormalA + + if (posx<=5.01 and posx>5) : + vx=-vx + posx=5 + state=Modes.NormalB + + if (posy>5 and posy<=5.01) : + vy=-vy + posy=5 + state = Modes.NormalD + + + + +if (state ==State.Modes.NormalD) : + if (posy<0 and posy>=-0.01) : + vy=-vy + posy=0 + state=Modes.NormalD + + if (posx<0 and posx>=-0.01) : + vx=-vx + posx=0 + state=Modes.NormalA + + if (posx<=5.01 and posx>5) : + vx=-vx + posx=5 + state=Modes.NormalB + + if (posy>5 and posy<=5.01) : + vy=-vy + posy=5 + state = Modes.NormalC + + + +s.posx = posx +s.posy= posy +s.vx = vx +s.vy = vy +s.mode = state + +#TODO: what is output? + -- GitLab