DEV Community

sazdboiz
sazdboiz

Posted on

✨3D spinning plate in python in less than 30 lines✨

What we get:

Plugin

import math
import time
Enter fullscreen mode Exit fullscreen mode

Settings - You can change

R = 0 #rotateposition
PW = 100 #platewide
PH = round(PW/32*14, 0) #plateheight
colours = [".",",","-","~",":",";","=","!","*","#","$","@"]
Enter fullscreen mode Exit fullscreen mode

Calculating

By using this:
Image description
We have:

while True:
    lighting = int(round(abs(11 * (math.cos(math.radians(R+90)))),0))
    DPW = round(abs(PW * (math.cos(math.radians(R)))),0) #displayplatewide
Enter fullscreen mode Exit fullscreen mode

Rotating loops

    R = R + 4
Enter fullscreen mode Exit fullscreen mode

Printing

    HL = PH  # heightloops
    S = (PW - DPW)/2 #space
    x = True
Enter fullscreen mode Exit fullscreen mode

S means the numbers of " " in this:
Image description

    while x:
        if HL == 0:
            x = False
        print(' ' * int(S),(colours[lighting]) * int(DPW))
        HL = HL - 1
    time.sleep(0.1)

Enter fullscreen mode Exit fullscreen mode

But the frames are connected, let's fix it!

    HL = PH #heightloops
    y = True
    while y:
        if HL == 0:
            y = False
        print(" ")
        HL = HL - 1
Enter fullscreen mode Exit fullscreen mode

If this help you, upvote!

Top comments (1)

Collapse
 
trungdao profile image
Trung

good job, boy! Keep your passion always