Draw a grid

with functions

Draw a horizontal and vertical line 10px from the top and left edges.

line, width, height

background(255)

line(10, 0, 10, height())
line(width(), 10, 0, 10)

 

Modify Exercise 1 so that the horizontal and vertical lines are drawn 10 points apart. Use a for-loop. Use the width and height functions of the canvas as the termination condition.

for..., int, line, width, height

background(255)

for i in range(0, int(height()), 10): 
	line(0, i, width(), i)

for i in range(0, int(width()), 10):
	line(i, 0, i, height())

 

The solution from exercise 2 still has the problem that the grid is not redrawn when you change the size of the canvas. Therefore, change the solution from exercise 2 so that you create a draw function and call it continuously by the timer function. In the draw function you then draw the grid.
timer, for..., int, line, width, height

def draw():
	background(255)
	
	for i in range(0, int(height()), 10): 
		line(0, i, width(), i)
	
	for i in range(0, int(width()), 10):
		line(i, 0, i, height())
		
timer(draw)

 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License