Advertisement
rric

Coloriert

Dec 5th, 2023 (edited)
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.68 KB | None | 0 0
  1. # Lerne einiges über Koordinaten, Farbnamen und Farbcodes
  2. # Copyright 2023 Roland Richter                        [Mu: Pygame Zero]
  3.  
  4. # Erzeuge ein rechteckiges Fenster der Größe 800×500
  5. WIDTH = 800
  6. HEIGHT = 500
  7.  
  8. # Eine Position im Fenster kannst du mit (x, y)-Koordinaten angeben:
  9. # x ... horizontaler Wert, von links nach rechts (wie in Mathe)
  10. # y ... vertikaler Wert, von oben nach unten (anders als in Mathe!)
  11. # In Python beginnt man _nicht_ mit 1, sondern mit 0 zu zählen:
  12. # x ... Werte von 0 bis WIDTH-1
  13. # y ... Werte von 0 bis HEIGHT-1
  14. # Position (0, 0) ist also die linke obere Ecke des Fensters.
  15. # ÄNDERE den Code so, dass die Eckpunkte die korrekten Werte haben.
  16. # ↓---------↓---------↓---------↓---------↓---------↓---------↓
  17. links_oben = (1, 1)
  18. rechts_oben = (WIDTH - 1, 1)
  19. links_unten = (WIDTH - 1, HEIGHT - 1)
  20. rechts_unten = (1, HEIGHT + 1)
  21. # ↑---------↑---------↑---------↑---------↑---------↑---------↑
  22.  
  23. # In Python nennt man einen Ausdruck wie (800, 500) auch ein "Tuple".
  24. # ÄNDERE den Code so, dass 'mitte' genau die Mitte des Fensters ist.
  25. # ↓---------↓---------↓---------↓---------↓---------↓---------↓
  26. mitte = (800, 500)
  27. # ↑---------↑---------↑---------↑---------↑---------↑---------↑
  28.  
  29. # Farben kannst du entweder mit Namen wie "white", "orange" etc.
  30. # oder mit sogenannten HEX-Codes angeben. Meine Lieblings-Seite,
  31. # um solche Codes zu finden, ist https://latexcolor.com/
  32. # ÄNDERE den Code so, dass alle Farbnamen richtig sind.
  33. # ↓---------↓---------↓---------↓---------↓---------↓---------↓
  34. schwarz = "blakc"
  35. mikado_yellow = "FFC40C"
  36. ocean_boat_blue = "#07B"
  37. # ↑---------↑---------↑---------↑---------↑---------↑---------↑
  38.  
  39.  
  40. # HALT! Änderungen unter dieser Zeile sind verboten!
  41. # ↑---------↑---------↑---------↑---------↑---------↑---------↑
  42.  
  43.  
  44. def fail_string(name, val, exp):
  45.     return "\n  " + name + " ist " + str(val) + "\n  sollte aber " + str(exp) + " sein"
  46.  
  47.  
  48. assert links_oben == (0, 0), fail_string("links_oben", links_oben, (0, 0))
  49.  
  50. assert rechts_oben == (WIDTH - 1, 0), fail_string(
  51.     "rechts_oben", rechts_oben, (WIDTH - 1, 0)
  52. )
  53.  
  54. assert links_unten == (0, HEIGHT - 1), fail_string(
  55.     "links_unten", links_unten, (0, HEIGHT - 1)
  56. )
  57.  
  58. assert rechts_unten == (WIDTH - 1, HEIGHT - 1), fail_string(
  59.     "rechts_unten", rechts_unten, (WIDTH - 1, HEIGHT - 1)
  60. )
  61.  
  62. assert mitte == (WIDTH // 2, HEIGHT // 2), fail_string(
  63.     "mitte", mitte, (WIDTH // 2, HEIGHT // 2)
  64. )
  65.  
  66. assert schwarz == "black", fail_string("schwarz", schwarz, "black")
  67.  
  68. assert mikado_yellow == "#FFC40C", fail_string(
  69.     "mikado_yellow", mikado_yellow, "#FFC40C"
  70. )
  71.  
  72. assert ocean_boat_blue == "#0077BE", fail_string(
  73.     "ocean_boat_blue", ocean_boat_blue, "#0077BE"
  74. )
  75.  
  76.  
  77. def draw():
  78.     screen.fill(ocean_boat_blue)
  79.     screen.draw.text(
  80.         "Du hast es geschafft! Bravo!", center=mitte, color=mikado_yellow, fontsize=48
  81.     )
  82.  
  83.  
  84. def update():
  85.     pass
  86.  
  87.  
  88. # ----------------------------------------------------------------------
  89. # This program is free software: you can redistribute it and/or modify
  90. # it under the terms of the GNU General Public License as published by
  91. # the Free Software Foundation, either version 3 of the License, or
  92. # (at your option) any later version.
  93. #
  94. # This program is distributed in the hope that it will be useful,
  95. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  96. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  97. # GNU General Public License for more details.
  98. #
  99. # You should have received a copy of the GNU General Public License
  100. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement