repl.it
Python (with Turtle)

No description

fork
loading
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from math import sin, cos
import turtle

VERTEXES = [(-1, -1, -2), ( 1, -1, -2), ( 1,  1, -2), (-1,  1, -2),
            (-1, -1,  9), ( 1, -4,  1), ( 1,  5,  1), (-1,  1,  1)]

TRIANGLES = [
    (0, 4, 2), (2, 6, 0),
    (0, 4, 5), (5, 1, 0),
    (0, 4, 3), (4, 7, 3),
    (5, 4, 7), (7, 6, 5),
    (7, 6, 3), (6, 2, 3),
    (5, 1, 2), (2, 6, 5)
]

FOV = 400

# Create turtle,
pointer = turtle.Turtle()

# Turn off move time, makes drawing instant,
turtle.tracer(0, 0)
pointer.up()

def rotate(x, y, r):
  s, c = sin(r), cos(r)
  return x * c - y * s, x * s + y * c

counter = 0
while True:
	# Clear screen,
	pointer.clear()

	# Draw,
	for triangle in TRIANGLES:
		points = []
		for vertex in triangle:
			# Get the X, Y, Z coords out of the vertex iterator,
			x, y, z = VERTEXES[vertex]

			# Rotate,
			x, z = rotate(x, z, counter)
			y, z = rotate(y, z, counter)
			x, y = rotate(x, y, counter)

			# Perspective formula,
			z += 5
			f = FOV / z
			sx, sy = x * f, y * f

			# Add point,
			points.append((sx, sy))
		
		# Draw trangle,
		pointer.goto(points[0][0], points[0][1])
		pointer.down()

		pointer.goto(points[1][0], points[1][1])
		pointer.goto(points[2][0], points[2][1])
		pointer.goto(points[0][0], points[0][1])
		pointer.up()

	# Update,
	turtle.update()

	counter += 0.025
result
console