Advertisement
rric

fly_my_bird

Oct 23rd, 2023 (edited)
650
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.35 KB | None | 0 0
  1. # Draws movements of a flying bird, reminiscent of paintings
  2. # by Erika G. Klien (1900--1957), who was one of the leading
  3. # proponents of Viennese Kineticism:
  4. # https://sammlung.belvedere.at/people/1059/erika-giovanna-klien
  5. # Copyright 2023 Roland Richter
  6.  
  7. from __future__ import division, print_function
  8.  
  9. # setup() is called only once, at start-up
  10. def setup():
  11.     size(800, 500)
  12.     background("#87CEEB")   # Light sky blue
  13.    
  14.     # The birds position: let it start at the upper right edge;
  15.     # birdx and birdy are global variables, since they are used
  16.     # in this function, setup(), and in another function, draw().
  17.     global birdx, birdy
  18.     birdx = width - 40
  19.     birdy = 0
  20.  
  21.     frameRate(8)
  22.  
  23.  
  24. # draw() is called about 60 times/sec by default; but ...
  25. # QUIZ Why is the frame rate only about 8 frames per second?
  26. def draw():
  27.     # If (and only if) the left mouse button is pressed, the
  28.     # canvas is erased each time, resulting in a "flip book" effect.
  29.     if mousePressed:
  30.         background("#87CEEB")   # Light sky blue
  31.        
  32.     # TRY to reverse the logic above: if the left mouse button is pressed,
  33.     #     the sketch should *not* re-paint the background, and vice versa        
  34.        
  35.     # Paint the seascape: a green island, and the sea
  36.     stroke("#483C32")  # "Dark lava"
  37.     fill("#087830")    # "La Salle Green"
  38.     circle(0.5*width, height, 0.6*height)
  39.  
  40.     noStroke()
  41.     fill("#08457E") # "Dark cerulean"
  42.     rect(0, 0.8*height, width, height)
  43.  
  44.     # Draw the sun
  45.     fill("#FFFF00")  # Yellow
  46.     circle(0.1*width, 0.2*height, 90)
  47.        
  48.     # Compute the new position of the bird, ...
  49.     global birdx, birdy
  50.     birdx -= 5   # short for "subtract 5 from birdx"
  51.     birdy += 2   # short for "add 2 to birdy"
  52.  
  53.     # TRY to let the bird fly from the upper left to the lower right!
  54.    
  55.     # ... then draw the bird at its current position
  56.     stroke("#000000")   # Black
  57.     fill("#F3E5AB")     # Medium champagne
  58.    
  59.     # Test whether frameCount is even or odd, then draw the corresponding
  60.     # bird. In this way, the sketch constantly switches back and forth
  61.     # between the two variants.
  62.     if frameCount % 2 == 0:
  63.         triangle(birdx, birdy, birdx-70, birdy-18, birdx-55, birdy-5)
  64.         triangle(birdx, birdy, birdx+70, birdy-18, birdx+55, birdy-5)
  65.     else:
  66.         triangle(birdx, birdy, birdx-70, birdy-5, birdx-55, birdy+8)
  67.         triangle(birdx, birdy, birdx+70, birdy-5, birdx+55, birdy+8)
  68.    
  69.     # TRY adding more birds, or other moving objects
  70.    
  71.     # TRY adding a lighthouse with a light that flashes like
  72.     #     on-off-off-off, on-off-off-off, ...
  73.  
  74.    
  75. # ----------------------------------------------------------------------
  76. # This program is free software: you can redistribute it and/or modify
  77. # it under the terms of the GNU General Public License as published by
  78. # the Free Software Foundation, either version 3 of the License, or
  79. # (at your option) any later version.
  80. #
  81. # This program is distributed in the hope that it will be useful,
  82. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  83. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  84. # GNU General Public License for more details.
  85. #
  86. # You should have received a copy of the GNU General Public License
  87. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  88.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement