timer.py

Created by ziii

Created on February 19, 2022

1.36 KB

A basic timer with a round clock counting seconds and a digital clock with the amount of hours minutes and second elapsed.

How to use :

Ok to start or stop the timer.


from time import *
from math import *
from kandinsky import *
from ion import *
def draw_circle(r,pos,c):
  for x in range(0,r):
    y=((r**2)-(x**2))**0.5
    set_pixel(pos[0]+int(x),pos[1]+int(y),c)
    set_pixel(pos[0]+int(x),pos[1]-int(y),c)
    set_pixel(pos[0]-int(x),pos[1]+int(y),c)
    set_pixel(pos[0]-int(x),pos[1]-int(y),c)
    set_pixel(pos[0]+int(y),pos[1]+int(x),c)
    set_pixel(pos[0]+int(y),pos[1]-int(x),c)
    set_pixel(pos[0]-int(y),pos[1]+int(x),c)
    set_pixel(pos[0]-int(y),pos[1]-int(x),c)
def radius_circle(deg,pos,r,col):
  deg-=90
  deg*=3.14/180
  si=sin(deg)
  co=cos(deg)
  [set_pixel(int(x*co+pos[0]),int(si*x+pos[1]),col) for x in range(0,r)]
run=0
draw_string("OK to start timer",0,0)
sleep(0.2)
while 1:
  if run:
    if keydown(KEY_OK):
      run=0
      fill_rect(0,0,320,222,color(255,255,255))
      draw_string("OK to start timer",0,0)
      sleep(0.2)
    elif monotonic()-tick>sec+1:
      sec=int(monotonic()-tick)
      draw_string("{}:{}:{}{}".format(sec//3600,sec//60,""if sec%60>9 else "0",sec%60),0,0)
      radius_circle(int(6*((sec-1)%60)),[160,111],110,color(255,255,255))
      radius_circle(int(6*(sec%60)),[160,111],110,color(0,0,0))
  else:
    if keydown(KEY_OK):
      run=1
      sec=-1
      tick=monotonic()
      fill_rect(0,0,320,222,color(255,255,255))
      draw_circle(110,[160,111],color(0,0,0))
      sleep(0.25)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.