fromkandinskyimportfill_rectasf,set_pixelass_pfromionimport*fromtimeimport*"""""
I imported fill_rect as f and set_pixel as s_p to save space,
you can do the same or change it in every program
"""""defdraw(arr,coo,cor,le,col,r,scale):a=r%2ifcor[nota]+le[nota]>=coo[nota]+coo_r(arr[-1*(r//2)]*scale,r)[nota]andcoo[nota]+coo_r(arr[-1+r//2]*scale,r)[nota]>=cor[nota]:forlinarr:forsinrange(scale):ifle[nota]>coo[nota]+coo_r(l,r)[nota]*scale+s-cor[nota]>=0andcor[a]+le[a]>coo[a]+(coo_r(l,r)[a]-l[2]*(((r+1)//2)%2))*scaleandcoo[a]+(coo_r(l,r)[a]+l[2]*(((r-1)//2)%2))*scale>cor[a]:sq=[coo[0]+(coo_r(l,r)[0]-l[2]*(r==2))*scale+s*a,coo[1]+(coo_r(l,r)[1]-l[2]*(r==1))*scale+s*(nota),coo[0]+(coo_r(l,r)[0]+l[2]*(r==0))*scale+s*a,coo[1]+(coo_r(l,r)[1]+l[2]*(r==3))*scale+s*(nota)]sq[a]=(sq[a],cor[a])[cor[a]>sq[a]]sq[a+2]=(sq[a+2],cor[a]+le[a])[sq[a+2]>cor[a]+le[a]]f(sq[0],sq[1],(sq[2]-sq[0])**(nota),(sq[3]-sq[1])**a,col)coo_r=lambdacoo,r:[(1-r+r%2)*coo[r%2]-(r//2),(1-2*(((-r)%4)//2))*coo[(r+1)%2]-(((-r)%4)//2)]coos_r=lambdacoos,r,cntr:[[(1-r+r%2)*(coo[r%2]-cntr[r%2])-(r//2)+cntr[0],(1-2*(((-r)%4)//2))*(coo[(r+1)%2]-cntr[(r+1)%2])-(((-r)%4)//2)+cntr[1]]forcooincoos]defcross(size,thick,pos,col):forxinrange(size-thick+1):f(x+pos[0],pos[1]+x,thick,thick,col)f(x+pos[0],pos[1]+size-x,thick,-thick,col)defcircle(r,pos,col):forxinrange(r):h=int(((r**2)-(x**2))**0.5)f(pos[0]-x,pos[1]-h,1,h*2,col)f(pos[0]+x,pos[1]-h,1,h*2,col)defsquare(a,coo,w,col):f(coo[0],coo[1],a,w,col)f(coo[0],coo[1]+a-w,a,w,col)f(coo[0],coo[1],w,a,col)f(coo[0]+a-w,coo[1],w,a,col)#draws a number
NS=737837656508197734647defnumber(num,x,y,size,col,sp=1):a=[1+size[1]//12,1+size[0]//(len(str(num))*12)]a=a[a[0]>a[1]]b=[(size[1]-3*a)//2,(size[0]+sp)//len(str(num))-sp-2*a]b=b[b[0]>b[1]]ifb>1andnum>=0:num=[int(a)forainstr(num)]coo=((x,y+a,a,b),(x+a,y,b,a),(x+a+b,y+a,a,b),(x+a,y+a+b,b,a),(x,y+2*a+b,a,b),(x+a,y+2*a+2*b,b,a),(x+a+b,y+2*a+b,a,b))forn,kinenumerate(num):forxinrange(7):if ((k*7+x)>>NS)&1:f(coo[x][0]+n*(b+2*a+sp),coo[x][1],coo[x][2],coo[x][3],col)#take number keyboard input
num=0NUMS={KEY_ZERO:"0",KEY_ONE:"1",KEY_TWO:"2",KEY_THREE:"3",KEY_FOUR:"4",KEY_FIVE:"5",KEY_SIX:"6",KEY_SEVEN:"7",KEY_EIGHT:"8",KEY_NINE:"9"}defmin_max(min_n=0,max_n=0):globalnumifmax_n>0andint(num)>max_n:num=str(max_n)ifint(num)<min_n:num=str(min_n)defupdate(input):globalnumifinput==KEY_BACKSPACE:iflen(num)==1:num="0"else:num=num[:-1]elifnot(int(num)==0andinput==KEY_ZERO):iflen(num)==1andint(num)==0:num=""num+=NUMS[input]#check wich keys were pressed between calls
#put this at the beginning of your code with the keys you want to check in listening
"""""
key_pressing={KEY_OK:0,KEY_DOWN:0,KEY_UP:0,KEY_LEFT:0,KEY_RIGHT:0}
key_pressed={k:0 for k in key_pressing}
"""""#use this to check for presses
"""""
for k in key_pressing:
key_pressed[k]=0
if keydown(k):
if not key_pressing[k]:
key_pressed[k]=1
key_pressing[k]=1
else:
key_pressing[k]=0
"""""#condition to see if a key was just pressed, replace KEY_NAME
# key_pressed[KEY_NAME]
#creates gradient
GRADIENT_COLORS=((255,150,0),(0,149,255),(50,50,50))N=1/(len(GRADIENT_COLORS)-1)defrgb(v):returntuple([GRADIENT_COLORS[int(v/N)][x]+(GRADIENT_COLORS[int(v/N)+1][x]-GRADIENT_COLORS[int(v/N)][x])*(v%N)/Nforxinrange(3)])#draw a line between two points
defline(x0,y0,x1,y1,color):h=((x1-x0)**2+(y1-y0)**2)**0.5cos=(x1-x0)/hsin=(y1-y0)/hforpinrange(int(h)+1):s_p(x0+int(cos*p),y0+int(sin*p),color)#three points bezier curve
defbezier3(x0,y0,x1,y1,x2,y2):d=int(((x0-x1)**2+(y0-y1)**2)**0.5+((x1-x2)**2+(y1-y2)**2)**0.5)forainrange(d):t=a/ds_p(int(x0*(1-2*t+t**2)+2*x1*(t-t**2)+x2*(t**2)),int(y0*(1-2*t+t**2)+2*y1*(t-t**2)+y2*(t**2)),(0,0,0))#set nth bit of an integer i to 1
defset_1_at(i,n):n|=1<<i#set nth bit of an integer i to 0
defset_0_at(i,n):n&=~(1<<i)#set nth bit of an integer i to 0 or 1
defset_at(n,bit,i):i=(i&(~(1<<n)))|(bit<<n)#return the value of the nth bit of an integer i
defget_at(n,i):return (i>>n)&1
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
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.