(AGK version: 20170901)
Submitted: 2017-01-11 08:40:31
//***************************************************************
//** By Damo the Great
//** A Roational Stopwatch with some text movement effects - This will
//** create a clock face with drawing commands and the use of maths
//** to get the angle correctly
//** But most importantly, it builds up tweens to calculate around 
//** the clock face and every second, it will move round, changing colours
//** changing angles, and added a bit extra to create a Text Tween of which
//** you can easily programatically do wonderful things with TextTweens
//**
//** Example of various tween commands
//**
//** SetTweenSpriteXByOffset
//** SetTweenSpriteYByOffset
//** SetTweenSpriteAngle
//** SetTweenSpriteBlue
//** SetTweenSpriteRed
//** SetTweenSpriteGreen
//** CreateTweenSprite
//** CreateTweenChain
//** AddTweenChainSprite
//** UpdateTweenChain
//** PlayTweenChain
//** PlayTweenChain
//** UpdateAllTweens
//*************************************************************

// Lets setup the display
#Constant width=1024
#Constant height=768
SetWindowSize( width, height, 0 )
SetVirtualResolution( width, height )
 
tween as integer[60]

// Setup a starting location and colours
oldpositionx=width/2 : oldpositiony=height/2
beginx#=width/2
beginy#=height/2

// *******************************************************************
// Lets create a sprite first and position it somewhere on the screen
render()
DrawEllipse(0,0,50,50,makecolor(255,255,255),makecolor(255,255,255),1)

swap()
sprite = CreateSprite( getimage(0,0,50,50 ))
SetSpritePosition(sprite,oldpositionx,oldpositiony)
SetSpriteScale(sprite,.5,.5)
SetSpritePositionByOffset(sprite,50,50)
// *******************************************************************
//Setup a chain of tweens to follow on from one another in a sequence
chain=CreateTweenChain()

secstep=30 // 30 = as minute hands, 12 = hours, 6 = seconds
depth#=200 // the distance of the starting (centre of screen to the end
sec=secstep
// Lets setup the multiple of tweems depending how big you have set the tween array above

for tweens=1 to tween.length
	// Create a sprite tween first with a delay of 1 (so at least it starts)
	tween[tweens] = CreateTweenSprite( 1 )

	// Lets create a new position - This is how to work out Angles particularly for a 
	// clock face 
	endx#=width/2 -  depth# * cos(270-sec)
	endy#=height/2 + depth# * sin(270-sec) 
	inc sec,secstep
	
	// +30 cause a full circle is 360d and there are 12 hands in the hour hand - 360/12 = 30
	endcolour=random(1,255)

	// Setup the coordinates begin and end and interpolation
	// There are a few default interopulations with nice effects
	SetTweenSpriteXByOffset(tween[tweens],beginx#,endx#,TweenBounce())
	SetTweenSpriteYByOffset(tween[tweens],beginy#,endy#,TweenBounce())

	// Setup an angle for the sprite which will change the angle in one pass of the update
	SetTweenSpriteAngle(tween[tweens],220-secstep+sec,220-secstep+sec,TweenLinear())
	
	// For effect change the tween colour upon stages of the length
	// Starting at BeginColour and EndColour variables
	SetTweenSpriteBlue(tween[tweens],random(1,255),random(1,255),TweenSmooth1())
	SetTweenSpriteRed(tween[tweens],random(1,255),random(1,255),TweenSmooth1())
	SetTweenSpriteGreen(tween[tweens],random(1,255),random(1,255),TweenSmooth1())

	// When the for loop is finished --> Next then next rotation of the for loop the tween
	// commands need to remember where and what colour the tween finished up at and for it 
	// to start where it finished
	
	begincolour=endcolour
	beginx#=endx#
	beginy#=endy#
	
	AddTweenChainSprite( chain, tween[tweens], sprite, 0 )
	
next

// Mainloop to setup the clock and start the tweens
do
	// Make some lines for a clock face.
	for a=1 to 360 step secstep
		endx#=width/2 + (depth#-40) * cos(a)
		endy#=height/2 - (depth#-40) * sin(a) 
		drawline(width/2,height/2,endx#,endy#,makecolor(255,255,255),makecolor(0,0,0))
		DrawEllipse(endx#,endy#,5,5,makecolor(0,0,0),makecolor(0,255,255),1)
	next
	
	// We can play the tweens by running the chain event
    PlayTweenChain( chain )
	
	UpdateAllTweens(GetFrameTime())
    Sync()
loop
Help make AGK better by submitting an example for this command!
(All examples are subject to approval)
Login to post an example of your own.