Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Draw a rectangular grid, and display a short description of Processing
- # Copyright 2022, 2023 Roland Richter [Processing.py]
- # This sketch shows you how to ...
- # - [ ] draw a rectangular grid with two nested for loops
- def setup():
- # Create a 900×600 canvas (plus a small margin) with black background
- size(904, 604)
- ellipseMode(CENTER)
- def draw():
- background(0)
- # This sentence is taken from https://py.processing.org/
- words = ["Since", "2001", "Processing", "has", "promoted", "software",
- "literacy", "within", "the", "visual", "arts", "and",
- "visual", "literacy", "within", "technology"]
- # Set coordinates of the circles' centers (x and y separately)
- # TRY to use list comprehension to compute these numbers;
- # best with the help of the width and height variables.
- cxs = [112, 112+225, 112+2*225, 112+3*225]
- cys = [75, 75+150, 75+2*150, 75+3*150]
- # TRY to reverse y coordinates, or both x and y coordinates.
- # TRY to "reverse" the text as well: "Since" -> "ecniS", "2001" -> "1002", ...
- if mousePressed and mouseButton == LEFT:
- cxs.reverse()
- # Draw circles with white lines and black interior
- strokeWeight(4)
- stroke(255)
- fill(0)
- # First draw 4 × 4 circles, ...
- for cx in cxs:
- for cy in cys:
- circle(cx, cy, 215)
- # ... (just for fun, add a little offset to the word positions) ...
- off = 8.0 * sin(radians(4*frameCount))
- # ... then place one word within each circle.
- textSize(36)
- textAlign(CENTER, CENTER)
- fill(255)
- i = 0
- for cy in cys:
- for cx in cxs:
- sign = +1 if i % 2 == 0 else -1
- text(words[i], cx, cy + sign*off)
- i += 1
- # ----------------------------------------------------------------------
- # 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