Navigation

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

    Posts made by jo

    • RE: when to apply paragraphBottomSpacing

      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))
      
      

      Screenshot 2023-03-17 at 10.42.24.png

      posted in Feature Requests
      jo
      jo
    • when to apply paragraphBottomSpacing

      I tried to use paragraphBottomSpacing and was hoping that drawbot would interpret \n as still the same paragraph and only apply the extra white space once I use a \r.

      So there should only be extra white space after the line 'with new lines' but not after the other newlines.

      txt = 'Some Text\nwith new lines\rIs a return\na new line\ror a new paragraph?'
      fstr = FormattedString(txt, paragraphBottomSpacing=3)
      newPage(150, 150)
      text(fstr, (20, 110))
      

      asdtasdt.png

      hope that makes sense, thanks

      posted in Feature Requests
      jo
      jo
    • RE: Help combining ideas

      you instantiate the BezierPath outside the loop and then draw the text in every round of the loop. just put the bp = BezierPath() inside the loop.

      posted in General Discussion
      jo
      jo
    • RE: Help combining ideas

      hi, I think the BezierPath text does not accept variable font settings. You can first draw the text into a FormattedString() and then add that to the BezierPath.

      bp = BezierPath()
      fstr = FormattedString("JUICY", font='Skia-Regular', fontSize=80, fontVariations = {'wght' : curr_value})
      bp.text(fstr, (10, 10))
      

      hope that helps!

      posted in General Discussion
      jo
      jo
    • RE: Local modules don’t update

      reload is python 2
      afaik in python 3.4 and newer you are supposed to use:

      import importlib
      importlib.reload(module)
      

      good luck!

      posted in Bugs
      jo
      jo
    • RE: Change the value of a bool with (arrow) keys

      this should work already.

      when you select the bool (True or False) and then press the Cmd + arrow keys the value should change.

      posted in Feature Requests
      jo
      jo
    • RE: Tutorial Request:Randomize Each Character Color in text

      you will need to use a loop to iterate over your list of characters and append them to a formattedString.

      first initiate the formattedString:

      f_str = FormattedString(font = myFont, fontSize = pointSize)
      

      then iterate over your list:

      for ch in wordText:
      

      select a random color inside the loop and append the character to the formattedString

          ch_col = random.choice(colors)
          f_str.append(ch, fill = ch_col)
      

      finally draw your textBox with the formattedString

      textBox(f_str, box, align="left")
      

      so the last four lines of your code should be:

      f_str = FormattedString(font = myFont, fontSize = pointSize)
      
      for ch in wordText:
          ch_col = random.choice(colors)
          f_str.append(ch, fill = ch_col)
      
      textBox(f_str, box, align="left")
      

      good luck!

      posted in Tutorials
      jo
      jo
    • RE: Chess board in one loop

      @monomonnik
      yes and no.
      in the chessboard examples it does not really matter if you go by columns or by rows.
      but yes the first returned value is the quotient i//n or int(i/n) and the second returned value is the remainder (modulo) i % n.

      posted in General Discussion
      jo
      jo
    • RE: Chess board in one loop

      @monomonnik
      perfect place to use divmod.
      this:

      x = i % 8
      y = int(i/8)
      

      could be written like:

      x, y = divmod(i, 8)
      

      it will return the quotient (x) and the remainder (y).

      posted in General Discussion
      jo
      jo
    • RE: Random values inside the axes of a variable font

      I am not quite sure what exactly you are asking but the get a random integer value inside a range you could use randint(min_value, max_value). This works for integers. To get a random value between 100 and 900 you would use randint(100, 900).
      If you have a smaller range and want fractions as well you could use min_value + random() * (max_value - min_value) eg 100 + (900-100) * random()
      I hope that helps, good luck!

      posted in General Discussion
      jo
      jo
    • binary counting with a 7 segment LCD

      here is some code to draw a 7 segment LCD and use the segments to count up to 127 (2**7-1).

      
      class digit(object):
      	"""a digit of the lcd display"""
      	def __init__(self, pos, size, seg_l, seg_h):
      		self.pos    = pos
      		self.size   = size
      		self.seg_l  = seg_l
      		self.seg_h  = seg_h
      
      	def draw_segment(self, indx, l, h):
      		seg_poss = [
      			(           0,  self.size),
      			( self.size/2,  self.size/2),
      			( self.size/2, -self.size/2),
      			(           0, -self.size),
      			(-self.size/2, -self.size/2),
      			(-self.size/2,  self.size/2),
      			(           0,  0), ]
      
      		x = self.pos[0] + seg_poss[indx][0]
      		y = self.pos[1] + seg_poss[indx][1]  
      
      		if indx in [1, 2, 4, 5]:
      			polygon(
      				(x, y + l/2),
      				(x - h/2, y + l/2 - h/2),
      				(x - h/2, y - l/2 + h/2),
      				(x, y - l/2),
      				(x + h/2, y - l/2 + h/2),
      				(x + h/2, y + l/2 - h/2),)
      		else: 		
      			polygon(
      				(x + l/2, y),
      				(x + l/2 - h/2, y + h/2),
      				(x - l/2 + h/2, y + h/2),
      				(x - l/2, y),
      				(x - l/2 + h/2, y - h/2),
      				(x + l/2 - h/2, y - h/2),)
      
      	def draw(self, num):
      		for s in range(7):
      			if (num & (1<<s)):
      				self.draw_segment(s, self.seg_l, self.seg_h)
      
      # ---------------------------
       
      int_to_bin = {
          0 :  63,
          1 :   6,
          2 :  91,
          3 :  79,
          4 : 102, 
          5 : 109, 
          6 : 125,
          7 :   7,
          8 : 127,
          9 : 111,
          }
      
      # ---------------------------
      
      PW, PH = 500, 500
      
      d  = digit((0, 0), PW/3, 150, 30)
      d_int = digit((PW*.5, -PH*.4), 16, 14, 4)
      
      
      for n in range(128):
          assert (0 <= n < 128), "Values should be higher than -1 and smaller than 128!"    
          newPage(PW, PH)
          fill(.2)
          rect(0, 0, PW, PH)
          translate(PW/2, PH/2)
          skew(2)
          fill(0, 1, 0)
          d.seg_h = n+4
          d.draw(n)
      
          with savedState():
              for i in reversed(str(n)):
                  translate(-30)
                  d_int.draw(int_to_bin[int(i)])         
      

      should make animations like this:

      bin_count2.gif

      posted in Code snippets
      jo
      jo
    • RE: 2D 5-Neighbor Cellular Automata

      i would leave the center or starting point at (0, 0) and shift the origin with translate(canvas/2, canvas/2). If cell at (n, n) is positive add (n, n), (-n, n), (n, -n), (-n, -n) to the list or dict of active cells. hmmhmh not sure if that makes sense.

      for x in range(cell_amount):
          for y in range(cell_amount):
              if (x, y): #check if cell is active here 
                  grid[( x,  y)] == 1
                  grid[(-x,  y)] == 1
                  grid[( x, -y)] == 1
                  grid[(-x, -y)] == 1
      

      hope that makes sense. good luck!

      posted in Code snippets
      jo
      jo
    • RE: 2D 5-Neighbor Cellular Automata

      hi juan, pretty nice!
      I hope somebody will post a more general and cleaner solution to this but one way would be remove all the ifs and calculate the ruleSet position:

      val = 9 - 2 * nbs(grid,r,c) - grid[r][c]
      newGrid[r].append(int(ruleSet[val])) 
      

      This line:

      return sum(map(bool, neighbors_list))
      

      could be simplified to just:

      return sum(neighbors_list)
      

      Two remarks:
      If you are drawing the result in two colors you could just draw the background colour with one rect covering the whole canvas and then draw black cells if the grid position is positive.
      Lists are not pythons fastest collection. It would need some rewriting but using a dictionary for the grid could speed this up.

      Good luck!

      UPDATE / ADDITION
      actually the whole check if a cell is active or not could be reduced to one quarter since there is a twofold symmetry. so just checking it once and then setting all four quarters.

      posted in Code snippets
      jo
      jo
    • RE: Tutorial request: how to animate a variable font

      @hzinn

      not sure how best to improve this
      more frames and higher resolution might be a start
      and maybe adding a background.

      posted in Tutorials
      jo
      jo
    • RE: Tutorial request: how to animate a variable font

      @hzinn hi,
      maybe some calculation is going wrong. maybe the variable font has some issues? but it is really hard to say what is happening without some code or image.
      does it work if you use the Skia font?

      posted in Tutorials
      jo
      jo
    • RE: Unknown Pleasures Tutorial

      @eduairet nice!
      I am happy you found the comments helpful! So I will mention one more about the page count. The 66 pages confused me at first since I did not see them assigned anywhere. Until I realized that you are generating the Triangular Number since you are looping twice. Not sure if you are doing this on purpose but maybe the last loop

      for i in range(12):
          lineGrid(i)
      

      could just be.

      lineGrid(12)
      

      or

      lineGrid(66)
      

      if you really wanted exactly that amount of frames.

      posted in Tutorials
      jo
      jo
    • RE: Unknown Pleasures Tutorial

      hi @eduairet
      nice one! I don’t think I have ever tried that one myself. I had a look at your code and have some suggestions that might shorten it but hopefully keep it readable.

      Here are some comments on the lsPts function:

      The if statements could be written without the and:

      if min_limit < value <= max_limit: 
      

      Not sure why you are doing 10**1 since it is the same as 10

      All the ifs could probably be an if and some elifs and a final else so not every value gets checked four times.

      DRY! The line x = i is used four times but since you only change y you could write this line outside of your ifs just once. Also the points.append() could happen just at the end of the ifs.

      The lsPts() function takes the parameter num but it never gets used. Maybe this could be the gap between the points?

      Maybe some of these comments are helpful — Have fun!

      posted in Tutorials
      jo
      jo
    • RE: Variable portrait

      hi @eduairet
      you can submit a string of characters to the random choice function:

      chars = 'aeiou'
      print (random.choice(chars))
      

      any call of a ‘drawing function’ will make a new Page. Remove the translate(0, 2) to not have the blank page.

      Finally getting the image pixel color takes some time. Try to move stuff outside of the loops if they do not change. Eg try a loop outside the ranLetters() function to get and store the pixel colors, so you do not have to do that for every page.

      pix_cols = {}
      
      for x in range(0, w, s):
          for y in range(0, h, s):
              pix_cols[(x, y)] = imagePixelColor(path, (x, y))
      

      then inside the loop just ask for the stored value:

      color = pix_cols[(x, y)]
      

      also these three lines do not change so they could be outside of the loop:

      font("League Spartan Variable")
      fontSize(s)
      lineHeight(s * 0.75)
      

      good luck!

      posted in Tutorials
      jo
      jo
    • bezierPath.polygon()?

      I just tried to use bezierPath.polygon() since bezierPath.rect() and bezierPath.oval() work.
      this does not work (and can be solved in other ways), but maybe it would be nice and somewhat logic since rect and oval do work?

      posted in Feature Requests
      jo
      jo
    • RE: How can I split a path into multiple segments?

      @jansindl3r keep in mind that in a Bezier curve time and distance do not correlate. if you construct a point at time .1 it will not be at one tenth of the curve length.
      Bezier_const.png

      afaik the most common technique to get similar distances is to calculate lots of points on the curve(s), calculate some distances and select the closest points.

      this link has some very helpful information.

      good luck.

      posted in General Discussion
      jo
      jo