This is my first try with turtle graphics in Python.
It is in fact a sort of "translation" from some old LOGO code.
When you run it, this should be the result:
Insiders can perhaps play the "Dark side of the moon" record by Pink Floyd :)
Any comments (good or bad) on my code are more than welcome.
Light refraction
'''
Refraction of sunlight through a prism
Python 3.3
28.05.2014 Danny Marivoet
'''
import turtle as tu
TOPLEFT = (-470,350)
#left = (-470,0)
OFFSET = 60
INDIGO = '#4B0082'
def start():
tu.hideturtle()
tu.speed('fastest')
tu.bgcolor('black')
tu.pencolor('lightblue')
tu.penup()
tu.goto(TOPLEFT)
tu.write('Refraction of light through a prism.', True, align='left',font=('Ariel',24,'normal'))
tu.goto(0,0)
def draw_prism(x,y,side,color,pensize):
tu.goto(x,y)
tu.pendown()
tu.pencolor(color)
tu.pensize(pensize)
tu.backward(side/2)
tu.left(60)
tu.forward(side)
tu.right(120)
tu.forward(side)
tu.right(120)
tu.forward(side/2)
def draw_light_beam(x,y,length):
tu.penup()
tu.goto(x-length,y+OFFSET)
tu.pendown()
tu.pencolor('white')
tu.pensize(15)
tu.goto(x,y+OFFSET)
#tu.right(180)
#tu.forward(length)
def draw_refraction(color,x,tox,y,toy):
tu.penup()
tu.goto(x,y+OFFSET)
tu.pendown()
tu.pencolor(color)
tu.pensize(15)
tu.goto(tox,toy)
start()
draw_prism(0,-50,200,"white",2)
tu.speed('slowest')
draw_light_beam(0,0,400)
draw_refraction('red',0,400,0,-80)
draw_refraction('orange',0,400,0,-105)
draw_refraction('yellow',0,400,0,-130)
draw_refraction('green',0,400,0,-155)
draw_refraction('mediumblue',0,400,0,-180)
draw_refraction('navy',0,400,0,-205)
draw_refraction(INDIGO,0,400,0,-230)
tu.done()
TrustyTony 888 pyMod Team Colleague Featured Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
TrustyTony 888 pyMod Team Colleague Featured Poster
ddanbe commented: This is great help, thanks! +15
ddanbe 2,724 Professional Procrastinator Featured Poster
TrustyTony 888 pyMod Team Colleague Featured Poster
TrustyTony 888 pyMod Team Colleague Featured Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.