Schülerarbeit: Skyline vor Sonnenuntergang

Turtle Graphics

Valeria Scheiwillers Programm ist eine animierte Skyline in Sonnenuntergangsstimmung.

Der Programm-Code

#
# (c) 2014, Valeria Scheiwiller
#
from gturtle import *
from random import randint
from time import sleep

def rechteck():
    penWidth(3)
    forward(5)
     
def fensterhaus(minX,maxX,maxY):
    anzahl = randint(4,13)
    n=1
    repeat anzahl:
        x = (randint(minX,maxX)//5)*5
        y = (randint(-200,maxY)//5)*5
        setPos(x,y)
        if n == -1:
            setPenColor("yellow")
        if n== 1:
            setPenColor(makeColor(1.0,0.8,0.2))
        n= n*-1   
        rechteck()
        
#Point-to-Point
def fillPolygon(shape):
    setPos(head(shape))
    startPath()
    for point in shape:
        moveTo(point)
    fillPath()

skyline = [
    (-400,-151),(-355,-146),(-354,-150),(-296,-165),
    (-270,-181),(-279,-181),(-280,-171),(-264,-159),
    (-266,-117),(-261,-111),(-261,-92),(-256,-90),
    (-256,-82),(-246,-78),(-245,-73),(-239,-73),
    (-238,-74),(-204,-69),(-199,-71),(-198,-73),
    (-195,-74),(-195,-89),(-156,-89),(-156,-169),
    (-151,-169),(-151,-120),(-146,-119),(-144,-116),
    (-125,-116),(-119,-124),(-119,-119),(-115,-139),
    (-109,-139),(-110,-112),(-76,-108),(-75,23),
    (-68,26),(-68,-53),(-63,53),(-61,-5),(-57,-7),
    (-51,-13),(-49,-15),(-47,-30),(-44,-31),(-44,-26),
    (-23,-27),(-20,-83),(-19,-85),(-12,-151),(-6,-151),
    (-8,-103),(6,-103),(6,-114),(11,-115),(11,-50),
    (18,-52),(18,-43),(21,-43),(22,-15),(26,-15),
    (26,-43),(32,-43),(43,-48),(44,-49),(44,-62),
    (59,-64),(62,-98),(71,-100),(76,-118),(77,-99),
    (102,-99),(106,-170),(114,-170),(114,-142),
    (114,-132),(132,-132),(132,-141),(144,-141),
    (145,-163),(151,-169),(171,-169),(169,-138),
    (176,-136),(174,-99),(179,-111),(179,-95),(189,-77),
    (188,-62),(190,-46),(192,-46),(196,-64),(196,-80),
    (206,-91),(207,-108),(210,-94),(214,-125),(215,-143),
    (219,-142),(220,-140),(228,-140),(229,-121),
    (233,-121),(233,-138),(244,-138),(259,-148),
    (259,-89),(300,-89),(303,-163),(309,-163),(314,-153),
    (353,-151),(353,-133),(373,-133),(372,-150),
    (400,-150),(400,-300),(-400,-300),(-400,-151)
  ]

fenster = [
    (-400,-354,-158),(-354,-263,-176),(-254,-198,-87),
    (-195,-162,-99),(-149,-123,-126),(-120,-104,-144),
    (-105,-80,-120),(-71,-26,-40),(-28,-5,-155),
    (-3,13,-116),(16,39,-59),(41,54,-66),(57,71,-112),
    (76,98,-115),(99,112,-177),(120,128,-139),
    (133,135,-147),(146,162,-180),(178,181,-140),
    (183,203,-99),(205,256,-148),(264,297,-96),
    (297,317,-185),(316,398,-171),(357,368,-140)
  ]

makeTurtle()
#Start Farbverlauf
hideTurtle()
right(90)
i = 0
winkel = 90
setPos(-400,-181)
repeat 479:
    i += 1
    setPenColor( makeColor(1.0, i/479, 0.0) )
    forward(800)
    left(winkel)
    forward(1)
    left(winkel)    
    winkel *= -1
#END
#Start Skyline
repeat:
    setPenColor("black")
    setFillColor("black")
    setPos(-400,-151)
    fillPolygon(skyline)
    for minX,maxX,maxY in fenster:
        fensterhaus(minX,maxX,maxY)
    sleep(1)
#END