Skip to content

Instantly share code, notes, and snippets.

@hlorand
Last active March 1, 2023 21:54
Show Gist options
  • Select an option

  • Save hlorand/a6649d8e8a2e744b3511c6bad88ba435 to your computer and use it in GitHub Desktop.

Select an option

Save hlorand/a6649d8e8a2e744b3511c6bad88ba435 to your computer and use it in GitHub Desktop.
3D rotating cube in Python - only 15 lines of code https://imgur.com/87vnopo.gif
# 3D rotating cube in Python - only 15 lines of code https://imgur.com/87vnopo.gif
import tkinter, math, time
c = tkinter.Canvas(tkinter.Tk(), width=600, height=600)
c.pack()
while t := int(time.time()*60) :
c.update()
c.delete("all"); n = []
for p in range( t % 157, 628, 157 ):
x = 180 * math.cos(p/100) + 300
y = 60 * math.sin(p/100)
n.extend([[x,y+190],[x,y+410]])
for i in range(-2,len(n)-2):
c.create_line(n[i], n[i+abs(i%2-1)], n[i], n[i+2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment