commit f60ad9b9ad865761886dd531adbc14ca3441ad6a Author: AlexVeeBee Date: Wed Jan 17 10:22:52 2024 +0000 Add Projects diff --git a/files/requirements.txt b/files/requirements.txt new file mode 100644 index 0000000..e2fd32e --- /dev/null +++ b/files/requirements.txt @@ -0,0 +1 @@ +PySimpleGui \ No newline at end of file diff --git a/files/school.simple input.chalanger1.py b/files/school.simple input.chalanger1.py new file mode 100644 index 0000000..a9254dc --- /dev/null +++ b/files/school.simple input.chalanger1.py @@ -0,0 +1,7 @@ +print("Simple input and output") +name = input("What is your name? ") +age = input("How old are you? ") + +# string formatting with f-strings +# https://realpython.com/python-f-strings/ +print(f"Hello {name}, you are {age} years old") \ No newline at end of file diff --git a/files/school.turtle.chalange2.py b/files/school.turtle.chalange2.py new file mode 100644 index 0000000..8c5b250 --- /dev/null +++ b/files/school.turtle.chalange2.py @@ -0,0 +1,204 @@ +import turtle as t +import random + +import sys + +# get required modules +try: + import pip + pip.main(['install', 'PySimpleGUI']) +except Exception as e: + print("Pip not found") + print(e) + sys.exit(1) + + +import PySimpleGUI as sg + +terminal_colors = { + "RESET": "\033[0m", + "RED": "\033[1;31;40m", + "GREEN": "\033[1;32;40m", +} + +stars = [ + { + "rotation": 0, + "color": "red", + }, + { + "rotation": 36, + "color": "blue", + }, + { + "rotation": 36, + "color": "green", + }, + { + "rotation": 36, + "color": "yellow", + }, + { + "rotation": 36, + "color": "purple", + }, + { + "rotation": 36, + "color": "pink", + }, + { + "rotation": 36, + "color": "orange", + }, + { + "rotation": 36, + "color": "black", + }, + { + "rotation": 36, + "color": "white", + }, + { + "rotation": 36, + "color": "grey", + }, + { + "rotation": 36, + "color": "brown", + } +] + +firstMessages = [ + "YOU", + "ARE", +] + +def main(skipoptions): + skips = { + "star": False, + "spiral": False, + } + + if skipoptions: + skips = skipoptions + + # create a star + t.setup(800, 600) + t.begin_fill() + t.speed(1) + t.penup() + + if not skips["star"]: + t.goto(0, 300) + t.pendown() + + for message in firstMessages: + # add delay + t.speed(1) + # align center top + t.write(message, align='center', font=('Arial', 48, 'normal')) + t.penup() + t.goto(0, t.ycor() - 50) + t.pendown() + t.speed(10) + t.penup() + t.goto(0, 0) + + t.speed(30) + # go trough the stars + for star in stars: + t.penup() + t.goto(0, 0) + t.pendown() + t.right(star["rotation"]) + t.color(star["color"], star["color"]) + t.begin_fill() + for i in range(5): + t.forward(200) + t.right(144) + t.end_fill() + t.penup() + t.goto(0, -300) + t.pendown() + t.color('black') + # t.write('You are NOT a star', align='center', font=('Arial', 48, 'normal')) + # switch trough texts + meessages = [ + "NOT", + "A", + "STAR" + ] + + for message in meessages: + # add delay + t.speed(1) + t.write(message, align='center', font=('Arial', 48, 'normal')) + t.penup() + t.goto(0, t.ycor() - 50) + t.pendown() + + # change background color + # clear the screen + + if not skips["spiral"]: + t.clear() + # creat a spiral + t.speed(10) + t.penup() + t.goto(0, 0) + t.pendown() + t.color('black') + t.speed(30) + rangeset = 1500 + for i in range(rangeset): + # random color + color = random.randint(0, 0xFFFFFF) + print(f"color: {color}") + t.color("#%06x" % color) + # t.color(1 - i / rangeset, 1 - i / rangeset, 1 - i / rangeset) + t.speed(100) + t.forward(i) + t.right(144) + t.penup() + + t.done() + + + + pass + +def setupui(): + opts = { + "star": False, + "spiral": False, + } + + layout = [ + [sg.Checkbox('Skip Star', default=False, key='skipstar')], + [sg.Checkbox('Skip Spiral', default=False, key='skipspiral')], + [sg.Button('Ok')] + ] + + window = sg.Window('Skip Options', layout) + + while True: + event, values = window.read() + if event in (None, 'Cancel'): + break + if event == 'Ok': + opts["star"] = values['skipstar'] + opts["spiral"] = values['skipspiral'] + break + + window.close() + return opts + +if __name__ == '__main__': + skipoptions = setupui() + print(skipoptions) + try: + main(skipoptions) + except Exception as e: + print(f"{terminal_colors['RED']}[ERROR]{terminal_colors['RESET']}") + print(e) + pass \ No newline at end of file