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.


    Alpha problem with ui.ImageContext.get_image()

    Pythonista
    2
    3
    1621
    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.
    • WillW68
      WillW68 last edited by

      I have modified the Sketch.py code to draw a succession of ovals instead of using path.stroke(), with the intention of using the pencil pressure to change the alpha at different points along the path. In the code below I have kept it constant for simplicity. But the alpha value does not seem to be captured correctly in ctx.get_image(), causing it to change when path_action() is called at the end of the path. Just add the code below to the Sketch.py example, and change the definition in touch_began() to self.path = MyPath() to see the problem when you lift the pencil/finger at the end of the stroke.

      import math
      def distanceBetween(point1, point2):
        return math.sqrt((point2[0] - point1[0])**2 + (point2[1] - point1[1])**2)
      
      def angleBetween(point1, point2):
        return math.atan2( point2[0] - point1[0], point2[1] - point1[1] )
      
      class MyPath():
      
      	def move_to(self,x,y):
      		self.path = [(x,y)]
      
      	def line_to(self,x,y):
      		self.path.append((x,y))
      	
      	def stroke(self):
      		w = 20
      		ui.set_alpha(0.006)
      		lastPoint = self.path[0]
      		for i in range(1,len(self.path)):
      			currentPoint = self.path[i]
      			dist = distanceBetween(lastPoint, currentPoint)
      			angle = angleBetween(lastPoint, currentPoint)
      			for j in range(int(dist)):
      				x = lastPoint[0] + (math.sin(angle) * j)
      				y = lastPoint[1] + (math.cos(angle) * j)
      				circle = ui.Path.oval(x, y, w, w)
      				circle.fill()
      			lastPoint = currentPoint
      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        sure you didnt change anything else? your code works for me:

        https://gist.github.com/48675c9f598a1a8ade648391b429d63c

        1 Reply Last reply Reply Quote 0
        • WillW68
          WillW68 last edited by

          I copied and pasted your code into a new script, and get the same result - when I lift my finger off at the end of a stroke, the alpha value of the whole stroke changes (gets lighter).

          I am running the latest version of Pythonista (3.2) using python 3.6 on a 10.5” iPad Pro with iOS 11.2

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