Created
March 1, 2018 01:45
-
-
Save SnugBug/1cc5ea67d11487d69aae8549107372ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter import Tk, Canvas, PhotoImage, mainloop | |
from math import cos, sin, radians | |
import itertools | |
import time | |
def rotate(pos,rot): | |
x,y,z = pos | |
Rx,Ry,Rz = [radians(x) for x in rot] | |
cA, cB, cC, sA, sB, sC = [cos(Rx), cos(Ry), cos(Rz), sin(Rx), sin(Ry), sin(Rz)] | |
Fx = (x * cB * cC) + (y * sA * sB * cC) + (y * cA * sC) + (z * -cA * sB * cC) + (z * sA * sC) | |
Fy = (x * -cB * sC) + (y * -sA * sB * sC) + (y * cA * cC) + (z * cA * sB * sC) + (z * sA * cC) | |
Fz = (x * sB) + (y * -sA * cB) + (z * cA * cB) | |
return [Fx,Fy,Fz] | |
WIDTH, HEIGHT = 640, 480 | |
window = Tk() | |
canvas = Canvas(window, width=WIDTH, height=HEIGHT, bg="#000000") | |
canvas.pack() | |
img = PhotoImage(width=WIDTH, height=HEIGHT) | |
canvas.create_image((WIDTH/2, HEIGHT/2), image=img, state="normal") | |
canvas.pack() | |
for i in range(0,3600): | |
rot = [0,i,0] | |
Tx,Ty,Tz,Zm = [0,0,200,200] | |
x,y,z = [10,10,10] | |
for m,n in itertools.product(range(-50,50,2),range(-50,50,2)): | |
x,y,z = rotate([m,n,0],rot) | |
img.put("#ffffff", (int(WIDTH/2 + ((x+Tx)*Zm/(z+Tz))), int(HEIGHT/2 - ((y+Ty)*Zm/(z+Tz))))) | |
canvas.update() | |
img.blank() | |
mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment