Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. import tkinter as tk
  2. import math
  3.  
  4. x = 20
  5. y = 20
  6. z = -20
  7.  
  8. def nextPoint():
  9. global x,y,z,app
  10.  
  11. x = x + 3
  12. y = y + 2
  13. z = z + 0.5
  14.  
  15. print(x,y,z)
  16.  
  17. app.drawPoint(x,y,z)
  18.  
  19. class Application(tk.Frame):
  20. def __init__(self, master=None):
  21. tk.Frame.__init__(self, master)
  22. self.pack()
  23. self.createWidgets()
  24. self.x=20
  25. self.y=20
  26. self.z=-2
  27.  
  28. self.maxDepth = -20
  29.  
  30. def createWidgets(self):
  31. self.canvas = tk.Canvas(self, bg="black", height=640, width=800)
  32. #arc = self.canvas.create_arc(coord, start=0, extent=150, fill="red")
  33. self.canvas.pack()
  34.  
  35. self.createPoint = tk.Button(self, text="Create point", fg="black", command=nextPoint)
  36. self.createPoint.pack(side="bottom")
  37.  
  38. self.QUIT = tk.Button(self, text="QUIT", fg="black", command=root.destroy)
  39. self.QUIT.pack(side="bottom")
  40.  
  41. def incrementHex(self, hex_str, increment): #with hex_str in format "#FFFFFF" or any colour
  42. red = int(hex_str[1:3],16) #specifies base for integer conversion
  43. green = int(hex_str[3:5],16)
  44. blue = int(hex_str[5:],16)
  45. red += increment #increment can be negative
  46. green += increment
  47. blue += increment
  48.  
  49. print(str(hex(red)))
  50.  
  51. if len(str(hex(red))[2:4]) < 2:
  52. new_hex_str = "#0" + str(hex(red))[2:4] + "0000"
  53. else :
  54. new_hex_str = "#" + str(hex(red))[2:4] + "0000"
  55. return new_hex_str
  56.  
  57. def drawPoint(self, x, y, z):
  58. self.canvas.create_oval(x-2, y-2, x+2, y+2, fill=self.incrementHex("#000000", round((z/self.maxDepth)*255)))
  59.  
  60. root = tk.Tk()
  61. app = Application(master=root)
  62.  
  63. app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement