Navigation

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Users
    • Groups
    • Solved
    • Unsolved
    • Search
    1. Home
    2. frederik
    3. Posts
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Posts made by frederik

    • RE: Script to Standalone app

      If you use a path in font(filePath) then the path is relative to the current directory (which is not always the the directory of the python file)

      DrawBot the app set the current directory to the .py file directory. When used as module this does not happen.

      So either set the a correct current directory or get a absolute path from the .py file: os.path.join(os.path.basename(__file__), "font.otf")

      posted in Code snippets
      frederik
      frederik
    • RE: Rounded Rectangle

      cool way to make a rounded rect!

      there are already a roundedRect example in the repository: see https://github.com/typemytype/drawbot/blob/master/examples/roundedRect.py

      I would encourage you to make a python package out of your helper tools that you import when you needed it...

      # a separate file with the name "roundedRect.py"
      def roundedRect(...):
          # draw your stuff here
      
      # an other file in the same directory
      
      #  name of the file/module  name of the function 
      from roundedRect import roundedRect
      
      # call it
      roundedRect(...)
      

      hope this makes sense!

      posted in Code snippets
      frederik
      frederik
    • RE: Script to Standalone app

      that is way to complex 🙂

      Variable works fine with the UI of drawBot... dont use it outside a drawBot document 😉

      You will have more control when you build it with vanilla and use this in a drawBot packages.

      import vanilla
      
      
      class MyController:
          
          def __init__(self):
              self.w = vanilla.Window((150, 40), "My Tool Name")
              self.w.slider = vanilla.Slider((10, 10, -10, 22), callback=self.sliderCallback)
              self.w.open()
          
          def sliderCallback(self, sender):        
              x = sender.get()
              newDrawing()
              fill(random(), random(), random())
              oval(x, 0, 1000, 1000)
              saveImage('/Users/frederik/Desktop/issueDrawBotPackage/test.pdf')
              endDrawing()
          
      
      MyController()
      

      this script wrapped in a .drawBot package

      posted in Code snippets
      frederik
      frederik
    • RE: Script to Standalone app

      this should work!

      8dec76fd-0762-4dc0-b37c-eb95a37420d2-image.png

      You can open the debugger in drawBot by hitten alt with the help menu open.

      posted in Code snippets
      frederik
      frederik
    • RE: Script to Standalone app

      If drawBot is installed as a module you can access it anywhere!

      If Variable(..) is a key thing in your script, use a drawBot package, where you can set a main script that gets executed when the file is opened in DrawBot.app.

      posted in Code snippets
      frederik
      frederik
    • RE: Change the value of a bool with (arrow) keys

      yes, thanks @jo

      possible with cmd + arrows keys or cmd + click when ever True or False is selected

      posted in Feature Requests
      frederik
      frederik
    • RE: Script to Standalone app

      Some parts of drawBots api don't work automatically outside the application, mainly parts where an UI is involved.

      But first why building an app?

      I would recommend UI parts to build separately. Build a window with vanilla, add some sliders and callback whenever that slider will change.

      DrawBot has a drawBot package, so drawBot code can be shared without looking a complex script folder structure: https://www.drawbot.com/content/drawBotApp/drawBotPackage.html

      posted in Code snippets
      frederik
      frederik
    • RE: QR code with type

      expanding Gustavo's example:

      import colorsys
      
      path = bytes('http://www.drawbot.com/', 'utf-8')
      
      w, h = 31, 31
      s = 10
      
      size(w*s, h*s)
      
      img = ImageObject()
      img.QRCodeGenerator((w, h), path, 'Q')
      
      iw, ih = img.size()
      
      t = ""
      
      for y in reversed(range(int(ih))):
          for x in range(int(iw)):
              r, g, b, a = imagePixelColor(img, (x, y))
              _, l, _ = colorsys.rgb_to_hls(r, g, b)
              if l < 0.51:
                  fill(0)            
                  rect(x*s, y*s, s, s)
                  t += "W"
              else:
                  t += " "
          
          t += "\n"
      
      newPage()
      font("Menlo", 16)
      lineHeight(10)
      textBox(t, (0, 0, width(), height()))
      print(t)
      

      and the corners are always the same 🙂

      posted in General Discussion
      frederik
      frederik
    • RE: Forced justified

      DrawBot is using CoreText to layout text. This is the same engine as TextEdit.app, and it seems this is also not possible there...

      posted in General Discussion
      frederik
      frederik
    • RE: FontTools, probably a simple question

      this works...

      from fontTools.misc.bezierTools import calcCubicArcLength
      
      
      pt1 = 100, 100
      pt2 = 200, 100
      pt3 = 400, 150
      pt4 = 400, 400
      
      l = calcCubicArcLength(pt1, pt2, pt3, pt4)
      
      path = BezierPath()
      path.moveTo(pt1)
      path.curveTo(pt2, pt3, pt4)
      
      text(str(l), pt3)
      
      fill(None)
      stroke(0)
      drawPath(path)
      
      posted in General Discussion
      frederik
      frederik
    • RE: masking photos

      you will need to mask a BezierPath with clipPath see https://www.drawbot.com/content/shapes/drawingPath.html#drawBot.clipPath

      I will let you try for a bit first 🙂

      good luck

      posted in Tutorials
      frederik
      frederik
    • RE: metaballs?

      not that I know of...

      there are some examples in processing and paperjs, which are vector based.

      posted in General Discussion
      frederik
      frederik
    • RE: Boolean and Rounded Corners

      he Lara!

      Nice to see you continuing your drawBots!!

      x, y = 300, 300
      s = 100
      # draw your rects as ovals
      oval(x, y, s, s)
      oval(x + s, y, s, s)
      oval(x + s, y + s, s, s)
      # build up connections with rects
      rect(x + s/2, y, s, s)
      rect(x + s, y + s/2, s, s)
      

      b8a0cb31-bcc4-4a19-9aa7-4c7635d8b202-image.png

      posted in General Discussion
      frederik
      frederik
    • RE: Once more: plot a single point

      use a global path instead of a creating a new path each time...

      xscreen = 640
      yscreen = 480
      
      left = 1.8
      right = 3.0
      bottom = 0.0
      top = 1.5
      invisible = 200
      visible = 200
      
          
      newPage(xscreen,yscreen)
      dotPath = BezierPath()
      
      def f(p, k) :
          fwert = p + k * p * (1 - p)
          return fwert
      
      def setglobalpoint(xw, yw):    
          x = (xw - left) * xscreen / (right - left)
          y = (yw - bottom) * yscreen / (top - bottom)
          
          dotPath.moveTo((x,y))
          dotPath.lineTo((x,y))
      
          
      def feigenbaumIteration():
          deltaxPerPixel = (right - left) / xscreen
          for section in range(0, xscreen+1, 1):
              coupling = left + section * deltaxPerPixel
              population = 0.3
              for i in range(0, invisible+1, 1):
                  population = f(population, coupling)
      
              for i in range(0, visible+1, 1):
                  setglobalpoint(coupling, population)
                  population = f(population, coupling)
                  
          
      feigenbaumIteration()
      
      lineCap("round")
      stroke(0)
      drawPath(dotPath)
      
      saveImage("~/Desktop/feigenbaum.png")
      

      this is already a megalot faster...

      posted in General Discussion
      frederik
      frederik
    • RE: plot a single point how?

      an example with a lot of random points

      p = BezierPath()
      
      for i in range(5000):
          x = random() * width() 
          y = random() * height()
          
          p.moveTo((x, y))
          p.lineTo((x, y))
      
      strokeWidth(10)
      lineCap("round")
      stroke(0)
      
      drawPath(p)
      

      e9327ed3-f3e8-4cc1-8720-8f9237e569a4-image.png

      posted in General Discussion
      frederik
      frederik
    • RE: plot a single point how?

      there is a work around

      # create a bezierPath 
      # this could collect all the points you want to show
      p = BezierPath()
      # add a point by moveTo and lineTo the same point
      p.moveTo((100, 100))
      p.lineTo((100, 100))
      # add an other point
      p.moveTo((100, 230))
      p.lineTo((100, 230))
      
      # set a stroke width
      strokeWidth(28)
      # set a line cap
      lineCap("round")
      # set a stroke color
      stroke(0)
      # draw the path
      drawPath(p)
      
      posted in General Discussion
      frederik
      frederik
    • RE: image patterns as shape fill

      not out of the box...

      but could be a nice feature to have support patterns

      the internals could like this:

      # create a source image
      source = ImageObject()
      with source:
          size(50, 50)
          rect(0, 0, 50, 10)
          for i in range(0, 5, 2):
              fill(random(), random(), random())
              oval(i * 10, 10, 10, 40)
          
      import AppKit
      
      # create an empty image
      im = AppKit.NSImage.alloc().initWithSize_((300, 300))
      # lock focus so drawing happens inside the image
      im.lockFocus()
      # create a color with a pattern of the source image and set it as the current color
      AppKit.NSColor.colorWithPatternImage_(source._nsImage()).set()
      # draw a rectangle with that pattern color
      AppKit.NSRectFill(((0, 0), (300, 300)))
      # unlock focus
      im.unlockFocus()
      
      # back to drawbot and draw the image object somewhere
      image(im, (50, 50))
      
      posted in General Discussion
      frederik
      frederik
    • RE: Using tkinter in DrawBot

      never used tkinter... DrawBot itself is made with `vanilla a pythonic wrapper around pyobjc.

      vanilla has all the dialogs you'll need!

      import vanilla
      
      result = vanilla.dialogs.getFileOrFolder()
      print(result)
      
      import vanilla
      help(vanilla.dialogs)
      
      posted in General Discussion
      frederik
      frederik
    • RE: Request: Barcode Generator

      An ImageObject as support to generate barcodes.

      fe: https://drawbot.com/content/image/imageObject.html#drawBot.context.tools.imageObject.ImageObject.code128BarcodeGenerator

      im = ImageObject()
      
      im.code128BarcodeGenerator((170, 32), message=b"hello world", quietSpace=0)
      image(im, (10, 10))
      
      

      Im making an issue to have the size argument optional.

      posted in Tutorials
      frederik
      frederik
    • RE: Scale text to fit rectangle?

      scale the canvas based on the dimension of your destination rectangle:

      # set a width height
      w, h = 396, 244
      # create a formattedString
      txt = FormattedString()
      # set a font
      txt.font("Times")
      # add some text
      txt += "kweti"
      
      #move it a bit
      translate(100, 100)
      # draw the black stroked rect
      fill(None)
      stroke(0)
      rect(0, 0, w, h)
      
      # create a path object
      path = BezierPath()
      # draw text into the path
      path.text(txt)
      # get the bounds of the path
      minx, miny, maxx, maxy = path.bounds()
      # get a scale value based on the bounding box
      scaleX = w / (maxx - minx)
      scaleY = h / (maxy - miny)
      # pick the smallest one and shift up to the middle in the other direction
      if scaleX < scaleY:
          scale(scaleX)
          shift = (h / scaleX - (maxy - miny)) / 2
          translate(0, shift)
      else:
          scale(scaleY)
          shift = (w / scaleY - (maxx - minx)) / 2
          translate(shift, 0)
      # translate witht the offset
      translate(-minx, -miny)
      # draw as text
      text(txt, (0, 0))
      
      posted in General Discussion
      frederik
      frederik