Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Sunset animation reminiscent of "Carla's Island", which was
- # a pioneering computer animation created by Nelson Max in 1981,
- # see e.g. https://archive.org/details/CarlasIsland;
- # here, using an SVG shape and a JPG image
- # Copyright 2021--2023 Roland Richter
- from __future__ import division, print_function
- # setup() is called only once, at start-up
- def setup():
- size(800, 500)
- global skyc
- skyc = color(135, 206, 235) # "Light sky blue"
- # The sun's position: let it start somewhere at the upper right edge
- global sunx, suny
- sunx = width - random(0.4*width)
- suny = 0
- # Load SVG shape and JPG image to draw sun and sea:
- # Vintage Smiling Sun by j4p4n used under CC0 (public domain)
- # https://openclipart.org/detail/332968/vintage-smiling-sun
- global sun
- sun = loadShape("anthropomorphicsun-colour.svg")
- shapeMode(CENTER)
- # Lavaküste by Maria Klingler used under CC BY-NC-SA 3.0 AT
- # https://bilder.tibs.at/node/42099
- global sea
- sea = loadImage("bilder-tibs-at-42099_cropped.jpg")
- imageMode(CORNER)
- # TRY What happens if you modify the frame rate?
- # What if you comment out the next line?
- # frameRate(8)
- # draw() is called about 60 times/sec by default
- def draw():
- global skyc
- background(skyc)
- # Compute the new sun position by adding deltas
- global sunx, suny
- sunx -= 1
- suny += 2
- # Draw the sun shape at the current position
- shape(sun, sunx, suny, 60, 60)
- # Draw the ocean
- noStroke()
- fill("#08457E") # "Dark cerulean"
- rect(0, 0.8*height, width, height)
- # TRY to display the image here -- what do you notice?
- # image(sea, 0, 0.6*height, width, 0.4*height)
- # Think of a progress bar moving from 0.0 (frame 0) to 1.0 (frame 299); ...
- progress = (frameCount % 300) / 299.0
- # ... the color of the sky is changing accordingly from "Light sky blue"
- # to black:
- skyc = lerpColor(color(135, 206, 235), color(0, 0, 0), progress)
- # Display the current frame rate, ...
- textSize(28)
- fill("#FFFFFF")
- textAlign(LEFT)
- text(nf(frameRate, 1, 1) + " fps", 10, 25)
- # ... plus some further information
- textAlign(RIGHT)
- text(nf(frameCount) + " mod 300 = " + nf(frameCount % 300), width-10, 25)
- text("color factor = " + nf(progress, 1, 2), width-10, 55)
- # Reset the sun position after 300 frames, i.e. ~ 5 secs
- if frameCount % 300 == 0:
- global sunx, suny
- sunx = width - random(0.4*width)
- suny = 0
- # Each time saveFrame() is executed here, a snapshot of the canvas
- # is saved, with file names being a numbered sequence in a folder.
- # Use the Movie Maker tool afterwards to generate a MPEG-4 video,
- # or an animated GIF.
- # saveFrame("sunset/####.jpg")
- # ----------------------------------------------------------------------
- # 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