Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import math
- x = 20
- y = 20
- z = -20
- def nextPoint():
- global x,y,z,app
- x = x + 3
- y = y + 2
- z = z + 0.5
- print(x,y,z)
- app.drawPoint(x,y,z)
- class Application(tk.Frame):
- def __init__(self, master=None):
- tk.Frame.__init__(self, master)
- self.pack()
- self.createWidgets()
- self.x=20
- self.y=20
- self.z=-2
- self.maxDepth = -20
- def createWidgets(self):
- self.canvas = tk.Canvas(self, bg="black", height=640, width=800)
- #arc = self.canvas.create_arc(coord, start=0, extent=150, fill="red")
- self.canvas.pack()
- self.createPoint = tk.Button(self, text="Create point", fg="black", command=nextPoint)
- self.createPoint.pack(side="bottom")
- self.QUIT = tk.Button(self, text="QUIT", fg="black", command=root.destroy)
- self.QUIT.pack(side="bottom")
- def incrementHex(self, hex_str, increment): #with hex_str in format "#FFFFFF" or any colour
- red = int(hex_str[1:3],16) #specifies base for integer conversion
- green = int(hex_str[3:5],16)
- blue = int(hex_str[5:],16)
- red += increment #increment can be negative
- green += increment
- blue += increment
- print(str(hex(red)))
- if len(str(hex(red))[2:4]) < 2:
- new_hex_str = "#0" + str(hex(red))[2:4] + "0000"
- else :
- new_hex_str = "#" + str(hex(red))[2:4] + "0000"
- return new_hex_str
- def drawPoint(self, x, y, z):
- self.canvas.create_oval(x-2, y-2, x+2, y+2, fill=self.incrementHex("#000000", round((z/self.maxDepth)*255)))
- root = tk.Tk()
- app = Application(master=root)
- app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement