rric

loop_2

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