ASCII visualization issue

Hello!
I’m trying to draw with some ASCII characters (like ░▒▓) on a Mac with Processing.py
but unfortunately when I hit play they are not displaying correctly as you can see from the screenshot here

What am I missing? Should I install something on my machine?
Thanks! :slight_smile:

2 Likes

Cheers @rrnn !

Please show us your code.

I’m afraid ’ ░▒▓’ are not ASCII chars, check this ASCII table at wikipedia, I think they are Unicode. So, you might need to find a font that has those glyphs on the Mac.

Also, remember Processing 3.5.4 with Python mode (doesn’t work well on Processing 4) are using a Python 2.7 interpreter, so you’ll need u before literal strings for unicode, like this: unicode_chars = u"░▒▓"

Here on Linux, using Source Code Pro, it worked for me.

3 Likes

More sketch examples of UNICODE chars in Python Mode: :snake:

"""
 Unicode Letters Test (v1.0.1)
 GoToLoop (2018/Apr/01)

 Forum.Processing.org/two/discussion/27619/
 drawing-characters-and-symbols#Item_3

 Discourse.Processing.org/t/ascii-visualization-issue/42041/3

 Studio.ProcessingTogether.com/sp/pad/export/ro.9hlrt8LyDd9uA
"""

FONT_TYPE, FONT_SIZE = 'Roman', 24
FG, BG = 0xffFFFF00, 0xff0000FF

def setup():
    size(600, 200)
    noLoop()

    fill(FG)
    textAlign(CENTER, CENTER)
    textFont(createFont(FONT_TYPE, FONT_SIZE, True))


def draw():
    background(BG)

    text(u'διχθαδίας κῆρας φερέμεν θανάτοιο τέλος δέ.\n' +
    u'Бу́ря мгло́ю не́бо кро́ет, Ви́хри сне́жные крутя́;\n' + 
    u'富士の風や扇にのせて江戸土産\n' + u'Ako sa voláš', width >> 1, height >> 1)
"""
 Unicode Chars Test (v1.0.1)
 GoToLoop (2018/Apr/01)

 Forum.Processing.org/two/discussion/27619/
 drawing-characters-and-symbols#Item_6

 Discourse.Processing.org/t/ascii-visualization-issue/42041/3
"""

FONT_TYPE, FONT_SIZE = 'Roman', 0100
FG, BG = 0xffFFFF00, 0xff008000

GLYPHS = u'■□▢▲△▼▽◆○●Δʊ'
GLY_LEN = len(GLYPHS)

def setup():
    size(150, 150)
    noLoop()

    fill(FG)
    textAlign(CENTER, CENTER)
    textFont(createFont(FONT_TYPE, FONT_SIZE, True))


def draw():
    background(BG)
    text(GLYPHS[int(random(GLY_LEN))], width >> 1, height >> 1)


def keyPressed(): redraw()
def mousePressed(): this.keyPressed()
6 Likes

hey both @villares @GoToLoop thanks for the help, I haven’t solved yet but you put me in the right direction to understand it :slight_smile:

Also, remember Processing 3.5.4 with Python mode (doesn’t work well on Processing 4) are using a Python 2.7 interpreter,

is then better to use the Java or js version?

1 Like

If you’d like to code in Python, have a look at py5. It fills a similar role as Processing.py and may be nicer to use at the moment.

3 Likes

Thanks, checking it!

There’s also PyScript, which allows us to code in Python on the web, using both Python & JavaScript libraries, such as p5*js, q5#js and even Pjs:

2 Likes

I almost forgot, @mcintyre has a Pyodide addon package for p5*js + PyScript named proceso:

It’s an excellent option for coding in p5*js using a pythonic syntax.

But we can always opt to just use PyScript directly, especially if we prefer other Processing flavors such as Pjs, q5#js and its fork q5*js.

3 Likes

Thanks @GoToLoop! I need a couple of weeks to complete proceso’s documentation, but the package works well today. I’ll learn a lot by teaching with it in my “Data Science in the Garden” class this summer.

@rrnn here’s a quick sketch with your original glyphs running on PyScript. Would love your feedback if you have some time to tinker.

2 Likes

Just made some small coding style changes to match my preferences: :face_with_peeking_eye:


index.html:

<!DOCTYPE html>

<meta charset=utf-8>

<link rel=stylesheet href=//PyScript.net/latest/pyscript.css>
<script defer src=//PyScript.net/latest/pyscript.js></script>

<link rel=stylesheet href=p5.css>
<script defer src=//cdn.JsDelivr.net/npm/p5></script>

<py-config src=pyscript.toml></py-config>
<py-script defer src=sketch.py></py-script>

pyscript.toml:

name = 'ASCII Visualization'
version = '1.0.2'
description = 'https://Discourse.Processing.org/t/ascii-visualization-issue/42041/10'
url = 'https://PyScript.com/view/37e29c80-c433-4dca-a8bc-4b7207b089a8/fd5c6e94-a7f3-424d-9be1-d43eb1859386/latest'
packages = [ 'proceso' ]

p5.css:

html, body {
  margin: 0;
  padding: 0;
}

canvas {
  display: block;
}

sketch.py:

"""
 Response to rrnn's issue:
 Discourse.Processing.org/t/ascii-visualization-issue/42041
 2023/May/22
"""

from proceso import Sketch

p = Sketch()
p.describe('big glyphs')

GLYPHS = '░▒▓'

def setup():
    p.create_canvas(200, 300)
    p.frame_rate(12)

    p.text_size(0o300)
    p.text_align(p.CENTER, p.CENTER)


def draw():
    p.background(0o350)
    char = GLYPHS[p.frame_count % len(GLYPHS)]
    p.text(char, p.width >> 1, p.height >> 1)


p.run_sketch(setup = setup, draw = draw)

1 Like

Just converted my 2 Python Mode sketches to run on just PyScript w/o any packages.

“Unicode Letters Test” is using library p5*js while “Unicode Chars Test” is in Pjs.

“Unicode Letters Test”:


“index.html”:

<!DOCTYPE html>

<meta charset=utf-8>

<link rel=stylesheet href=//PyScript.net/latest/pyscript.css>
<script defer src=//PyScript.net/latest/pyscript.js></script>

<script defer src=//cdn.JsDelivr.net/npm/p5></script>

<py-config src=pyscript.toml></py-config>
<py-script defer src=sketch.py></py-script>

“pyscript.toml”:

name = 'Unicode Letters Test'
version = '1.0.0'
author_name = 'GoToLoop'
license = 'Unlicense'
description = 'https://Discourse.Processing.org/t/ascii-visualization-issue/42041/11'
url = 'https://PyScript.com/view/37e29c80-c433-4dca-a8bc-4b7207b089a8/f540a5ff-ca53-4e5a-b149-a61df207cd01/latest'

“sketch.py”:

"""
 Unicode Letters Test (v1.0.0) [p5*js]
 GoToLoop (2023/May/26)

 Discourse.Processing.org/t/ascii-visualization-issue/42041/11

 Forum.Processing.org/two/discussion/27619/
 drawing-characters-and-symbols#Item_3

 Studio.ProcessingTogether.com/sp/pad/export/ro.9hlrt8LyDd9uA
"""

from js import p5
from types import MethodType

FONT_TYPE, FONT_SIZE = 'Verdana', 24
FG, BG = 'yellow', 'blue'

def sketch(p):
    p.setup = MethodType(setup, p)
    p.draw = MethodType(draw, p)


def setup(p):
    p.createCanvas(600, 200)
    p.fill(FG).noLoop()
    p.textFont(FONT_TYPE, FONT_SIZE).textAlign(p.CENTER, p.CENTER)

    global bg
    bg = p.color(BG)


def draw(p):
    p.background(bg).text(
      'διχθαδίας κῆρας φερέμεν θανάτοιο τέλος δέ.\n' +
      'Бу́ря мгло́ю не́бо кро́ет, Ви́хри сне́жные крутя́;\n' +
      '富士の風や扇にのせて江戸土産\n' + 'Ako sa voláš',
      p.width >> 1, p.height >> 1
    )


p5.new(sketch)

“Unicode Chars Test”

“index.html”:

<!DOCTYPE html>

<meta charset=utf-8>

<link rel=stylesheet href=//PyScript.net/latest/pyscript.css>
<script defer src=//PyScript.net/latest/pyscript.js></script>

<script defer src=//Unpkg.com/processing-js></script>

<py-config src=pyscript.toml></py-config>
<py-script defer src=sketch.py></py-script>

“pyscript.toml”:

name = 'Unicode Chars Test [pjs]'
version = '1.0.0'
author_name = 'GoToLoop'
license = 'Unlicense'
description = 'https://Discourse.Processing.org/t/ascii-visualization-issue/42041/11'
url = 'https://PyScript.com/view/37e29c80-c433-4dca-a8bc-4b7207b089a8/9c2d93cb-4168-45d9-a58e-9aea24ce8f40/latest'

“sketch.py”:

"""
 Unicode Chars Test (v1.0.0) [pjs]
 GoToLoop (2023/May/26)

 Discourse.Processing.org/t/ascii-visualization-issue/42041/11

 Forum.Processing.org/two/discussion/27619/
 drawing-characters-and-symbols#Item_6
"""

from js import Processing, document
from types import MethodType

FONT_TYPE, FONT_SIZE = 'Verdana', 0o100
FG, BG = 0xffFFFF00, 0xff008000

GLYPHS = '■□▢▲△▼▽◆○●Δʊ'
GLY_LEN = len(GLYPHS)

INSTANCES = range(3)

def instantiatePjs():
    canvas = document.createElement('canvas')
    document.body.appendChild(canvas)

    Processing.new(canvas, sketch)


def sketch(p):
    p.setup = MethodType(setup, p)
    p.draw = MethodType(draw, p)

    p.keyPressed = MethodType(keyPressed, p)
    p.mousePressed = MethodType(mousePressed, p)


def setup(p):
    p.size(150, 150)
    p.noLoop()

    p.fill(FG)
    p.textFont(FONT_TYPE, FONT_SIZE)
    p.textAlign(p.CENTER, p.CENTER)


def draw(p):
    p.background(BG)

    char = GLYPHS[int(p.random(GLY_LEN))]
    x, y = p.width >> 1, p.height >> 1

    p.text(char, x, y)


def keyPressed(p): p.redraw()
def mousePressed(p): keyPressed(p) # p.keyPressed()

for _ in INSTANCES: instantiatePjs()

2 Likes