Drawing characters and symbols

edited April 2018 in Python Mode

Hi,

I'm trying to draw special characters / symbols with the text() function such as:

'■', '□', '▢', '▲', '△', '▼', '▽', '◆', '○', '●', 'Δ', 'ʊ', '™', '©', '®', '¿', '¡', '½', '⅓', '⅔', '¼', '¾', '⅛', '⅜', '⅝', '⅞', '℅', '№', '∃', '∩', '∀','Ξ', 'Γ', 'ɐ', 'ə', 'ɘ', 'ε', 'β', 'ɟ', 'ɥ', 'ɯ', 'ɔ', 'и', 'ɹ', 'ʁ', 'я', 'ʌ', 'ʍ', 'λ', 'ч', '∞', 'Σ', 'Π', 'η', 'α','·','¨','…', '¦', '┅', '┆', '┈', '┊',' ╱',' ╲', '╳', '¯', '–', '—','≡', '░', '▒', '▓', '█', '▌', '▐', '▀', '▄', '╭', '╮', '╯', '╰','│', '┤', '╡', '╢', '╖', '╕', '╣', '║', '╝', '╜',' ╛', '┐', '└', '┴', '┬', '├', '─', '┼', '╞', '╟', '╚', '╔', '╩', '╦', '╠', '═', '╬', '╧', '╨', '╤', '╥', '╙', '╘', '╒', '╓', '╫', '╪', '┘', '┌', 'Σ', '♠', 'Ω', '♣', '♥', '♦', '☼', '☻'...

However most of them (90%) don't seem to be recognized. All I have instead is the letter 'â' printed on the screen.

Is there a way to draw all these symbols ?

Thanks

Answers

  • Hey GoToLoop, thanks for your answer. Strangely, the code works in Java but not in Python mode.

        JAVA = 1/2 != 1/2.;
        FONT_SIZE = 24;
        FONT_JAVA = "Roman";
    
        def setup():
          size(600, 200)
          smooth(3)
          noLoop()
    
          colorMode(RGB)
          fill(20)
    
          textMode(MODEL)
          textAlign(CENTER, CENTER)
    
          if JAVA:
              textFont(createFont(FONT_JAVA, FONT_SIZE, True))
          else:
              textSize(FONT_SIZE)
    
    
        def draw():
          background(255)
    
          text("διχθαδίας κῆρας φερέμεν θανάτοιο τέλος δέ.\n" +
            "Бу́ря мгло́ю не́бо кро́ет, Ви́хри сне́жные крутя́;\n" + 
            "Ako sa voláš", width>>1, height>>1)
    

    Any idea what could possibly prevent this to work in Python mode ?

  • edited April 2018 Answer ✓
    """
     Unicode Letters Test (v1.0)
     GoToLoop (2018/Apr/01)
    
     Forum.Processing.org/two/discussion/27619/
     drawing-characters-and-symbols#Item_3
    
     Studio.ProcessingTogether.com/sp/pad/export/ro.9hlrt8LyDd9uA
    """
    
    FONT_JAVA, FONT_SIZE = 'Roman', 24
    FG, BG = 0xffFFFF00, 0xff0000FF
    
    def setup():
        size(600, 200, JAVA2D)
    
        smooth(3)
        noLoop()
        frameRate(60)
    
        cursor(ARROW)
        colorMode(RGB)
        blendMode(REPLACE)
        fill(FG)
    
        textMode(MODEL)
        textAlign(CENTER, CENTER)
    
        textFont(createFont(FONT_JAVA, FONT_SIZE, True))
    
    
    def draw():
        background(BG)
    
        text(u'διχθαδίας κῆρας φερέμεν θανάτοιο τέλος δέ.\n' +
        u'Бу́ря мгло́ю не́бо кро́ет, Ви́хри сне́жные крутя́;\n' + 
        u'富士の風や扇にのせて江戸土産\n' + u'Ako sa voláš', width>>1, height>>1)
    
  • Great ! Thank you GoToLoop.

  • edited April 2018

    Apologies @GoToLoop, I still have a problem regarding unicode text. I'm not writing text directly inside the text function (as in the example) but call an item randomly in a list of strings (here named "symbols"):

    def setup():
        global x, y, edge, symbols
        background(240)
        size(706, 960)
        smooth(8)
    
        edge = 10
        x = 0
        y = edge
        symbols = ['■', '□', '▢', '▲', '△', '▼', '▽', '◆', '○', '●', 'Δ', 'ʊ']
    
    
    def draw():
        global x, y
    
        x +=  edge
        if x >= width - edge:
            x = edge
            y += edge / 1.35
        if y >= height - (edge*2) and x >= width - (edge*2):
            noLoop()
    
        rdm = int(random(len(sym)))
    
        fill(0)
        text(u'%.s' % symbols[rdm], x, y)
    

    The last line gives me the following error message:

    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)

    Then I though this would do the trick:

    text(u'%.s'.decode('utf-8') % sym[rdm], x, y)
    

    But unfortunately I still get the same error message. Do you have an idea how to solve this problem in Python ?

  • edited April 2018 Answer ✓
    """
     Unicode Chars Test (v1.0)
     GoToLoop (2018/Apr/01)
    
     Forum.Processing.org/two/discussion/27619/
     drawing-characters-and-symbols#Item_6
    """
    
    FONT_JAVA, FONT_SIZE = 'Roman', 0100
    FG, BG = 0xffFFFF00, 0xff008000
    
    GLYPHS = u'■□▢▲△▼▽◆○●Δʊ'
    GLY_LEN = len(GLYPHS)
    
    def setup():
        size(150, 150, JAVA2D)
    
        smooth(3)
        noLoop()
        frameRate(60)
    
        cursor(ARROW)
        colorMode(RGB)
        blendMode(REPLACE)
        fill(FG)
    
        textMode(MODEL)
        textAlign(CENTER, CENTER)
    
        textFont(createFont(FONT_JAVA, FONT_SIZE, True))
    
    
    def draw():
        background(BG)
        text(GLYPHS[int(random(GLY_LEN))], width>>1, height>>1)
    
    
    def keyPressed(): redraw()
    def mousePressed(): this.keyPressed()
    
  • Thanks a lot. :)

Sign In or Register to comment.