Skip to content

Instantly share code, notes, and snippets.

@RandomGuy3015
Created October 7, 2021 14:07
Show Gist options
  • Save RandomGuy3015/b42f07742046763438a1c56c49240c4d to your computer and use it in GitHub Desktop.
Save RandomGuy3015/b42f07742046763438a1c56c49240c4d to your computer and use it in GitHub Desktop.
Python random sketcher
z1 = 750
z2 = 500
ai = [z1,z2]
ai2 = [z1,z2]
a = [10,10,10]
a2 = [10,10,10]
def setup():
size(1000,1000)
background(0)
stroke(a[0],a[1],a[2])
def randomSketch1():
global ai
global a
x = int(random(-2,2))*16 # randomly selects a new direction for the walker to move to
y = int(random(-2,2))*16
x1 = ai[len(ai)-2]+x
y1 = ai[len(ai)-1]+y
if x1 < 0 or x1 > width or x1 < 0 or x1 > height: # checks if the walker hits an edge
a[int(random(-1,3))] += 30 # changes the color
ai = [z1,z1]
x1 = z1
y1 = z1
else:
if x1 < 0:
x1 = 0
if x1 > width:
x1 = width
if y1 < 0:
y1 = 0
if y1 > height:
y1 = height
stroke(a[0],a[1],a[2])
line(ai[len(ai)-2],ai[len(ai)-1],x1,y1) # draws the line
ai.append(x1)
ai.append(y1)
def randomSketch2():
global ai2
global a2
x = int(random(-2,2))*16
y = int(random(-2,2))*16
x1 = ai2[len(ai2)-2]+x
y1 = ai2[len(ai2)-1]+y
if x1 < 0 or x1 > width or x1 < 0 or x1 > height:
a2[int(random(-1,3))] += 30
ai2 = [z2,z2]
x1 = z2
y1 = z2
else:
if x1 < 0:
x1 = 0
if x1 > width:
x1 = width
if y1 < 0:
y1 = 0
if y1 > height:
y1 = height
stroke(a2[0],a2[1],a2[2])
line(ai2[len(ai2)-2],ai2[len(ai2)-1],x1,y1)
ai2.append(x1)
ai2.append(y1)
def draw():
if a[0] >= 250 or a[1] > 250 or a[2] > 250: # resets the color to black if it hits white
a[0] = 0
a[1] = 0
a[2] = 0
if a2[0] >= 250 or a2[1] > 250 or a2[2] > 250:
a2[0] = 0
a2[1] = 0
a2[2] = 0
randomSketch1()
randomSketch2()
print(a[0],a[1],a[2]," ",a2[0],a2[1],a2[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment