xyzzy [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=12187 Q: function for positive to negative <p>I'm trying to write a function to switch negative to positive and vise-versa. I've got:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> foot=3 function switch(f) f*=-1 end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>when I call switch(foot) it returns the original value but if at the command prompt I type &quot;foot*=-1 it preforms as expected.</p> <p>Thanks for any help and sorry for these remedial questions.</p> <p>--<br /> -john</p> https://www.lexaloffle.com/bbs/?tid=29452 https://www.lexaloffle.com/bbs/?tid=29452 Fri, 09 Jun 2017 01:49:35 UTC Q: orbiting around a point <p>I would like to create a function that would move one point in along a circle around another, but lack the math know how.</p> <p>here's what I have cobbled together from examples elsewhere and a little help, hopefully at least my intentions are clear (the inc=increment would let me fiddle with how fast p2 travels)</p> <p>point1={}<br /> point1.x=68<br /> point1.y=78</p> <p>point2={}<br /> point2.x=57<br /> point2.y=43</p> <p>function orbit(p1, p2, inc)<br /> distance = sqrt((p1.x-p2.x)<em>(p1.x-p2.x) + (p1.y-p2.y)</em>(p1.y-p2.y))<br /> ang= atan2(p2.y, p2.x) - atan2(p1.y, p2.x)<br /> p2.x=(p1.x + distance <em> cos(ang+inc))<br /> p2.y=(p1.y + distance </em> sin(ang+inc))<br /> end</p> <p>function _update()<br /> orbit(point1, point2, .01)<br /> end</p> <p>function _draw()<br /> line(point1.x, point1.y, point2.x, point2.y, 7)<br /> end</p> <p>--<br /> -john</p> https://www.lexaloffle.com/bbs/?tid=29443 https://www.lexaloffle.com/bbs/?tid=29443 Thu, 08 Jun 2017 03:13:05 UTC