We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I've just started trying python mode, so I'm probably missing something very obvious, but essentially, my problem is that I can't seem to set the font. The code that pertains to my font looks something like this:
def setup (): font = createFont ("Numbers.ttf", width / 62)
def draw (): textFont (font, width / 62)
However, this gives me an error saying that font is not defined. I assumed that I couldn't use font outside of setup, so I tried putting "font = None" at the beginning, so that it would be a global variable, but then it just says that a null font was passed to textFont. I also can't put "font = createFont ("Numbers.ttf", width / 62)" at the beginning, because it must be in setup, and putting textFont in setup doesn't seem to work either. What am I doing wrong?
Answers
Well I sort of got it to work, using the create font tool, loadFont, and putting textFont in setup, but I would still like to know if it's possible to use a ttf, because from my understanding, ttf works better if the font will be scaled, and I do plan on scaling.
https://Forum.Processing.org/two/discussion/15473/how-to-format-code-and-text
In Python, when we assign a value to a variable, it's assumed to be
local
to its function, unless we declare it asglobal
. :-Bhttps://Py.Processing.org/reference/globals.html
But in case 'Numbers.ttf' is the only font you're gonna need in your whole sketch, you can simply use textFont() right there within setup(): :ar!
No need for any
global
font variable at all this time! :)>-Well now I feel really dumb. I just realized that "numbers.ttf" is not capitalized...