reaction_test_v2.py

Created by elnix91

Created on April 18, 2025

3.96 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 elnix91@gmail.com


from kandinsky import draw_string as txt,fill_rect as rect
from time import sleep,monotonic
from random import randrange as r,randint as ra
from ion import keydown as k
SKY,IMP,TXT,RED,GRE,CYA,MAG,YEL=(0,0,0),(0,255,0),(255,)*3,(255,0,0),(0,255,0),(0,255,255),(195,50,50),(255,255,0)
v=lambda:k(4)|k(52)
s=lambda:k(0)|k(3)
save="rt.sav"
sa=1
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))
def dBestScore(s):
  if s==-1:s="Na"
  txt("Best score:",40,5,CYA,SKY)
  txt(str(s),170,5,RED,SKY)
def dBestAverage(a):
  if a==-1:a="Na"
  txt("Best average:",40,25,CYA,SKY)
  txt(str(a),180,25,RED,SKY)

if OS:
  if save in os.listdir():
    A=[[],[]]
    with open(save,"r")as f:
      B=f.read().split(",")
      for i in range(2):
        C=B[i].split("/")
        for j in range(7):
          D=C[j].split("(")
          A[i].append([int(D[0]),int(D[1])])
    sa=0
if sa:A=[[[-1,-1] for i in range(7)]for i in range(2)]

N=5
Hard=1
while 1:
  N-=1
  while v():1
  rect(0,0,320,222,SKY)
  txt("Press [OK] or [EXE] to play",25,100,IMP,SKY)
  txt("Harder:",50,170,TXT,SKY)
  txt("[Shift]",130,170,MAG,SKY)
  txt("Number of tests:    <  >",50,200,TXT,SKY)
  switch(258,170,Hard)
  first=1
  while not v():
    if s()|first|k(12):
      N=(N-k(0)+k(3))%7
      txt(str(N+1),265,200,RED,SKY)
      rect(40,5,280,50,SKY)
      if k(12):
        Hard=not Hard
        switch(258,170,Hard)
      if N>0:
        dBestAverage(A[0][N][Hard])
      dBestScore(A[1][N][Hard])
      while s()|k(12):1
    if first:first=0
  T=[]
  N+=1
  for i in range(N):
    rect(0,0,320,222,RED)
    txt("Test",120,100,TXT,RED)
    txt(str(i+1)+"/"+str(N),170,100,CYA,RED)
    txt("[OK]",140,150,IMP,RED)
    while v():1
    while not v():1

    txt("Wait for green",90,100,TXT,RED)
    rect(180,121,50,1,TXT)
    rect(140,150,40,20,RED)
    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,RED)
          txt("TOO SOON!!",110,50,SKY,RED)
          txt("YOU SUCH A FAILURE!",65,70,SKY,RED)
          txt("YOU SHOULD QUESTION",65,90,SKY,RED)
          txt("YOUR LIFE!",110,110,SKY,RED)
          txt("YOU AREN'T EVEN ABLE TO",45,130,SKY,RED)
          txt("RECOGNISE GREEN COLOR!",50,150,SKY,RED)
          sleep(0.01)
          rect(0,0,320,222,SKY)
          txt("TOO SOON!!",110,50,RED,SKY)
          txt("YOU SUCH A FAILURE!",65,70,RED,SKY)
          txt("YOU SHOULD QUESTION",65,90,RED,SKY)
          txt("YOUR LIFE!",110,110,RED,SKY)
          txt("YOU AREN'T EVEN ABLE TO",45,130,RED,SKY)
          txt("RECOGNISE GREEN COLOR!",50,150,RED,SKY)
          sleep(0.01)
        break
    if ok:
      rect(0,0,320,222,GRE)
      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,GRE)
  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,RED,SKY)
  else:
    txt("Reaction time:",90,80,IMP,SKY)
  if Hard:txt("Harder was enabled",65,60,MAG,SKY)
  if (N>1)&((m<A[0][N-1][Hard])|(A[0][N-1][Hard]==-1)):
    txt("YOU BEAT BEST AVERAGE!",50,25,YEL,SKY)
    A[0][N-1][Hard]=m
  elif N>1:
    dBestAverage(A[0][N-1][Hard])
  if (min(T)<A[1][N-1][Hard])|(A[1][N-1][Hard]==-1):
    txt("YOU BEAT BEST SCORE!",60,5,YEL,SKY)
    A[1][N-1][Hard]=min(T)
  else:
    dBestScore(A[1][N-1][Hard])
  if OS:
    with open(save,"w")as f:
      z=""
      for i in range(2):
        for j in range(7):
          z+=str(A[i][j]).replace(",","(")
          if j<6:z+="/"
        if i<1:z+=","
      f.write(z.replace("[","").replace("]","").replace(" ",""))
  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.