Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_s_curve.py
- import tkinter as tk
- import random
- import math
- steps_value = 500
- start_y = 200
- end_y = 50
- def draw_s_curve():
- canvas.delete("all")
- canvas_width = canvas.winfo_width()
- start_x = (canvas_width - steps_value) // 2
- end_x = start_x + steps_value
- for i in range(start_x, end_x + 1):
- x = i - start_x
- y = start_y + (end_y - start_y) * (math.sin((x / steps_value) * math.pi - (math.pi / 2)) + 1) / 2 + 30
- canvas.create_oval(i, y, i, y, fill='black')
- def get_steps_value(event):
- global steps_value
- steps_value = int(steps_scale.get())
- draw_s_curve()
- def get_start_y(event):
- global start_y
- start_y = 255 - int(start_scale.get())
- draw_s_curve()
- def get_end_y(event):
- global end_y
- end_y = 255 - int(end_scale.get())
- draw_s_curve()
- root = tk.Tk()
- root.title("S-Curve Generator")
- canvas = tk.Canvas(root, width=600, height=300, bg="white")
- canvas.pack()
- steps_scale = tk.Scale(root, from_=8, to=600, orient=tk.HORIZONTAL, label="Steps", command=get_steps_value)
- steps_scale.set(steps_value) # Set default length to 500
- steps_scale.pack(fill='x')
- start_scale = tk.Scale(root, from_=0, to=255, orient=tk.HORIZONTAL, label="Start Point", command=get_start_y)
- start_scale.set(start_y) # Set default start to 200
- start_scale.pack(fill='x')
- end_scale = tk.Scale(root, from_=0, to=255, orient=tk.HORIZONTAL, label="End Point", command=get_end_y)
- end_scale.set(end_y) # Set default end to 50
- end_scale.pack(fill='x')
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement