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 variables of the canvas as the termination condition.

for..., int, Line, Width, Height

Background(255);

for(int i = 0; i < Height; i = i + 10) 
	Line(0, i, Width, i); 

for(int i = 0; i < Width; i = i + 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 assign a Draw function to the Timer variable. In the Draw function you then draw the grid.
Timer, void, for..., int, Line, Width, Height

Timer = Draw;

void Draw() 
{
	Background(255);
	
	for(int i = 0; i < Height; i = i + 10) 
		Line(0, i, Width, i); 

	for(int i = 0; i < Width; i = i + 10) 
		Line(i, 0, i, Height);
}

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