0% found this document useful (0 votes)
5 views

Spinning Triangular Prism in python

The document is a Python script using Pygame to create a visual representation of a triangular prism. It initializes colors and points, then draws lines to represent the prism in various phases, updating the display in a loop. The script concludes with a wait period before closing the window.

Uploaded by

2009571
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Spinning Triangular Prism in python

The document is a Python script using Pygame to create a visual representation of a triangular prism. It initializes colors and points, then draws lines to represent the prism in various phases, updating the display in a loop. The script concludes with a wait period before closing the window.

Uploaded by

2009571
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

"""

TRIANGULAR_PRISM_ATTEMPT

Description:
"""

# # # P Y G A M E I M P O R T A N D I N I T I A L I Z E # # #
import pygame
pygame.init()
# # # V A R I A B L E S # # #
# # C O L O R S # #
tar = 255
tag = 255
tab = 0
tacolor = (tar,tag,tab)

tbr = 0
tbg = 255
tbb = 255
tbcolor = (tbr,tbg,tbb)

tcr = 255
tcg = 0
tcb = 255
tccolor = (tcr,tcg,tcb)

# tcolor = (tr,tg,tb)
abr = 0
abg = 255
abb = 0
abcolor = (abr,abg,abb)
bcr = 0
bcg = 0
bcb = 255
bccolor = (bcr,bcg,bcb)
car = 255
cag = 0
cab = 0
cacolor = (car,cag,cab)
"""
# # P O I N T V A R I A B L E S # #
# top=(489,266)
topx=489
topy=266
top=(topx,topy)

# ap=(489,226)
apx=489
apy=226
ap=(apx,apy)

# bp=(449,286)
bpx=449
bpy=286
bp=(bpx,bpy)

# cp=(529,286)
cpx=529
cpy=286
cp=(cpx,cpy)
"""
# bgv = background view
bgv = 3
# ngv = normal gound view
ngv = 5
# fgv = foreground view
fgv = 7

# # # O P E N I N G W I N D O W # # #
w = pygame.display.set_mode([1018, 573])
# # # C O L O R C H A N G E T O B L A C K # # #
w.fill((0, 0, 0))
pygame.display.flip()
while True:
# # # # P H A S E O N E # # #
w.fill((0, 0, 0))
pygame.display.flip()
topx=489
topy=276
top=(topx,topy)
apx=489
apy=236
ap=(apx,apy)
bpx=449
bpy=286
bp=(bpx,bpy)
cpx=529
cpy=286
cp=(cpx,cpy)
pygame.draw.line(w,tacolor,top,ap,bgv)
pygame.draw.line(w,tbcolor,top,bp,bgv)
pygame.draw.line(w,tccolor,top,cp,bgv)

pygame.draw.line(w,abcolor,ap,bp,ngv)
pygame.draw.line(w,bccolor,bp,cp,fgv)
pygame.draw.line(w,cacolor,cp,ap,ngv)
pygame.display.flip()
pygame.time.wait(250)

# # # # P H A S E T W O # # #
w.fill((0, 0, 0))
pygame.display.flip()

topx-=20
topy=276
top=(topx,topy)
apx-=5
apy=236
ap=(apx,apy)
bpx+=20
bpy=286
bp=(bpx,bpy)
cpx-=20
cpy=286
cp=(cpx,cpy)
sctn1=bgv
sctn2=ngv

pygame.draw.line(w,tacolor,top,ap,bgv)
pygame.draw.line(w,tbcolor,top,bp,bgv)
pygame.draw.line(w,tccolor,top,cp,bgv)

pygame.draw.line(w,abcolor,ap,bp,fgv)
pygame.draw.line(w,bccolor,bp,cp,ngv)
pygame.draw.line(w,cacolor,cp,ap,ngv)
pygame.display.flip()
pygame.time.wait(250)

# # # # P H A S E T H R E E # # #
w.fill((0, 0, 0))
pygame.display.flip()

topx-=25
topy=276
top=(topx,topy)
apx-=5
apy=236
ap=(apx,apy)
bpx+=20
bpy=286
bp=(bpx,bpy)
cpx-=20
cpy=286
cp=(cpx,cpy)

sctn1=bgv
sctn2=ngv

pygame.draw.line(w,tacolor,top,ap,ngv)
pygame.draw.line(w,tbcolor,top,bp,ngv)
pygame.draw.line(w,tccolor,top,cp,ngv)

pygame.draw.line(w,abcolor,ap,bp,ngv)
pygame.draw.line(w,bccolor,bp,cp,ngv)
pygame.draw.line(w,cacolor,cp,ap,bgv)
pygame.display.flip()
pygame.time.wait(250)

# # # # P H A S E F O U R # # #
w.fill((0, 0, 0))
pygame.display.flip()

topx+=25
topy=276
top=(topx,topy)
apx+=10
apy=236
ap=(apx,apy)
bpx+=20
bpy=286
bp=(bpx,bpy)
cpx-=20
cpy=286
cp=(cpx,cpy)

sctn1=bgv
sctn2=ngv

pygame.draw.line(w,abcolor,ap,bp,bgv)
pygame.draw.line(w,bccolor,bp,cp,bgv)
pygame.draw.line(w,cacolor,cp,ap,bgv)

pygame.draw.line(w,tacolor,top,ap,ngv)
pygame.draw.line(w,tbcolor,top,bp,ngv)
pygame.draw.line(w,tccolor,top,cp,ngv)
pygame.display.flip()
pygame.time.wait(250)

# # # # P H A S E F I V E # # #
w.fill((0, 0, 0))
pygame.display.flip()

topx+=20
topy=276
top=(topx,topy)
apx-=0
apy=236
ap=(apx,apy)
bpx+=20
bpy=286
bp=(bpx,bpy)
cpx-=20
cpy=286
cp=(cpx,cpy)

sctn1=bgv
sctn2=ngv

pygame.draw.line(w,abcolor,ap,bp,ngv)
pygame.draw.line(w,bccolor,bp,cp,ngv)
pygame.draw.line(w,cacolor,cp,ap,ngv)

pygame.draw.line(w,tacolor,top,ap,fgv)
pygame.draw.line(w,tbcolor,top,bp,fgv)
pygame.draw.line(w,tccolor,top,cp,fgv)
pygame.display.flip()
pygame.time.wait(250)

# # # P H A S E S I X # # #
w.fill((0, 0, 0))
pygame.display.flip()

topx+=25
topy=276
top=(topx,topy)
apx+=5
apy=236
ap=(apx,apy)
bpx-=20
bpy=286
bp=(bpx,bpy)
cpx+=20
cpy=286
cp=(cpx,cpy)

sctn1=bgv
sctn2=ngv

pygame.draw.line(w,abcolor,ap,bp,ngv)
pygame.draw.line(w,bccolor,bp,cp,bgv)
pygame.draw.line(w,cacolor,cp,ap,bgv)

pygame.draw.line(w,tacolor,top,ap,ngv)
pygame.draw.line(w,tbcolor,top,bp,ngv)
pygame.draw.line(w,tccolor,top,cp,ngv)
pygame.display.flip()
pygame.time.wait(250)

# # # P H A S E S E V E N # # #
w.fill((0, 0, 0))
pygame.display.flip()

topx+=25
topy=276
top=(topx,topy)
apx+=10
apy=236
ap=(apx,apy)
bpx-=20
bpy=286
bp=(bpx,bpy)
cpx+=20
cpy=286
cp=(cpx,cpy)

sctn1=bgv
sctn2=ngv

pygame.draw.line(w,abcolor,ap,bp,ngv)
pygame.draw.line(w,bccolor,bp,cp,bgv)
pygame.draw.line(w,cacolor,cp,ap,bgv)

pygame.draw.line(w,tacolor,top,ap,ngv)
pygame.draw.line(w,tbcolor,top,bp,ngv)
pygame.draw.line(w,tccolor,top,cp,ngv)
pygame.display.flip()
pygame.time.wait(250)

# # # P H A S E E I G H T # # #
w.fill((0, 0, 0))
pygame.display.flip()

topx-=20
topy=276
top=(topx,topy)
apx-=5
apy=236
ap=(apx,apy)
bpx+=20
bpy=286
bp=(bpx,bpy)
cpx-=20
cpy=286
cp=(cpx,cpy)

sctn1=bgv
sctn2=ngv

pygame.draw.line(w,tacolor,top,ap,bgv)
pygame.draw.line(w,tbcolor,top,bp,bgv)
pygame.draw.line(w,tccolor,top,cp,bgv)

pygame.draw.line(w,abcolor,ap,bp,fgv)
pygame.draw.line(w,bccolor,bp,cp,ngv)
pygame.draw.line(w,cacolor,cp,ap,ngv)
pygame.display.flip()
pygame.time.wait(250)
# # # C L O S I N G # # #
pygame.time.wait(3000)
# input("Enter to close")

You might also like