Re: Adding modular functionality to the RGB knobs in the demo
Status: Alpha
Brought to you by:
cwalther
From: Christian W. <cwa...@gm...> - 2011-11-18 20:13:26
|
IndianaScones wrote: > I am attempting to change the behavior of the RGB knobs in the building. > Instead of a smooth range of motion, I would like to make them each have 4 > settings (when you click and drag a knob, it jumps through each of the 4 > settings). Each of these settings will play a different looped audio track. > The key in the doorway behind you (when at the controls) will be invisible > at first, but it will appear when you have set the knobs to the correct > combination. > > Here is an example of what I'm trying to accomplish (the settings with > asterisks would be the secret combination): > http://old.nabble.com/file/p32859425/screen.jpg > > ... > > It may be a lot of help to ask for (I don't know), but if someone can even > point me in the right direction, I would greatly appreciate it. When I look > at all that stuff in node 18 dealing with the RGB controls, I am completely > lost. I understand - there is a bit of math involved in moving something on a circle, and then there is the animated gauge and all that adding more complexity to the script of node 18. Here's a replacement mousestilldown function for the red knob that snaps the knob to five regularly spaced positions on its circle, and hopefully makes things a bit clearer with the comments: onmousestilldown = function() -- center of the circle local x0, y0 = 219, 422 -- mouse location relative to the center of the circle local x, y = pipmak.mouseloc() x = x - x0 y = y - y0 -- if the mouse is exactly in the center, treat it as slightly above if x == 0 and y == 0 then y = -1 end -- angle, clockwise from the top, in radians ([0..2*pi)) local a = math.atan2(x, -y) -- angle in fifth-circles ([0..5)) a = a/(2*math.pi)*5 -- round to the closest whole number a = math.floor(a + 0.5) -- convert back to radians a = a/5*2*math.pi -- convert from angle back to coordinates ([-1..1]) x = math.sin(a) y = -math.cos(a) -- place the knob: center of the knob on a circle of radius 21 around the center coordinates, therefore its top left corner 8 pixels offset from that horizontally and vertically redknob:moveto(x0 + x*21 - 8, y0 + y*21 - 8) end To have irregularly spaced positions, as you depict, instead of rounding the angle to the nearest whole number, you need to check if it's inside each of the five ranges individually, and then snap it to the respective position. Does that help? -Christian |