rainbow_spiral.py

Created by mobluse

Created on November 22, 2021

756 Bytes

Rainbow Spiral draws a spiral using the turtle library. First it asks for a closed caption that is printed on the picture. Press Esc/BACK or OK when the drawing is finished. You are dropped into the Python shell where you can rerun it using run(), and then the old caption is default. This program is based on an example from https://edublocks.org with the same name.


import time
from kandinsky import *
from turtle import *
n=""
def run():
  global n
  s="Rainbow Spiral"
  colors=("red","purple","blue","green","orange","yellow")
  print(s)
  d=""
  if len(n):
    d="("+n+") "
  ns=n
  n=input("Closed Caption: "+d)
  if not len(n):
    n=ns
  print("CC is \""+n+"\".")
  time.sleep(2)
  t0 = time.monotonic()
  reset()
  speed(0)
  pu()
  ht()
  fill_rect(0,0,320,222,"black")
  draw_string(n,5,200,colors[2],colors[5])
  p=pos()
  w=(-140,85)
  goto(w)
  write(s)
  goto(p)
  pd()
  for i in range(210):
    color(colors[i%6])
    width(i//50+1)
    fd(i)
    lt(59)
  pu()
  draw_string(n,5,200,colors[2],colors[5])
  goto(w)
  seth(0)
  write(s)
  pd()
  t1=time.monotonic()
  print(t1-t0)
run()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.