Skip to content

Instantly share code, notes, and snippets.

@firm1
Created March 13, 2022 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save firm1/336e2c315816921b93d9ea68b491269f to your computer and use it in GitHub Desktop.
Save firm1/336e2c315816921b93d9ea68b491269f to your computer and use it in GitHub Desktop.
from tkinter import Tk, Canvas, Frame, BOTH
from colour import Color
import math
# les constantes de la formule
E0=20
U=0.0005
class Example(Frame):
def __init__(self):
super().__init__()
self.canvas = Canvas(self)
self.initUI()
def energy(self, deep):
# le calcul de l'energie
return E0*math.exp(-U*deep)
def draw_item(self):
x = 400
y = 300
long = 200
larg = 250
# dessin du laser
self.canvas.create_line(x, y-200, x + larg, y-200)
for i in range(x, x+larg+1, 50):
self.canvas.create_line(i, y-200+5, i, y-200+5+50)
# dessin du rectangle
self.canvas.create_line(x, y, x + larg, y, x + larg, y+long, x, y+long, x, y)
energies = []
for cpt in range(long):
e = self.energy(cpt)
energies.append(e)
if e == 0.0:
break
red = Color("red")
colors = list(red.range_to(Color("blue"), len(energies)))
for cpt in range(long):
if cpt < len(colors):
color = colors[cpt]
else:
color = Color("blue")
self.canvas.create_line(x, y+cpt, x + larg, y+cpt, fill=color)
def initUI(self):
self.master.title("X Ray")
self.pack(fill=BOTH, expand=1)
self.draw_item()
self.canvas.pack(fill=BOTH, expand=1)
def main():
root = Tk()
ex = Example()
root.geometry("1024x720+100+100")
root.mainloop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment