1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

What is _ctx?

Posted by Benjamin on Jan 05, 2011

Hi,

I'm currently looking at the source code of the lsystem library.
There, I've stumbled upon '_ctx'.
An example is

elif rule == "|": _ctx.rotate(180)

From the expression itself I think it's about some context, but I don't get what it actually is.

Best,
Benjamin


 
Posted by Josh Caswell on Jan 10, 2011

You're right. There's a Context object which maintains a bunch of state for the running script. Things like fill and stroke colors, stroke width, transformations. It is also what allows you call oval and rect without having to import anything.

_ctx is the name of the instance that exists when your script is run. You can access it yourself if you want, just like any other variable. (for example, you can say _ctx.oval(10,10,10,10). You'll find the definition of Context in the NodeBox source code, (in file /src/nodebox/graphics/__init__.py) which you can get at http://dev.nodebox.net/