Advertisement
rric

graph_till_dusk

Oct 23rd, 2023 (edited)
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.59 KB | None | 0 0
  1. # Sunset animation reminiscent of "Carla's Island", which was
  2. # a pioneering computer animation created by Nelson Max in 1981,
  3. # see e.g. https://archive.org/details/CarlasIsland;
  4. # here, using an SVG shape and a JPG image
  5. # Copyright 2021--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.    
  13.     global skyc
  14.     skyc = color(135, 206, 235) # "Light sky blue"
  15.  
  16.     # The sun's position: let it start somewhere at the upper right edge
  17.     global sunx, suny
  18.     sunx = width - random(0.4*width)
  19.     suny = 0
  20.    
  21.     # Load SVG shape and JPG image to draw sun and sea:
  22.    
  23.     # Vintage Smiling Sun by j4p4n used under CC0 (public domain)
  24.     # https://openclipart.org/detail/332968/vintage-smiling-sun
  25.     global sun
  26.     sun = loadShape("anthropomorphicsun-colour.svg")
  27.     shapeMode(CENTER)
  28.    
  29.     # Lavaküste by Maria Klingler used under CC BY-NC-SA 3.0 AT
  30.     # https://bilder.tibs.at/node/42099
  31.     global sea
  32.     sea = loadImage("bilder-tibs-at-42099_cropped.jpg")
  33.     imageMode(CORNER)
  34.    
  35.     # TRY What happens if you modify the frame rate?
  36.     #     What if you comment out the next line?
  37.     # frameRate(8)
  38.  
  39.  
  40. # draw() is called about 60 times/sec by default
  41. def draw():
  42.     global skyc
  43.     background(skyc)
  44.  
  45.     # Compute the new sun position by adding deltas
  46.     global sunx, suny
  47.     sunx -= 1
  48.     suny += 2
  49.    
  50.     # Draw the sun shape at the current position
  51.     shape(sun, sunx, suny, 60, 60)
  52.  
  53.     # Draw the ocean
  54.     noStroke()
  55.     fill("#08457E") # "Dark cerulean"
  56.     rect(0, 0.8*height, width, height)
  57.    
  58.     # TRY to display the image here -- what do you notice?
  59.     # image(sea, 0, 0.6*height, width, 0.4*height)
  60.    
  61.     # Think of a progress bar moving from 0.0 (frame 0) to 1.0 (frame 299); ...
  62.     progress = (frameCount % 300) / 299.0
  63.    
  64.     # ... the color of the sky is changing accordingly from "Light sky blue"
  65.     # to black:
  66.     skyc = lerpColor(color(135, 206, 235), color(0, 0, 0), progress)
  67.    
  68.     # Display the current frame rate, ...
  69.     textSize(28)
  70.     fill("#FFFFFF")
  71.     textAlign(LEFT)
  72.     text(nf(frameRate, 1, 1) + " fps", 10, 25)
  73.    
  74.     # ... plus some further information
  75.     textAlign(RIGHT)
  76.     text(nf(frameCount) + " mod 300 = " + nf(frameCount % 300), width-10, 25)
  77.     text("color factor = " + nf(progress, 1, 2), width-10, 55)
  78.    
  79.     # Reset the sun position after 300 frames, i.e. ~ 5 secs
  80.     if frameCount % 300 == 0:
  81.         global sunx, suny
  82.         sunx = width - random(0.4*width)
  83.         suny = 0
  84.        
  85.     # Each time saveFrame() is executed here, a snapshot of the canvas
  86.     # is saved, with file names being a numbered sequence in a folder.
  87.     # Use the Movie Maker tool afterwards to generate a MPEG-4 video,
  88.     # or an animated GIF.
  89.     # saveFrame("sunset/####.jpg")
  90.  
  91.  
  92. # ----------------------------------------------------------------------
  93. # This program is free software: you can redistribute it and/or modify
  94. # it under the terms of the GNU General Public License as published by
  95. # the Free Software Foundation, either version 3 of the License, or
  96. # (at your option) any later version.
  97. #
  98. # This program is distributed in the hope that it will be useful,
  99. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  100. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  101. # GNU General Public License for more details.
  102. #
  103. # You should have received a copy of the GNU General Public License
  104. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  105.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement