Pythonistapro777
Aug 11, 2015 - 13:42
In the game, when you draw the colour is white but I need help with making it so when I tap the re button the draw colour is red and if I click the blue button the draw color will be blue.
Thanks in advance!
Here's the code:
from scene import *
class MyScene (Scene):
def setup(self):
self.lines = []
self.button = Button(Rect(self.size.w/2+85, self.size.h/2-245, 75, 50))
self.button.background = Color(1,1,1)
self.button.stroke = Color(1,1,1)
self.button.action = self.add_clicks
self.add_layer(self.button)
self.redbutton = Button(Rect(self.size.w/2-35, self.size.h/2-245, 75, 50))
self.redbutton.background = Color(1,0,0)
self.redbutton.stroke = Color(1,1,1)
self.redbutton.action = self.turnred
self.add_layer(self.redbutton)
self.bluebutton = Button(Rect(self.size.w/2-155, self.size.h/2-245, 75, 50))
self.bluebutton.background = Color(0,0,1)
self.bluebutton.stroke = Color(1,1,1)
self.bluebutton.action = self.turnblue
self.add_layer(self.bluebutton)
def add_clicks(self):
run(MyScene())
def turnred(self):
stroke(1,0,0)
def turnblue(self):
stroke(0,0,1)
def draw(self):
background(0,0,0)
self.button.draw()
self.redbutton.draw()
self.bluebutton.draw()
fill(1,1,1)
rect(0,180,320,15)
rect(0,290,320,15)
rect(92,87,15,310)
rect(208,87,15,310)
#draw colour
stroke(1,1,1)
stroke_weight(4)
for l in self.lines:
line(*l)
def touch_moved(self, touch):
x = touch.location.x
y = touch.location.y
ppos = touch.prev_location
self.lines.append((ppos.x, ppos.y, x, y))
run(MyScene())