bigfontcalculator.py

Created by wperez274

Created on July 11, 2023

5.95 KB

big font calculator. graphical user interface.

[Arrow] keys = increase, decrease numbers. [Backspace] = Reset both integers to zero.


from math import *
from kandinsky import *
from kandinsky import fill_rect as F
from random import *
from random import randint as RAND
from ion import *
from time import *

BL=(0,0,0)
WH=(255,)*3
GR=(230,)*3
RE=(155,0,0)

def dot(x,y,c,fg,bg,t,a,b):
  draw_string(c,0,0,GR,WH)
  fill_rect(x,y,9*t,18*t,bg)
  for v in range(18):
    for u in range(9):
      if get_pixel(u,v)==WH:
        fill_rect(x+u*t,y+v*t,t-a,t-b,fg)
        
  draw_string(" ",0,0,WH,WH)
  
  
def aff(txt,x,y,t,fg,bg=WH,a=1,b=1):
  for (i,c) in enumerate(txt):
    dot(x+i*t*9,y,c,fg,bg,t,a,b)
    
    
x=20

num=0
num_2=0


def refresh():
  aff(str(numbers[num])+" + "+str("2"),20,105,3,RE,b=0)




#aff("GAME OVER",x,-5,3,(0,255,0),BL)
#for i in range(26):
#  aff(chr(97+i),25+10+i,132,1,BL,GR,0,0)
#  aff(chr(65+i),25+10*i,172+30*(i%2)-15,2,[BL,RE][i%2],a=0)


arith=["*","/","+","-"]

func=0
oper=arith[func]


bg=(240,)*3




def clear_scr():
  F(0,83,322,104,bg)

#  fill_rect(0,105,322,50,bg)


#  F(0, 0, 322, 222,(0,255,255))
#  F(0, 77, 322, 116, 'black')
#  F(0, 83, 322, 104, (240,)*3)





font_bg_c=(0,)*3
font_c=(255,)*3

#fill_rect(0,0,322,222,bg)






F(0, 0, 322, 222,(0,255,255))
F(0, 77, 322, 116, 'black')
F(0, 83, 322, 104, (240,)*3)

aff(str(int(num))+arith[0]+str(int(num_2))+"="+str(int(num*num_2)),20,105,3,(220,)*3,(0,)*3)#b=0)

speed_t=0.2

while not keydown(KEY_EXE):
  oper=arith[func]
  
  if func==1 and num_2==0:
    num_2=1



#*************************

  if keydown(KEY_MULTIPLICATION):
    func=0
    clear_scr()
    F(0,0,322,50,(255,0,0))
    aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num*num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)

    aff("Multiplication",20,5,2,font_c,font_bg_c)
    
  if keydown(KEY_DIVISION):
    func=1
    clear_scr()
    F(0,0,322,50,(0,255,0))

    if func==1 and num_2==0:
      num_2=1

    aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(float(num/num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)

    aff("Division",20,5,2,font_c,font_bg_c)


  if keydown(KEY_PLUS):
    func=2
    clear_scr()
    F(0,0,322,50,(255,255,0))

    aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num+num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)
    aff("Addition",20,5,2,font_c,font_bg_c)


  if keydown(KEY_MINUS):
    func=3
    clear_scr()
    F(0,0,322,50,(0,0,255))

    aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num-num_2)),20,105,3,font_c,font_bg_c)#font_c,b=0)
    aff("Subtraction",20,5,2,font_c,font_bg_c)



#*************************
  if keydown(KEY_UP):
    speed_t-=0.01
    sleep(speed_t)
    if speed_t<0.0005:
      speed_t=0.0005
    num+=1
          
    
    if func==0:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num*num_2)),10,105,3,font_c,font_bg_c)#(0,0,0))#b=0)
    if func==1:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(float(num/num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)

    if func==2:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num+num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)

    if func==3:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num-num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)




  if keydown(KEY_DOWN):
    sleep(0.2)
  
    num-=1
    
    if func==0:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num*num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)
    if func==1:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(float(num/num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)

    if func==2:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num+num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)

    if func==3:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num-num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)


  if keydown(KEY_LEFT):
    sleep(0.2)
    num_2-=1
    if func==0:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num*num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)
    if func==1:
      clear_scr()
      if num_2==0:
        num_2=-1
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(float(num/num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)
    if func==2:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num+num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)
    if func==3:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num-num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)



  if keydown(KEY_RIGHT):
    sleep(0.2)
    num_2+=1
    if func==0:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num*num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)


    if func==1:
      clear_scr()
      if num_2==0:
        num_2=1
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(float(num/num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)

    if func==2:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num+num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)
    if func==3:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num-num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)

    
  if keydown(KEY_BACKSPACE):
    sleep(0.2)
    num=0
    num_2=0
    if func==0:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num*num_2)),10,105,3,font_c,font_bg_c)#(0,0,0))#b=0)
    if func==1:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(float(num/num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)
    if func==2:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num+num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)

    if func==3:
      clear_scr()
      aff(str(int(num))+arith[func]+str(int(num_2))+"="+str(int(num-num_2)),10,105,3,font_c,font_bg_c)#font_c,b=0)

    
  

draw_string("Press [OK]",100,190)

print("")  
print("bg=",bg)
print("font_c=",font_c)

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.