hard_reaction_test.py

Created by elnix91

Created on September 28, 2025

2.62 KB

A simple reaction test to measure your reaction speed. Use OK or EXE to interact, and Shift and left and right arrows in the menu. If you are on Omega or Upsilon, the best results are automatically saved in a file named “rt.sav” Don’t hesitate to tell me if you find any bug on discord or by mail: elnix91@gmail.com


from kandinsky import draw_string as txt,fill_rect as rect
from time import *
from random import randrange as r,randint as ra
from ion import keydown as k

SKY=(0,0,0)
IMP=(0,255,0)
TXT=(255,)*3
v=lambda:k(4)|k(52)
s=lambda:k(0)|k(3)
save="rt.sav"

try:
  import os
  OS=1
except:OS=0



def switch(x,y,on):
  rect(x,y,23,23,TXT)
  rect(x+2,y+2,19,19,SKY)
  if on:rect(x+4,y+4,15,15,IMP)
  else:rect(x+4,y+4,15,15,(50,50,50))

while 1:

  while v():1
  rect(0,0,320,222,SKY)
  txt("Press ok to play",80,60,IMP,SKY)
  txt("Harder:",50,130,TXT,SKY)
  txt("[Shift]",130,130,(195,50,50),SKY)
  txt("Number of tests:    <  >",50,160,TXT,SKY)
  Hard=0
  N=4
  first=1
  while not v():
    if s()|first:
      N=(N-k(0)+k(3))%7
      txt(str(N+1),265,160,(255,0,0),SKY)
      while s():1
    if k(12)|first:
      Hard=not Hard
      switch(258,130,Hard)
      while k(12):1
    if first:first=0
  T=[]
  N+=1
  for i in range(N):
    rect(0,0,320,222,(255,0,0))
    txt("React when green",80,100,TXT,SKY)
    rect(190,121,50,1,TXT)
    txt("[OK]",140,150,IMP,SKY)
    txt(str(i+1)+"/"+str(N),0,0,TXT,(255,0,0))

    while v():1
    while not v():1
    rect(140,150,40,20,(255,0,0))

    b=monotonic()
    t=r(1,10)
    ok=True
    while v():1
    while monotonic()-b<t:
      if (ra(0,1000)==0)&((monotonic()-b)<(t-1))&Hard:
        rect(0,0,320,222,(ra(0,255),0,ra(0,255)))
      if v():
        ok=False
        T.append(10000)
        for j in range(25):
          rect(0,0,320,222,(255,0,0))
          txt("Trop tot!",115,100,SKY,(255,0,0))
          sleep(0.01)
          rect(0,0,320,222,SKY)
          txt("Trop tot!",115,100,(255,0,0),SKY)
          sleep(0.01)
        break
    if ok:
      rect(0,0,320,222,(0,255,0))
      a=monotonic()
      while not v():1
      re=monotonic()-a
      T.append(round(re*1000))

  m=round(sum(T)/N)
  rect(0,0,320,222,SKY)
  txt(str(m)+" ms",160-len(str(m))*5-15,110,SKY,(0,255,0))
  if N>1:
    txt("Av. Reaction time:",70,80,IMP,SKY)
    txt("Times:",135,140,IMP,SKY)
    txt(" ".join([str(T[i])for i in range(N)]),0,180,(255,0,0),SKY)
  else:
    txt("Reaction time:",90,80,IMP,SKY)
  if OS:
    if save in os.listdir():
      with open(save,"r")as f:
        A=f.read().split(",")
        A[0]=int(A[0])
        A[1]=int(A[1])
#        A.append(int(B[0])
#        A.append(float(B[1]))
    else:A=[10000,10000]
    if N>1:
      if m<A[0]:
        txt("YOU BEAT BEST AVERAGE!",50,5,(255,255,0),SKY)
        A[0]=m
    if min(T)<A[1]:
      txt("YOU BEAT BEST SCORE!",60,25,(255,255,0),SKY)
      A[1]=min(T)
    with open(save,"w")as f:
      f.write(str(A[0])+","+str(A[1]))


  while v():1
  while not v():1

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.