rric

Processing_03_Iteration

Oct 25th, 2021
719
135 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Shows how to draw many shapes in one go
  2. # Copyright 2021 Roland Richter
  3.  
  4. # Creates a canvas with "Dark midnight blue" background
  5. size(600, 450)
  6. background("#003366")
  7.  
  8. # Sets drawing and text attributes for this sketch
  9. noStroke()
  10. textSize(16)
  11. textAlign(CENTER, CENTER)
  12.      
  13. # --- Line 1 ---
  14.  
  15. horizontal = [50, 140, 230, 320, 410, 500]
  16.  
  17. for x in horizontal:
  18.     y = 0.1 * height
  19.     fill("#FFCC33")     # "Sunglow"
  20.     circle(x, y, 80)
  21.     fill("#2F4F4F")     # "Dark slate gray"
  22.     text("x=" + nf(x), x, 0.1 * height)
  23.     # QUIZ nf() formats numbers into string.
  24.     #       What happens if you skip nf() here, i.e. write
  25.     # text("x=" + x, x, 0.1 * height)
  26.  
  27. # --- Line 2 ---
  28.  
  29. # QUIZ What do the numbers 70, 600, and 90 stand for?
  30. for x in range(70, 600, 90):
  31.     y = 0.3 * height
  32.     fill("#F28500")     # "Tangerine"
  33.     circle(x, y, 80)
  34.     fill("#2F4F4F")     # "Dark slate gray"
  35.     text("x=" + nf(x), x, 0.3 * height)
  36.  
  37. # --- Line 3 ---
  38.  
  39. for slider in range(0, 100, 20):
  40.     # HINT lerp(60, 480, 0.0) -> 60
  41.     #      lerp(60, 480, 0.5) -> 270 (mean of 60 and 480)
  42.     #      lerp(60, 480, 1.0) -> 480
  43.     #      etc.
  44.     #      Think of a slider going from 0 to 100 %
  45.     x = lerp(60, 480, slider/100.0)
  46.     y = lerp(0.5 * height, 0.6 * height, slider/100.0)
  47.     fill("#FF4500")     # "Orange-red"
  48.     circle(x, y, 80)
  49.     fill("#2F4F4F")     # "Dark slate gray"
  50.     text("slider=" + nf(slider), x, y)
  51.  
  52. # --- Line 4 ---
  53.  
  54. # QUIZ Why did I wrote "10" here instead of "0" ?
  55. for slider in range(10, 100, 20):
  56.     x = lerp(140, 540, slider/100.0)
  57.     y = lerp(0.9 * height, 0.75 * height, slider/100.0)
  58.    
  59.     # QUIZ What do you think "dia" and "col" stand for? Why?
  60.     dia = lerp(80, 130, slider/100.0)
  61.     col = lerpColor("#FF0800", "#8B0000", slider/100.0)
  62.    
  63.     fill(col)           # "Candy apple red" -> "Dark red"
  64.     circle(x, y, dia)
  65.     fill("#778899")     # "Light slate gray"
  66.     text("slider=" + nf(slider), x, y)
  67.  
  68. # ----------------------------------------------------------------------
  69. # This program is free software: you can redistribute it and/or modify
  70. # it under the terms of the GNU General Public License as published by
  71. # the Free Software Foundation, either version 3 of the License, or
  72. # (at your option) any later version.
  73. #
  74. # This program is distributed in the hope that it will be useful,
  75. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  76. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  77. # GNU General Public License for more details.
  78. #
  79. # You should have received a copy of the GNU General Public License
  80. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
RAW Paste Data