Continuous lines

with functions

Draw 200 lines on the canvas. Find x and y coordinates using the random function. The maximum value for the x-coordinate is Width and for the y-coordinate Height. Set the width of the stroke to 3 and the color to 128.

double, int, for..., Random, Background, Line, Stroke, StrokeWeight

Background(255);

StrokeWeight(3);
Stroke(128);

for(int i = 0; i < 200; i++)
{
	double x1 = Random(0, Width);
	double y1 = Random(0, Height);
	double x2 = Random(0, Width);
	double y2 = Random(0, Height);

	Line(x1, y1, x2, y2);
}

 

Change Exercise 1 so that the end of the line is the beginning of the next line, resulting in a continuous line.

double, int, for..., Random, Background, Line, Stroke, StrokeWeight

Background(255);

StrokeWeight(3);
Stroke(128);

double x1 = Random(0, Width);
double y1 = Random(0, Height);

for(int i = 0; i < 80; i++)
{
	double x2 = Random(0, Width);
	double y2 = Random(0, Height);

	Line(x1, y1, x2, y2);
	
	x1 = x2;
	y1 = y2;
}

 

Change exercise 2 so that it doesn't use a for-loop. Instead, you set the Timer variable to a draw function and draw a single line with each call.
double, int, void, Timer, Random, Background, Line, Stroke, StrokeWeight

Background(255);

StrokeWeight(3);
Stroke(128);

double x1 = Random(0, Width);
double y1 = Random(0, Height);

Timer = Draw;

void Draw()
{
	double x2 = Random(0, Width);
	double y2 = Random(0, Height);

	Line(x1, y1, x2, y2);
	
	x1 = x2;
	y1 = y2;
}

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