Post by eyfenna on Oct 23, 2016 6:16:09 GMT -6
After watching a analog clock tutorials for other languages I decided to code my own in RCBasic, the pictures and font are in the attached zip file.
function displayhourlines()
for i = 0 to 11
angle = i * 360/12
radangle = -1*angle*3.1415926/180
drawImage_Rotate(1, 295+150*sin(radangle),225+150*cos(radangle),angle)
next
end function
function displayminutelines()
for i = 0 to 59
angle = i *360/60
radangle = -1*angle*3.1415926/180
drawImage_Rotate(0, 295+150*sin(radangle),225+150*cos(radangle),angle)
next
end function
function drawtime()
textwidth=0
textheight=0
currentTime$ = Time$()
currentHour$ = Mid$(currentTime$,0,2)
currentMinute$ = Mid$(currentTime$,3,2)
currentSecond$ = Mid$(currentTime$,6,2)
curHour = Val(currentHour$)
curMinute= Val(currentMinute$)
curSecond = Val(currentSecond$)
GetTextSize(0,currentTime$,textwidth,textheight)
Font(0)
setcolor(rgb(0,0,0))
drawText(currentTime$,320-textwidth/2,440-textheight/2)
angleHour = (curHour mod 12) *360/12
angleMinute = curMinute *360/60
angleSecond = curSecond *360/60
drawImage_rotate(2,296,240-175,angleSecond)
drawImage_rotate(3,295,240-150,angleMinute)
drawImage_rotate(4,293,240-120,angleHour)
end function
windowopen(0,"analog clock",windowpos_centered,windowpos_centered,640,480,0)
canvasopen(0,640,480,0,0,640,480,0)
loadImage(0,"clock media/minuteline.png")
loadImage(1,"clock media/hourline.png")
loadImage(2,"clock media/secondhand.png")
loadImage(3,"clock media/minutehand.png")
loadImage(4,"clock media/hourhand.png")
loadFont(0,"clock media/zekton rg.ttf",20)
while true
clearcanvas()
setcolor(rgb(255,255,255))
BoxFill(0,0,640,480)
displayhourlines()
displayminutelines()
drawtime()
update()
if key(k_escape) then
end
end if
wend