rric

loop_3

Nov 13th, 2023 (edited)
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.47 KB | None | 0 0
  1. # Draw a grid of lines, parametrized with step size and offset shift.
  2. # Copyright 2023 Roland Richter                          [Processing.py]
  3.  
  4. from __future__ import division, print_function
  5.  
  6. def setup():
  7.     size(800, 560)
  8.  
  9.  
  10. def draw():
  11.     background("#0F0F0F")
  12.  
  13.     draw_vertical_lines()
  14.     # TRY to pass different arguments to the function, such as
  15.     # draw_vertical_lines(55, 12)
  16.     # draw_vertical_lines(offset = 18)
  17.    
  18.     # TRY to use a variable, e.g. frameCount or mouseX/Y, to animate the grid
  19.     draw_horizontal_lines()
  20.  
  21.  
  22. def draw_vertical_lines(step = 40, offset = 0):
  23.     """Draw vertical grey lines, `step` pixels apart, starting at `offset`.
  24.    
  25.    Arguments:
  26.    step -- vertical lines are drawn every `step` pixels (default: 40)
  27.    offset -- vertical lines start at x coordinate `offset` (default: 0)
  28.    """
  29.     stroke(92)
  30.     fill(192)
  31.     textSize(12)
  32.     textAlign(CENTER, CENTER)
  33.    
  34.     # Draw vertical lines, and place a label at the top of each line
  35.     for x in range(offset, width+1, step):  
  36.         line(x, 0, x, height)
  37.         label = nf(x, 3)
  38.         text(label, x, 12)
  39.    
  40.    
  41. def draw_horizontal_lines(step = 40, offset = 0):
  42.     """Draw horizontal grey lines, `step` pixels apart, starting at `offset`.
  43.    
  44.    Arguments:
  45.    step -- horizontal lines are drawn every `step` pixels (default: 40)
  46.    offset -- horizontal lines start at y coordinate `offset` (default: 0)
  47.    """
  48.     stroke(92)
  49.     fill(192)
  50.     textSize(12)
  51.     textAlign(CENTER, CENTER)
  52.    
  53.     # Draw horizontal lines, and place a label at the left of each line
  54.     # TRY to implement this function in a similar way as above
  55.     for y in range(0):  
  56.         line(0, 1, 2, 3)
  57.         label = ""
  58.         text(label, 4, 5)    
  59.  
  60.  
  61. # ----------------------------------------------------------------------
  62. # This program is free software: you can redistribute it and/or modify
  63. # it under the terms of the GNU General Public License as published by
  64. # the Free Software Foundation, either version 3 of the License, or
  65. # (at your option) any later version.
  66. #
  67. # This program is distributed in the hope that it will be useful,
  68. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  69. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  70. # GNU General Public License for more details.
  71. #
  72. # You should have received a copy of the GNU General Public License
  73. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  74.    
Advertisement
Add Comment
Please, Sign In to add comment