Navigation

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

    Topics created by jo

    • jo

      trim box in pdfs
      Feature Requests • • jo  

      4
      0
      Votes
      4
      Posts
      16
      Views

      frederik

      tried it a long time ago... didnt got it to work for some reason, so support for trim and bleed is set on hold: https://github.com/typemytype/drawbot/pull/304 if you got any idea to get it to work with quartz pdf context, let me know
    • jo

      when to apply paragraphBottomSpacing
      Feature Requests • • jo  

      3
      0
      Votes
      3
      Posts
      11
      Views

      jo

      oké I had some small hope but thanks for testing and clarifying! not very elegant but kind of working: txt = 'Some Text\nwith new lines\rIs a return\na new line\ror a new paragraph?' paras = [[l + '\n' for l in p.split('\n')] for p in txt.split('\r')] newPage(150, 150) fstr = FormattedString() for para in paras: for l in para: extra_space = 5 if l == para[-1] else 0 fstr.append(l, paragraphBottomSpacing = extra_space) text(fstr, (20, 110))
    • jo

      binary counting with a 7 segment LCD
      Code snippets • • jo  

      1
      0
      Votes
      1
      Posts
      6
      Views

      No one has replied

    • jo

      SOLVED bezierPath.polygon()?
      Feature Requests • bezierpath • • jo  

      2
      1
      Votes
      2
      Posts
      228
      Views

      frederik

      continue here https://github.com/typemytype/drawbot/issues/301 thanks!
    • jo

      Lissajous table
      Code snippets • lissajous • • jo  

      1
      2
      Votes
      1
      Posts
      339
      Views

      No one has replied

    • jo

      Vera Molnar re-coded
      Code snippets • recreations • • jo  

      3
      3
      Votes
      3
      Posts
      378
      Views

      mrrouge

      very cool thanks
    • jo

      Solar eclipse
      Code snippets • • jo  

      1
      0
      Votes
      1
      Posts
      352
      Views

      No one has replied

    • jo

      listInstances(font)?
      Feature Requests • variable fonts • • jo  

      2
      0
      Votes
      2
      Posts
      585
      Views

      frederik

      oh that api is idd missing added a issue and further discussion should happen there https://github.com/typemytype/drawbot/issues/256 thanks!
    • jo

      Drawing a circle with Beziers
      Code snippets • bezierpath geometry • • jo  

      1
      2
      Votes
      1
      Posts
      706
      Views

      No one has replied

    • jo

      More variable fonts nonsense
      Code snippets • animation variable fonts • • jo  

      9
      4
      Votes
      9
      Posts
      1673
      Views

      Christine

      Hoi I’m using OS 10.13.6, Drawbot says ModuleNotFoundError: No module named 'helper_functions' ––– ah, sorry, I just saw that there’s an extra file with the helper functions.
    • jo

      Tutorial request: BezierPath() to pen
      Tutorials • bezierpath pens • • jo  

      8
      0
      Votes
      8
      Posts
      1927
      Views

      frederik

      found it back: this reminds me a thing I wrote some years ago
    • jo

      Animated Müller-Lyer illusion
      Code snippets • animation recreations • • jo  

      7
      3
      Votes
      7
      Posts
      2181
      Views

      jo

      ok, one more. very similar to the previous one. page_s = 500 cell_amount = 12 rhythm = [1, 0, 0, 1, 0, 1, 1, 0] cell_s = page_s / cell_amount corner_s = cell_s/4 newPage(page_s, page_s) translate(-cell_s/2, -cell_s/2) def lozenge(pos, s): x, y = pos polygon((x, y), (x + s/2, y + s/2), (x + s, y), (x + s/2, y - s/2)) for x in range(cell_amount+1): for y in range(cell_amount+1): pos_x, pos_y = x * cell_s, y * cell_s fill(0.5) if (x+y) % 2 == 0 else fill(1) rect(pos_x, pos_y, cell_s, cell_s) fill(1) lozenge((pos_x - corner_s, pos_y), corner_s*2) fill(0) shift = (x + y) % len(rhythm) if rhythm[ shift ]: lozenge((pos_x - corner_s, pos_y), corner_s) lozenge((pos_x, pos_y), corner_s) else: lozenge((pos_x - corner_s/2, pos_y + corner_s/2), corner_s) lozenge((pos_x - corner_s/2, pos_y - corner_s/2), corner_s)
    • jo

      SOLVED setPixelColor() image Object?
      General Discussion • image object • • jo  

      2
      0
      Votes
      2
      Posts
      841
      Views

      frederik

      not directly... you can load the image as an ImageObject and use it as a context to draw something, a pixel at a specific place. im = ImageObject("http://f.cl.ly/items/1T3x1y372J371p0v1F2Z/drawBot.jpg") with im: fill(1, 0, 1) rect(0, 0, 10, 10) image(im, (10, 10))
    • jo

      Rotating rectangles based on an artpiece by Vera Molnar
      Tutorials • recreations randomness • • jo  

      4
      3
      Votes
      4
      Posts
      2492
      Views

      jo

      A small extension to the original code. The above Version (with the rectangle size of cell size / sqrt(2)) is only one of a series of four. Depending on the size of the rectangles they touch in different ways. So here is the updated code to use the same rotation pattern on four pages with different rectangle sizes. First let’s store the size of the canvas (1000) in the variable canvas_s. The amount variable and calculation of the cell size stays the same: canvas_s = 1000 amount = 24 cell_s = canvas_s / (amount + 2) The four different rectangle sizes are stored in a list. rect_sizes = [ cell_s / 2, cell_s / sqrt(2), 2 * cell_s / ( 1 + sqrt(2) ), cell_s] The sizes are calculated to get the various ‘touchings’. Just add other rectangle sizes to the list and see that you get. cell_s / 2: no touching cell_s / sqrt(2): the rotated rectangles tough on the corners 2 * cell_s / (1 + sqrt(2)): a rotated and default rectangle touch on the corner and side cell_s: the not rotated rectangles touch on the side To use the same rotation grid we have to generate and store it somehow. Let’s use the nested loops to store this information in the grid variable. It is a list of lists (rows or columns whatever you prefere). Declare the variable and store an empty list: grid = [] Loop though the amount for y in range(amount): For every row we assign a new empty list to the newRow variable newRow = [] Then loop through the amount and append either True or False to the newRow for x in range(amount): if random() > .5: newRow.append(True) else: newRow.append(False) When we are finished with the row loop let’s append the newRow to the grid grid.append( newRow ) The above grid generation could actually be done in one line as well. So this: grid = [] for y in range(amount): newRow = [] for x in range(amount): if random() > .5: newRow.append(True) else: newRow.append(False) grid.append( newRow ) Will do the same as this: grid = [[True if random() > .5 else False for x in range(amount)] for y in range(amount)] List comprehension and ternary operators are great and will save you some lines but they can be a bit confusing. The rest of the script basically stays the same. There is one more loop added to generate the pattern for each size: for rect_s in rect_sizes: For each size we need a new canvas so we call newPage() and use the variable canvas_s to make them all the same size: newPage(canvas_s, canvas_s) Translation for the margin translate( cell_s, cell_s) To loop through the stored grid let’s use the enumerate() function. This is very helpful if you need the index and the actual element of a list. for index, value in enumerate(['a', 'b', 'c']): print index, value will print (in python 2.7) 0 a 1 b 2 c We will use the index for the transformation and the element (True or False) for the rotation. for r, row in enumerate(grid): for c, cell in enumerate(row): with savedState(): translate( c * cell_s + cell_s/2, r * cell_s + cell_s/2 ) if cell: rotate(45) rect(-rect_s/2, -rect_s/2, rect_s, rect_s) If you want to store seperate images (.jpg or .png) we call the saveImage() inside the size loop. saveImage('~/Desktop/Vera_Molnar_rotating_rects_%f.png' % rect_s) For a multipage pdf or gif the saveImage() should be outside of the loops. The full code canvas_s = 1000 amount = 24 cell_s = canvas_s / (amount + 2) rect_sizes = [ cell_s / 2, cell_s / sqrt(2), 2 * cell_s / ( 1 + sqrt(2) ), cell_s] grid = [[True if random() > .5 else False for x in range(amount)] for y in range(amount)] for rect_s in rect_sizes: newPage(canvas_s, canvas_s) translate( cell_s, cell_s) for r, row in enumerate(grid): for c, cell in enumerate(row): with savedState(): translate( c * cell_s + cell_s/2, r * cell_s + cell_s/2 ) if cell: rotate(45) rect(-rect_s/2, -rect_s/2, rect_s, rect_s) # saveImage('~/Desktop/Vera_Molnar_rotating_rects_f.png' % rect_s) You should get something like this
    • jo

      Cellular automaton
      Code snippets • • jo  

      4
      2
      Votes
      4
      Posts
      2101
      Views

      justvanrossum

      @jo Beautiful!!!