Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Is there a way to manipulate objects on the dynamic lighting layer?

I'd like to make a map where some images are in constant motion (turning) and I'd like their dynamic lighting to turn with them.  Imagine a rotating pillar with a recessed light source that shines in a narrow 90 degree cone.  It will light up different parts of the map as it turns.  Is this possible?
1459273255

Edited 1459273403
Lithl
Pro
Sheet Author
API Scripter
When rotating a DL wall, in order to make the page's lighting respect the new angle, you have to manipulate the _path. And, since _path is read-only, you have to create a new path (presumably deleting the old one). Here's a set of functions Aaron wrote to manipulate the _path for rotations: function bounds(p){     return _.reduce(p,function(m,p){         m.minX=Math.min(p[1],m.minX);         m.minY=Math.min(p[2],m.minY);         m.maxX=Math.max(p[1],m.maxX);         m.maxY=Math.max(p[2],m.maxY);         return m;     },{minX:Infinity,maxX:0,minY:Infinity,maxY:0}); } function center(bounds){     return {         x: bounds.minX + ((bounds.maxX-bounds.minX)/2),         y: bounds.minY + ((bounds.maxY-bounds.minY)/2)     }; } function rotate(p,theta){     var b=bounds(p),         c=center(b),         sinT=Math.sin( theta*Math.PI/180.0),         cosT=Math.cos( theta*Math.PI/180.0),         newBounds={             minX:Infinity,             minY:Infinity,             maxX:0,             maxY:0         },         points =_.chain(p)             .map(function(point){                 var pointPrime=_.clone(point);                 pointPrime[1]=cosT*(point[1]-c.x) - sinT*(point[2]-c.y) + c.x;                 pointPrime[2]=sinT*(point[1]-c.x) + cosT*(point[2]-c.y) + c.y;                 newBounds.minX=Math.min(pointPrime[1],newBounds.minX);                 newBounds.minY=Math.min(pointPrime[2],newBounds.minY);                 newBounds.maxX=Math.max(pointPrime[1],newBounds.maxX);                 newBounds.maxY=Math.max(pointPrime[2],newBounds.maxY);                 return pointPrime;             })             .map(function(p){                 p[1]-=newBounds.minX;                 p[2]-=newBounds.minY;                 return p;             })             .value(),         newCenter=center(newBounds);     return {         path: points,         bounds: newBounds,         center: newCenter,         offset: {             x: newCenter.x-c.x,             y: newCenter.y-c.y         }     }; } So, given a path object path  and an angle theta , you would use it like this: var details = rotate(JSON.parse(path.get('path')), theta); createObj('path', { pageid: path.get('pageid'),     fill: path.get('fill'),     stroke: path.get('stroke'),     rotation: path.get('rotation'),     layer: path.get('layer'),     stroke_width: path.get('stroke_width'),     width: details.bounds.maxX - details.bounds.minX,     height: details.bounds.maxY - details.bounds.minY,     path: JSON.stringify(details.path),     top: path.get('top') + details.offset.y,     left: path.get('left') + details.offset.x,     scaleX: 1,     scaleY: 1 }); path.remove(); From there it's simply a matter of rotating the path on a set interval using setInterval( func , delay ) . Note: The above rotation function only works correctly for polygons and polylines. Circles, ovals, and freehand drawings get really  funky if you try to rotate them with it (because it's not also moving their curve control points correctly). However, freehand drawings are not usable on the DL layer through the interface, and circles/ovals don't operate correctly with the page's lighting anyway, so that shouldn't be a huge issue.
Thanks a bunch, I'll give it a try.  Never really got into using underscore or lodash regularly.  It looks like the API lets you use one of them?
1459276575
The Aaron
Pro
API Scripter
Underscore, yeah.
Thanks.  Is it worth learning the Underscore API given that it superficially  appears that more recent versions of JS/ECMAScript have a lot of the utility of the library built in?
1459279544
The Aaron
Pro
API Scripter
I believe it is still very useful.  It provides more of a functional programing paradigm than some of the ES6 stuff, which I think lends itself well to many problems you need to solve in API scripts.  Additionally, many of it's features provide simpler interfaces or more convenient shorthand forms.  Certainly, knowing more about underscore won't hurt you any when writing scripts. =D
I guess I will start fooling around with it then.  Trying to grok REST / Web API / typescript / angular 2 / React / gulp / grunt / etc these days at work, what's one more library =).
i've done something similar where instead of rotating the dynamic lighting walls, I moved it to the GM field as a transparent brush. The setup was a series of paths in a dungeon that rotated when the players interacted with a statue. There were only two possibilities for the rotation (North-South or East-West) so every rotation moved the dynamic lighting items of a specific color to the gm layer as transparent and whatever was transparent on the GM layer to the DL layer as the specific color (orange I think).  If you have multiple positions or want to drag an item around you'll have to do the above.
Joshua V. said: i've done something similar where instead of rotating the dynamic lighting walls, I moved it to the GM field as a transparent brush. The setup was a series of paths in a dungeon that rotated when the players interacted with a statue. There were only two possibilities for the rotation (North-South or East-West) so every rotation moved the dynamic lighting items of a specific color to the gm layer as transparent and whatever was transparent on the GM layer to the DL layer as the specific color (orange I think).  If you have multiple positions or want to drag an item around you'll have to do the above. That's great, did you do that manually or did you script it?