omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    [SOLVED!] Help with stroke color

    Pythonista
    2
    2
    1607
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Pythonistapro777
      Pythonistapro777 last edited by Pythonistapro777

      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())
      
      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by ccc

        stroke_color.py

        You do not need to draw each sublayer individually.

        def draw(self):
            scene.background(0,0,0)
            self.root_layer.update(self.dt)
            self.root_layer.draw()
        

        will draw all sublayers that have been added to a scene.Scene.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Powered by NodeBB Forums | Contributors