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.

for..., random, background, line, stroke, strokeWeight

background(255)

strokeWeight(3)
stroke(128)

for i in range(0, 200):
	x1 = random(0, width())
	y1 = random(0, height())
	x2 = random(0, width())
	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.

for..., random, background, line, stroke, strokeWeight

background(255)

strokeWeight(3)
stroke(128)

x1 = random(0, width())
y1 = random(0, height())

for i in range(0, 80):
	x2 = random(0, width())
	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 use the timer function to set a draw function and draw a single line with each call.
timer, random, background, line, stroke, strokeWeight

background(255)

strokeWeight(3)
stroke(128)

x1 = random(0, width())
y1 = random(0, height())

def draw():
	global x1, y1
	x2 = random(0, width())
	y2 = random(0, height())

	line(x1, y1, x2, y2)
	
	x1 = x2
	y1 = y2
	
timer(draw)

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