Use System variable in processing.py?

the codes in picture could be run successfully,but i am confused.
i don’t know why i could’t use System variable directly in processing.py.
i see the System variable could be used directly in java(processing).

help me.thank you very much!

1 Like
  • “System Variables” is merely a Processing’s “sugar” term.
  • Instead their actual nature is Java class instance fields.
  • That is, width, height, mouseX, sketchPath, etc. are simply fields from class PApplet:
    PApplet
  • When we assign a value to a variable outside a def we create a global variable:
    Globals \ Language (API)
  • If that variable happens to have the same name as a PApplet member, we end up overshadowing its corresponding __builtin__ property.
  • Once a PApplet member is overshadowed by a Python variable w/ the same name, we can still access the former via this or __builtin__ as a workaround:
width = 640 # global width overshadows __builtin__.width
print width, this.width # 640, 100

def setup():
    size(800, 600)
    print width, this.width, __builtin__.width # 640, 800, 800
    exit()
  • Anyways, regardless the Processing flavor we’re coding on, it just makes sense to access width & height after size() has been invoked:
    size() \ Language (API)
3 Likes

This is key. Don’t declare this globally. They exist globally already, and they are defined by size() in setup(). Call size, then use them.

3 Likes

Your words are clear,i understand now.
You are so nice.
Thank you very very very much.

1 Like

Thank you very much.

1 Like