Hi, I’m trying to have different bits of code inside draw() run continuously but be activated by different key presses.
The problem is that what is inside the if else statement only runs while I am pressing the key.
What I’d like is to be able to do, in general, but I’m having trouble implementing it in Processing, is to switch to different “modes”, each of which should continuously once activated, just like a simple draw() function would do.
Any suggestions will be greatly appreciated!
Here is an example of the issue:
def setup():
size(400,400)
background(255)
class Point(object):
def __init__(self,position):
self.position=position
def vector(self):
stroke(0)
#self.position.mult(0.3)
line(self.position.x,self.position.y,mouseX,mouseY)
def draw():
if keyPressed==True and key=="a":
background(255)
for i in range(0,width,20):
a=Point(PVector(i,0))
a.vector()
b=Point(PVector(i,height))
b.vector()
for j in range(0,height,20):
c=Point(PVector(0,j))
c.vector()
d=Point(PVector(width,j))
d.vector()
elif keyPressed==True and key=="s":
background(255)
for i in range(0,width,40):
a=Point(PVector(i,0))
a.vector()
b=Point(PVector(i,height))
b.vector()
for j in range(0,height,40):
c=Point(PVector(0,j))
c.vector()
d=Point(PVector(width,j))
d.vector()