User:Jakobap15

From rtgkomArkiv
Jump to: navigation, search
Navn: IT-komponentens navn: Screendump: Funktion: Ophavsmand/mænd:
Jakob Andkjær Poulsgærd Python http://rtgkom.dk/~jakobap15/styled/links/opgaver/itopgave/helloworld_kopi.png Funktionen med Python er at kode programmer og lave scripts. Python Software Foundation, men designet af Guido van Rossum
Årstal når IT-komponenten fremkom: Organisation: Licens: Pris: Primære kilder:
20 feb. 1991 Python Software Foundation GPL (General Public License) Open source https://www.python.org/about/ og https://en.wikipedia.org/wiki/Python_(programming_language)

Jakob A. Poulsgærd[edit]

Blomster landskab:
http://rtgkom.dk/~jakobap15/turtlebilleder/lille_blomst.png

Skærmbillede af kildekode:
http://rtgkom.dk/~jakobap15/turtlebilleder/lille_kildekode.png

Skærmbillede af shell:
http://rtgkom.dk/~jakobap15/turtlebilleder/lille_shelloutput.png

Kildekode:

import random
from random import randint
import math
import turtle

colors = ["white", "#ffc1cd", "#ffbf91", "#ff9e9e"]
hast = float(input('Animations hastighed: '))
n_skyer = int(input('Antal skyer: '))
n_strå = int(input('Antal græsstrå: '))

turtle.setup(1000, 1000)

wn = turtle.Screen()
bob = turtle.Turtle()
brian = turtle.Turtle()

bob.speed(hast)
bob.penup()
bob.hideturtle()

brian.speed(hast)
brian.penup()
brian.hideturtle()

def blad(radius):
	bob.pendown()
	#bob.color("#ffb366")
	bob.shape("triangle")
	bob.shapesize(1, 1)
	bob.begin_fill()
	bob.fillcolor("#ffb366")
	bob.circle(radius, None, 6)
	bob.end_fill()
	#skygge
	bob.begin_fill()
	bob.fillcolor("#ffa64d")
	bob.circle(radius/2+5, None, 6)
	bob.end_fill()

def nyBlad():
        bob.pendown()
        bob.color("#ffa64d")
        bob.shape("circle")
        bob.shapesize(11, 4)
        bob.stamp()
        #skygge
        bob.color("#ff9933")
        bob.shapesize(9, 3.5)
        bob.stamp()

def stilk():
        bob.up()
        bob.setpos(-400, -400)
        bob.color("#aaff80")
        bob.pensize(10)
        d = 1
        r = 0
        for i in range(12):
                r = r + 1
                bob.circle(400, r)
                if r > 6:
                        bob.down()
        #skygge
        bob.penup()
        bob.home()
        bob.setpos(-400, -405)
        bob.color("#99ff66")
        bob.pensize(5)
        d = 1
        r = 0
        for i in range(12):
                r = r + 1
                bob.circle(400, r)
                if r > 6:
                        bob.down()

def stilk_blomst(placering, side):
        bob.penup()
        bob.setpos(side, -400)
        bob.shape("circle")
        bob.shapesize(5, 2)
        bob.color("#a2ff59")
        bob.circle(400, placering)
        bob.stamp()

def sol(radius):
        brian.circle(radius)

#baggrund
def baggrund():
        wn.bgcolor("#aff0ff")
        #sol
        brian.penup()
        brian.setpos(300, 85)
        radius = 250
        move = 50
        for g in range(5):
                if g == 0:
                        brian.begin_fill()
                        brian.fillcolor("#cefcff")
                        sol(radius)
                        brian.end_fill()
                elif g == 1:
                        brian.begin_fill()
                        brian.fillcolor("#f7feff")
                        sol(radius)
                        brian.end_fill()
                elif g == 2:
                        brian.begin_fill()
                        brian.fillcolor("#fffced")
                        sol(radius)
                        brian.end_fill()
                elif g == 3:
                        brian.begin_fill()
                        brian.fillcolor("#fff7af")
                        sol(radius)
                        brian.end_fill()
                elif g == 4:
                        brian.begin_fill()
                        brian.fillcolor("#fff177")
                        sol(radius)
                        brian.end_fill()
                brian.lt(90)
                brian.forward(move)
                brian.rt(90)
                radius = radius - move
                move = move - 12
        #sky
        x = randint(-300, 400)
        y = randint(75, 250)
        brian.penup()
        brian.home()
        brian.setpos(x, y)
        brian.pendown()
        brian.lt(90)
        brian.begin_fill()
        for i in range(n_skyer):
                color = random.choice(colors)
                if brian.ycor() < y:
                        x = randint(-300, 400)
                        y = randint(75, 250)
                        brian.end_fill()
                        brian.penup()
                        brian.home()
                        brian.lt(90)
                        brian.setpos(x, y)
                        brian.pendown()
                        brian.begin_fill()
                        brian.color(color)
                while brian.ycor() >= y:
                        brian.color(color)
                        brian.circle(randint(10, 25), randint(95, 160))
                        brian.rt(randint(105, 120))
        brian.end_fill()
        #vulkan
        brian.color("grey")
        brian.shape("triangle")
        brian.penup()
        brian.home()
        brian.lt(90)
        brian.pendown()
        x = -400
        for i in range(5):
                brian.penup()
                brian.setpos(x, -100)
                brian.pendown()
                bredde = randint(10, 20)
                brian.shapesize(bredde, 5)
                brian.stamp()
                x = x + 20
        brian.penup()
        brian.home()
        #græs
        brian.color("#79ce37")
        brian.setpos(-500, -100)
        brian.pendown()
        brian.begin_fill()
        brian.fillcolor("#79ce37")
        for h in range(4):
                brian.forward(1000)
                brian.rt(90)
        brian.end_fill()

#blomster skygge
def blomst_skygge():
        bob.penup()
        bob.home()
        bob.shape("circle")
        bob.shapesize(3, 10)
        bob.color("#69b92d")
        bob.setpos(-200, -385)
        bob.pendown()
        bob.stamp()
        bob.penup()
        bob.setpos(-210, -385)
        bob.pendown()
        bob.shapesize(2.5, 9.5)
        bob.color("#79ce37")
        bob.stamp()
        bob.penup()
        bob.setpos(-210, -355)
        bob.pendown()
        bob.begin_fill()
        bob.fillcolor("#79ce37")
        bob.rt(90)
        for h in range(4):
                bob.forward(75)
                bob.rt(90)
        bob.end_fill()
        bob.lt(90)
        bob.penup()
        bob.setpos(-140, -385)
        bob.pendown()
        bob.shapesize(.4, 3)
        bob.color("#69b92d")
        bob.stamp()
        bob.penup()
        bob.setpos(-265, -410)
        bob.pendown()
        bob.shapesize(1.5, 10)
        bob.color("#69b92d")
        bob.stamp()

#antal blade
n_blad = 4

#blomsten
def blomst():
        #skygge på jorden
        blomst_skygge()
        #græsstrå
        brian.penup()
        brian.home()
        brian.pendown()
        for h in range(n_strå):
                brian.penup()
                brian.home()
                brian.pendown()
                brian.pensize(randint(3, 6))
                x = randint(-500, 500)
                y = randint(-480, -110)
                brian.penup()
                brian.setpos(x, y)
                brian.pendown()
                længde = randint(10, 15)
                brian.lt(40)
                brian.color("#69b92d")
                brian.forward(længde-3)
                brian.lt(45)
                brian.color("#9edc6f")
                brian.forward(længde)
        #stilk
        stilk()
        #ydre blade
        bob.penup()
        bob.home()
        bob.pendown()
        bob.pensize(1)
        for i in range(n_blad):
                bob.rt(45)
                nyBlad()
        #indre blade
        for i in range (n_blad):
                bob.rt(90)
                blad(40)
        bob.lt(90)
        bob.penup()
        bob.home()
        bob.pendown()
        stilk_blomst(65, -460)
        #midten
        bob.shape("circle")
        bob.shapesize(1.5, 1.5)
        bob.color("#ffdab3")
        bob.penup()
        bob.home()
        bob.stamp()

baggrund()
blomst()

wn.exitonclick()