// AGK 2.0.14b // Project: Throw It // MR 10.10.2015 spr=CreateSprite(0) SetSpriteSize(spr,10,10) SetSpritePositionByOffset(spr,50,50) SetSpriteColor(spr,255,0,0,255) sprground=createsprite(0) SetSpriteSize(sprground,100,5) SetSpritePosition(sprground,0,50+5) SetSpriteColor(sprground,192,128,64,255) Type TThrow action as integer spr as integer xstart as float ystart as float xdistance as float angle as float dir as float flyingheight as float endtype throw as TThrow throw.spr=spr do print("Click beside Sprite") if GetPointerPressed() throw.xstart=GetSpriteXByOffset(throw.spr) throw.ystart=GetSpriteYByOffset(throw.spr) throw.angle=0 throw.action=1 if GetPointerX()<throw.xstart then throw.dir = 1 if GetPointerX()>throw.xstart then throw.dir = -1 throw.xdistance = 20.0 throw.flyingheight= 5.0 endif ThrowIt(throw) Sync() loop end function ThrowIt(throw ref as TThrow) //print(throw.action) if throw.action=0 then exitfunction throw.angle = throw.angle + (360.0 / 60.0) //degrees per second (at 60 FPS) //print(throw.angle) if throw.angle => 180.0 then throw.action=0 x# = throw.xstart + sin((throw.angle / 2.0) * throw.dir ) * throw.xdistance y# = throw.ystart - sin(throw.angle) * throw.flyingheight if x#<GetSpriteWidth(throw.spr)/2.0 then x#=GetSpriteWidth(throw.spr)/2.0 if x#>GetVirtualWidth()-GetSpriteWidth(throw.spr)/2.0 then x#=GetVirtualWidth()-GetSpriteWidth(throw.spr)/2.0 SetSpritePositionByOffset(throw.spr,x#,y#) endfunction
// Clock-wise rotating line SetScreenResolution(1024, 768) Setvirtualresolution(640,480) SetSyncRate(60, 0) startX = 320 startY = 240 len = 100 angle = 90 do DrawEllipse(startX, startY, len, len, MakeColor(255, 255, 255), MakeColor(255, 255, 255), 0) angle = Mod(angle + 1, 360) x# = Cos(angle) * len y# = Sin(angle) * len Drawline(startX, startY , startX + x#, startY + y#,255,255,255) Print("Angle: " + Str(angle)) Sync() loop
// Project: Clock // Created: 22-01-17 // by Andrew van Dijk // show all errors // Usefull for using cos and sin to determine a point on a circle // General term // x = radius * cos(angle) // y = radius * sin(angle) SetErrorMode(2) // set window properties SetWindowTitle( "Clock" ) SetWindowSize( 1024, 768, 0 ) SetWindowAllowResize( 1 ) // allow the user to resize the window // set display properties SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders UseNewDefaultFonts( 1 ) SetVirtualResolution(100,100) SetDisplayAspect(1.333333) x1# = 50 //Center of screen y1# = 50 //Center of screen radius# = 20 // radius from center of circle to outside do for i = 0 to 359 step 30 angle# = i outerx# = x1# + radius# * cos(angle#) outery# = y1# + radius# * sin(angle#) * 1.333333 midx# = x1# + (radius#-1) * cos(angle#) midy# = y1# + (radius#-1) * sin(angle#) * 1.333333 DrawLine( midx#, midy#, outerx# , outery# , mod (i,255), mod (i,255), 255 ) next i time = GetUnixTime() second = GetSecondsFromUnix( time ) x0# = x1# + (radius#-1) * cos((-90)+(6 *second)) y0# = y1# + (radius#-1) * sin((-90)+(6 *second)) * 1.333333 DrawLine( x1#, y1#, x0# , y0# , mod (i,255), mod (i,255), 255 ) DrawEllipse(x0# ,y0# , 1,1 * 1.333333, MakeColor(255,64,mod (second,255),255) ,MakeColor(255,64,mod (second,255),255) ,1) minute = GetMinutesFromUnix( time ) x0# = x1# + (radius#-3) * cos((-90)+(6 * minute)) y0# = y1# + (radius#-3) * sin((-90)+(6 * minute)) * 1.333333 DrawLine( x1#, y1#, x0# , y0# , mod (i,255), mod (i,255), 255 ) hour = GetHoursFromUnix( time ) + 2 x0# = x1# + (radius#-6) * cos((-90)+(6 * 5 * hour)) y0# = y1# + (radius#-6) * sin((-90)+(6 * 5* hour)) * 1.333333 DrawLine( x1#, y1#, x0# , y0# , mod (i,255), mod (i,255), 255 ) Sync() loop