Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Draw a grid of lines, parametrized with step size and offset shift.
- # Copyright 2023 Roland Richter [Processing.py]
- from __future__ import division, print_function
- def setup():
- size(800, 560)
- def draw():
- background("#0F0F0F")
- draw_vertical_lines()
- # TRY to pass different arguments to the function, such as
- # draw_vertical_lines(55, 12)
- # draw_vertical_lines(offset = 18)
- # TRY to use a variable, e.g. frameCount or mouseX/Y, to animate the grid
- draw_horizontal_lines()
- def draw_vertical_lines(step = 40, offset = 0):
- """Draw vertical grey lines, `step` pixels apart, starting at `offset`.
- Arguments:
- step -- vertical lines are drawn every `step` pixels (default: 40)
- offset -- vertical lines start at x coordinate `offset` (default: 0)
- """
- stroke(92)
- fill(192)
- textSize(12)
- textAlign(CENTER, CENTER)
- # Draw vertical lines, and place a label at the top of each line
- for x in range(offset, width+1, step):
- line(x, 0, x, height)
- label = nf(x, 3)
- text(label, x, 12)
- def draw_horizontal_lines(step = 40, offset = 0):
- """Draw horizontal grey lines, `step` pixels apart, starting at `offset`.
- Arguments:
- step -- horizontal lines are drawn every `step` pixels (default: 40)
- offset -- horizontal lines start at y coordinate `offset` (default: 0)
- """
- stroke(92)
- fill(192)
- textSize(12)
- textAlign(CENTER, CENTER)
- # Draw horizontal lines, and place a label at the left of each line
- # TRY to implement this function in a similar way as above
- for y in range(0):
- line(0, 1, 2, 3)
- label = ""
- text(label, 4, 5)
- # ----------------------------------------------------------------------
- # 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