ThePoopLord [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=58025 funny code <h2>ello</h2> <p>I made a half working cart about bezier curves and wanted to see what people think about my code, so if you want to pls give feedback</p> <h3>note: you can add points by using the up and down arrow keys then move the points by using the mouse and cycle between them using X and O</h3> <div> <div class=scrollable_with_touch style="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>--bezier curve time function clone(t)--clone a table return{unpack(t)} end function lerp(s,e,m) return s*(1-m)+e*m end function lerp2d(p1,p2,t)--lerp lx=lerp(p1[1],p2[1],t)--two 2d ly=lerp(p1[2],p2[2],t)--points return lx,ly end poke(0x5f2d,1) --devkit mouse p1={64,64} --first point ptt={ p1} --point table pts=0 --number of desired points ind=1 --index used for selected point t=.5 --time value used across lerps function lerpcheck()--lerp the points po1=lerp2d(ptt[1],ptt[2],t) l=#ptt-2 for i=0,#ptt-1,1 do if(ptt[i+2]~=nil)lx,ly=lerp2d(ptt[i+1],ptt[i+2],t) --lx stands for lerped x circ(lx,ly,2,11) if(llx and lx~=po1)line(llx,lly,lx,ly,11) llx=lx --last lerped x lly=ly l-=1 end if l&gt;0 then lx2,ly2=lerp2d({lx,ly},{llx,lly},t) circ(lx2,ly2,2,12) line(lx,ly,lx2,ly2,12) l-=1 end end function drawp(p)--visualize points circ(p[1],p[2],3,7) if lp==nil then --last point elseif p~=p1 then line(lp[1],lp[2],p[1],p[2],7) lerpcheck(lp,p,t) end lp=p --update most recent point end function respts()--called when for i=1,pts,1do--points get added pt=clone(p1)--or removed add(ptt,pt) end end function _update60() mx=stat(32)my=stat(33) if(btnp(🅾️)and ind&gt;1)ind-=1--change selected if(btnp(❎)and ind&lt;#ptt)ind+=1--point if(btnp(⬆️))pts+=1ptt={ p1}respts()--add/remove if(btnp(⬇️))pts-=1ptt={ p1}respts()--points if(btnp(⬅️)and t&gt;.05)t-=.05 if(btnp(➡️)and t&lt;.95)t+=.05 end function _draw() cls() spr(0,mx,my) sp=ptt[ind] --selected point if(sp)?&quot;\^i#&quot;..ind..&quot; selected&quot;,sp[1]+5,sp[2]+5,7 foreach(ptt,drawp) if(stat(34)~=0 and ptt[ind])then sp[1]=mx --move point sp[2]=my end end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=48983 https://www.lexaloffle.com/bbs/?tid=48983 Sun, 21 Aug 2022 10:44:49 UTC