Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- from math import sin,cos
- import random
- win = turtle.Screen()
- win.setup(1000,1000)
- win.bgcolor('black')
- win.tracer(0)
- win.listen()
- counter = 0
- def rotate(x,y,r):
- s,c = sin(r), cos(r)
- return x*c-y*s, x*s+y*c
- class Cube:
- EDGES = (0,1), (1,2), (2,3), (3,0),(4,5), (5,6), (6,7), (7,4),(0,4), (1,5), (2,6), (3,7)
- VERTEXES = [(-1,-1,-1),(1,-1,-1), (1,1,-1),(-1,1,-1),(-1,-1,1),(1,-1,1),( 1,1,1),(-1,1,1)]
- def __init__(self, xpos, ypos, counter,axes, color):
- self.xpos = xpos
- self.ypos = ypos
- self.counter = counter
- self.axes = axes
- self.c = color
- self.t = turtle.Turtle()
- self.t.ht()
- self.t.color(self.c)
- self.distance = 300
- def draw(self):
- for edge in self.EDGES:
- points = []
- for vertex in edge:
- x,y,z = self.VERTEXES[vertex]
- if self.axes == '3':
- x,z = rotate(x,z,self.counter)
- y,z = rotate(y,z,self.counter)
- x,y = rotate(x,y,self.counter)
- elif self.axes == 'x':
- y,z = rotate(y,z,self.counter)
- elif self.axes == 'y':
- x,z = rotate(x,z,self.counter)
- elif self.axes == 'z':
- x,y = rotate(x,y,self.counter)
- z += 5
- if z != 0:
- f = self.distance/(z)
- sx, sy = x*f,y*f
- points.append((sx,sy))
- self.t.up()
- self.t.goto(points[0][0]+self.xpos, points[0][1]+self.ypos)
- self.t.down()
- self.t.goto(points[1][0]+self.xpos, points[1][1]+self.ypos)
- self.t.goto(points[0][0]+self.xpos, points[0][1]+self.ypos)
- self.t.up()
- def move_in(self):
- if self.distance<1000:
- self.distance+=50
- def move_out(self):
- if self.distance>50:
- self.distance-= 50
- # Cube(x,y,counter,axes,color)
- cube = Cube(0,0,counter,'3', 'blue')
- win.onkey(cube.move_in, 'Up')
- win.onkey(cube.move_out, 'Down')
- while True:
- cube.t.clear()
- cube.draw()
- win.update()
- cube.counter += 0.005
- #MADE BY AVMP
- #https://www.youtube.com/channel/UCQor7IURWM-lGT-tmFbFSCw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement