Snap to Position by Markus26th Jan 2013 8:18
|
---|
Summary point snap & linecross Description point snap & linecross etc. with example Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com rem rem AGK Application 1.08 Beta rem rem MR 26.01.2013 Test() end Function Test() do Print("hello snap") x#=getpointerx() y#=getpointery() PrintXY("mouse",x#,y#) DrawCrossLine(x#,y#,255,255,0) x#=SnapToGridX(x#,5) y#=SnapToGridY(y#,5) PrintXY("snap",x#,y#) DrawCrossLine(x#,y#,255,128,64) Sync() loop endfunction function SnapToGridX(x#,distance#) //example snapping x positions x#=Snap( 0.0,x#,distance#) x#=Snap( 10.0,x#,distance#) x#=Snap( 20.0,x#,distance#) x#=Snap( 30.0,x#,distance#) x#=Snap( 40.0,x#,distance#) x#=Snap( 50.0,x#,distance#) x#=Snap( 60.0,x#,distance#) x#=Snap( 70.0,x#,distance#) x#=Snap( 80.0,x#,distance#) x#=Snap( 90.0,x#,distance#) x#=Snap(100.0,x#,distance#) endfunction x# function SnapToGridY(y#,distance#) //example snapping y positions y#=Snap( 0.0,y#,distance#) y#=Snap( 10.0,y#,distance#) y#=Snap( 20.0,y#,distance#) y#=Snap( 30.0,y#,distance#) y#=Snap( 40.0,y#,distance#) y#=Snap( 50.0,y#,distance#) y#=Snap( 60.0,y#,distance#) y#=Snap( 70.0,y#,distance#) y#=Snap( 80.0,y#,distance#) y#=Snap( 90.0,y#,distance#) y#=Snap(100.0,y#,distance#) endfunction y# function Snap(sn#,a#,distance#) //MR 26.01.2013 //snap position sn# //position a# //snapping <= distance# if abs(sn#-a#)<=distance# a#=sn# endif endfunction a# function DrawCrossLine(x#,y#,r,g,b) //MR 26.01.2013 //draw a cross drawline(x#,0,x#,100,r,g,b) drawline(0,y#,100,y#,r,g,b) endfunction function PrintXY(text$,x#,y#) //MR 26.01.2013 //print text and the x and y value print(text$) print("X:"+str(x#)) print("Y:"+str(y#)) endfunction |