• Lage ulike figurer med Turtle-biblioteket. Bruke funksjoner til å lage de figurene vi ønsker.

Forslag til kode:

from turtle import*
def kvadrat(size,farge):
    pendown()
    begin_fill()
    fillcolor(farge)
    for i in range(4):
        forward(size)
        left(90)
    end_fill()
    penup()
goto(0,0)
kvadrat(100,"blue")
goto(-100,100)
kvadrat(70,"red")
goto(-150,-150)
kvadrat(120,"yellow")
goto(200,200)
kvadrat(50,"green")
  • Bruke Tutle til å lage kunstverk:

Forslag til kode:

from turtle import*
from random import randint,choice
farger = ["yellow","blue","green","black","purple","navy","brown","maroon","magenta","gold"]
speed(0)


def kvadrat(size,farge):
    pendown()
    begin_fill()
    fillcolor(farge)
    for i in range(4):
        forward(size)
        left(90)
    end_fill()
    penup()
    
for i in range(100):
    penup()
    goto(randint(-300,300), randint(-300,300))
    kvadrat(randint(1,100),choice(farger))
  • Lage stjernehimmel:

Forslag til kode:

from turtle import*
from random import randint,choice
farger = ["yellow","blue","green","purple","navy","brown","maroon","magenta","gold","light green","dark green"]
speed(0)
bgcolor("black")


def star(size,farge):
    #pendown()
    begin_fill()
    fillcolor(farge)
    for i in range(4):
        forward(size)
        left(144)
    end_fill()
    penup()

penup()    
for i in range(100):
    penup()