Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Draws movements of a flying bird, reminiscent of paintings
- # by Erika G. Klien (1900--1957), who was one of the leading
- # proponents of Viennese Kineticism:
- # https://sammlung.belvedere.at/people/1059/erika-giovanna-klien
- # Copyright 2023 Roland Richter
- from __future__ import division, print_function
- # setup() is called only once, at start-up
- def setup():
- size(800, 500)
- background("#87CEEB") # Light sky blue
- # The birds position: let it start at the upper right edge;
- # birdx and birdy are global variables, since they are used
- # in this function, setup(), and in another function, draw().
- global birdx, birdy
- birdx = width - 40
- birdy = 0
- frameRate(8)
- # draw() is called about 60 times/sec by default; but ...
- # QUIZ Why is the frame rate only about 8 frames per second?
- def draw():
- # If (and only if) the left mouse button is pressed, the
- # canvas is erased each time, resulting in a "flip book" effect.
- if mousePressed:
- background("#87CEEB") # Light sky blue
- # TRY to reverse the logic above: if the left mouse button is pressed,
- # the sketch should *not* re-paint the background, and vice versa
- # Paint the seascape: a green island, and the sea
- stroke("#483C32") # "Dark lava"
- fill("#087830") # "La Salle Green"
- circle(0.5*width, height, 0.6*height)
- noStroke()
- fill("#08457E") # "Dark cerulean"
- rect(0, 0.8*height, width, height)
- # Draw the sun
- fill("#FFFF00") # Yellow
- circle(0.1*width, 0.2*height, 90)
- # Compute the new position of the bird, ...
- global birdx, birdy
- birdx -= 5 # short for "subtract 5 from birdx"
- birdy += 2 # short for "add 2 to birdy"
- # TRY to let the bird fly from the upper left to the lower right!
- # ... then draw the bird at its current position
- stroke("#000000") # Black
- fill("#F3E5AB") # Medium champagne
- # Test whether frameCount is even or odd, then draw the corresponding
- # bird. In this way, the sketch constantly switches back and forth
- # between the two variants.
- if frameCount % 2 == 0:
- triangle(birdx, birdy, birdx-70, birdy-18, birdx-55, birdy-5)
- triangle(birdx, birdy, birdx+70, birdy-18, birdx+55, birdy-5)
- else:
- triangle(birdx, birdy, birdx-70, birdy-5, birdx-55, birdy+8)
- triangle(birdx, birdy, birdx+70, birdy-5, birdx+55, birdy+8)
- # TRY adding more birds, or other moving objects
- # TRY adding a lighthouse with a light that flashes like
- # on-off-off-off, on-off-off-off, ...
- # ----------------------------------------------------------------------
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement