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

Rotate is anticlockwise

Posted by Stu on Sep 21, 2009

Rotate seems to work anticlockwise - this isn't mentioned in the documentation and seems non-obvious.

I'd suggest having clockwise rotations (doing things in the obvious way seems more pythonic).

Obviously this may break compatibility with some bots though, if this is a big enough break it might be worth considering lumping similar behaviour changing things together (no examples here, but I'm sure there have been other api suggestions)


 

Posted by Josh Caswell on Sep 23, 2009

It's Cocoa's fault. NSAffineTransform goes CCW. However, for whatever reason, the Transform NodeBox object does go clockwise, you just need to do some translations before and after to rotate things about their own centers. Try this out:

from __future__ import division
 
fill(None)
stroke(0)
 
var("angle", NUMBER, 35, 1, 180)
 
rx, ry = 100,100
rw, rh = 400,200
r = rect(rx, ry, rw, rh, draw=False)
 
delta_x = rx + (rw/2)
delta_y = ry + (rh/2)
 
t, tp, ta = Transform(), Transform(), Transform()
 
tp.translate(-delta_x, -delta_y)
ta.translate(delta_x, delta_y)
 
t.rotate(degrees=angle)
 
t.prepend(tp)
t.append(ta)
 
r = t.transformBezierPath(r)
r.draw()
Some explanation of this (by me), if you need it, can be found in this old forum post. Hope that helps!