From 083dccaa59be0c300ee621b15f5dbe03b2073b96 Mon Sep 17 00:00:00 2001 From: helenehmoe Date: Wed, 2 Nov 2022 15:54:58 +0100 Subject: [PATCH] Add files via upload --- forrest.py | 46 +++++++++++++++++++++ main.py | 1 + multiple_colored_shapes.py | 85 ++++++++++++++++++++++++++++++++++++++ stjerne.py | 31 ++++++++++++++ weird_circle.py | 21 ++++++++++ 5 files changed, 184 insertions(+) create mode 100644 forrest.py create mode 100644 main.py create mode 100644 multiple_colored_shapes.py create mode 100644 stjerne.py create mode 100644 weird_circle.py diff --git a/forrest.py b/forrest.py new file mode 100644 index 0000000..91714f9 --- /dev/null +++ b/forrest.py @@ -0,0 +1,46 @@ +from turtle import * +from random import * + +ts = Screen() +ts.screensize(canvwidth=595, canvheight=842, bg="light blue") + +t1 = Turtle() +t2 = Turtle() +t3 = Turtle() +t4 = Turtle() + +turtles = [t1, t2, t3, t4] + + +def branch(t, branch_length): + angle = randint(22, 30) + sf = uniform(0.6, 0.8) + size = int(branch_length / 10) + t.pensize(size) + if branch_length < 20: + t.color('green') + t.stamp() + t.color('brown') + if branch_length > 10: + t.forward(branch_length) + t.left(angle) + branch(t, branch_length * sf) + t.right(angle * 2) + branch(t, branch_length * sf) + t.left(angle) + t.backward(branch_length) + + +x = -300 + +for t in turtles: + t.speed(1000) + t.left(90) + t.color('brown') + t.pu() + x += randint(80, 160) + t.goto(x, randint(-100, 100)) + t.pd() + branch(t, 100) + +ts.getcanvas().postscript(file="tree.eps", height=842, width=595) diff --git a/main.py b/main.py new file mode 100644 index 0000000..825062a --- /dev/null +++ b/main.py @@ -0,0 +1 @@ +import forrest \ No newline at end of file diff --git a/multiple_colored_shapes.py b/multiple_colored_shapes.py new file mode 100644 index 0000000..b9291d4 --- /dev/null +++ b/multiple_colored_shapes.py @@ -0,0 +1,85 @@ +#https://pythonforfun.in/2021/02/03/five_shapes-polygons-and-a-star-sort-of/ +import turtle +import random + +wn = turtle.Screen() +wn.bgcolor("black") +astroid = turtle.Turtle() +astroid.speed(0) +triad = turtle.Turtle() +triad.speed(0) +triad.up() +triad.goto(-120, 120) +triad.down() +squad = turtle.Turtle() +squad.speed(0) +squad.up() +squad.goto(120, 120) +squad.down() +pentago = turtle.Turtle() +pentago.speed(0) +pentago.up() +pentago.goto(-120, -120) +pentago.down() +octago = turtle.Turtle() +octago.speed(0) +octago.up() +octago.goto(120, -120) +octago.down() +colors = ["red", "gold", "blue", "green", "white", "cyan", "pink"] + +for i in range(50): + triad.color(random.choice(colors)) + triad.forward(i * 3) + triad.left(120) + +for i in range(50): + squad.color(random.choice(colors)) + squad.forward(i * 2) + squad.left(90) + +for i in range(50): + pentago.color(random.choice(colors)) + pentago.forward(i * 2) + pentago.left(72) + +for i in range(75): + octago.color(random.choice(colors)) + octago.forward(i) + octago.left(60) + +for i in range(50): + astroid.color(random.choice(colors)) + astroid.forward(i * 3) + astroid.left(144) + +triad.up() +triad.goto(-110, 200) +triad.down() +triad.write("Triad") +triad.hideturtle() + +squad.up() +squad.goto(120, 180) +squad.down() +squad.write("Squad") +squad.hideturtle() + +pentago.up() +pentago.goto(-140, -20) +pentago.write("Pentago") +pentago.hideturtle() + +octago.up() +octago.goto(120, -40) +octago.down() +octago.write("Hex") +octago.hideturtle() + +astroid.up() +astroid.goto(0, 60) +astroid.down() +astroid.write("Astroid") +astroid.hideturtle() + +turtle.done() \ No newline at end of file diff --git a/stjerne.py b/stjerne.py new file mode 100644 index 0000000..de2b9d7 --- /dev/null +++ b/stjerne.py @@ -0,0 +1,31 @@ +from turtle import * + +speed(100) + +color('red', 'yellow') + +t1 = Turtle() +t2 = Turtle() +t3 = Turtle() +t4 = Turtle() + +turtles = [t1, t2, t3, t4] + +for t in turtles: + star(t) + + +def star(turt): + + begin_fill() + while True: + turt.forward(200) + turt.left(170) + if abs(pos()) < 1: + break + end_fill() + + +star() + +done() diff --git a/weird_circle.py b/weird_circle.py new file mode 100644 index 0000000..f3a136d --- /dev/null +++ b/weird_circle.py @@ -0,0 +1,21 @@ +import turtle + +t = turtle.Turtle() + +t.speed(100) + +for i in range(180): + t.forward(100) + t.right(30) + t.forward(20) + t.left(60) + t.forward(50) + t.right(30) + + t.penup() + t.setposition(0, 0) + t.pendown() + + t.right(2) + +t.done() \ No newline at end of file