Post Reply 
Calculator graphics drawing benchmark
09-09-2023, 10:19 PM
Post: #45
RE: Calculator graphics drawing benchmark
The Numworks graphing calculator, using the fill_rect() function in Python, has a possible 2nd place time - 0.308 seconds.

Because the Hitomezashi algorithm only uses horizontal and vertical lines, fill_rect() can be used, because horizontal and vertical lines are essentially flat rectangles.

I used the monotonic() function to measure the time consumed.

I had to add a sleep(0.25) delay before reading key presses at the end, because it seems that the program runs so quickly that when you press the OK key to run the program, if you're not quick enough, that same key press is read by the calculator to then display the start and finish times.

Code:
 
from kandinsky import *
from random import *
from time import *
from ion import *

colr=['white','black','red']

        

def hitomezashi():
  color(0,0,255)
  kolr=1
  while 1:
    s=int(input("s="))
      
    n=monotonic()
    for y in range(0,225,s):
      i=s*randint(0,1)
      for x in range(i,320,2*s):
        fill_rect(x,y,s,1,colr[1])
    for x in range(0,320,s):
      i=s*randint(0,1)
      for y in range(i,225,2*s):
        fill_rect(x,y,1,s,colr[1])
    k=monotonic()
    sleep(0.25)
    while 1:
      if keydown(KEY_OK):
        break
  print(n)
  print(k)
hitomezashi()
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Calculator graphics drawing benchmark - arhtur - 09-09-2023 10:19 PM



User(s) browsing this thread: 1 Guest(s)