Try something new. NodeBox 2 Beta - Now Available for Download

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!

 



Add comment