WIP : added some graphics primitives in modgint + fonts on fxCG (same as fx9860G) + turtle/matplotl libraries + examples #2

Closed
Slyvtt wants to merge 2 commits from (deleted):dev into dev
28 changed files with 2525 additions and 0 deletions

28
.gitignore vendored
View file

@ -1,3 +1,30 @@
<<<<<<< HEAD
# Compiled Sources
###################
*.o
*.a
*.elf
*.bin
*.map
*.hex
*.dis
*.exe
# Vscode files
################
*.json
# Packages
############
# Logs and Databases
######################
*.log
# VIM Swap Files
######################
*.swp
=======
# This .gitignore file is intended to be minimal.
#
# If you find that you need additional rules, such as IDE temporary
@ -5,6 +32,7 @@
# with core.excludesFile), or by adding private repository-specific
# rules to .git/info/exclude. See https://git-scm.com/docs/gitignore
# for more information.
>>>>>>> upstream/dev
# Build directories
build/

View file

@ -3,7 +3,12 @@ include ../../py/mkenv.mk
SH_CFLAGS := -DFXCG50
SH_LDFLAGS := -T fxcg50.ld -ljustui-cg -lm -lgint-cg -lc -lgint-cg -lgcc
<<<<<<< HEAD
SH_ASSETS := img_modifier_states.png \
font_5x7.png font_4x4.png font_4x6.png
=======
SH_ASSETS := img_modifier_states.png font_9.png font_13.png font_19.png
>>>>>>> upstream/dev
SH_METADATA := fxconv-metadata.txt
SH_CONVFLAGS := --cg

BIN
ports/fxcg50/font_4x4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

BIN
ports/fxcg50/font_4x6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
ports/fxcg50/font_5x7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View file

@ -3,6 +3,37 @@ img_*.png:
name_regex: (.*)\.png \1
profile: p4
<<<<<<< HEAD
font_*.png:
name_regex: (.*)\.png \1
type: font
charset: print
grid.padding: 1
grid.border: 0
font_5x7.png:
type: font
charset: print
grid.size: 5x7
grid.padding: 1
grid.border: 0
font_4x4.png:
type: font
charset: print
grid.size: 4x4
grid.padding: 1
grid.border: 0
proportional: true
font_4x6.png:
type: font
charset: print
grid.size: 5x6
grid.padding: 1
grid.border: 0
proportional: true
=======
font_9.png:
name: font_9
type: font
@ -29,3 +60,4 @@ font_19.png:
grid.padding: 0
grid.border: 0
proportional: true
>>>>>>> upstream/dev

View file

@ -16,6 +16,11 @@ SRC_C = \
ports/sh/keymap.c \
ports/sh/modcasioplot.c \
ports/sh/modgint.c \
<<<<<<< HEAD
ports/sh/primitives.c \
ports/sh/modtime.c \
=======
>>>>>>> upstream/dev
ports/sh/mphalport.c \
ports/sh/pyexec.c \
ports/sh/widget_shell.c \

Binary file not shown.

View file

@ -0,0 +1,633 @@
import casioplot as plt
from math import pow
from builtins import round
limits=[17,56,127,0]
fenetre=[0,1,0,1]
points=[[]]
lines=[[]]
textes=[[]]
xmin,xmax,ymin,ymax=0,1,0,1
win_scaling='init'
axis_display='on'
color_auto=['b','r','g','k','m','c','y']
color_count=0
def roundedpython( n, nbdigits ):
nbis = n * pow(10, nbdigits)
r = round( nbis )
return r / pow(10, nbdigits)
def axis(*L):
global fenetre,win_scaling,axis_display
if L==():
if win_scaling=='auto':
if xmin==xmax:
if xmin==0:
fenetre[0:2]=[-0.05,0.05]
else:
fenetre[0:2]=[0.95*xmin,1.05*xmin]
else:
fenetre[0:2]=[xmin-0.05*(xmax-xmin),xmax+0.05*(xmax-xmin)]
if ymin==ymax:
if ymin==0:
fenetre[2:4]=[-0.05,0.05]
else:
fenetre[2:4]=[0.95*ymin,1.05*ymin]
else:
fenetre[2:4]=[ymin-0.05*(ymax-ymin),ymax+0.05*(ymax-ymin)]
return fenetre
elif isinstance(L[0],(list,tuple)) and len(L[0])==4:
fenetre=list(L[0])
if fenetre[0]==fenetre[1]:
if fenetre[0]==0:
fenetre[0:2]=[-0.05,0.05]
else:
fenetre[0:2]=[0.95*fenetre[0],1.05*fenetre[0]]
raise Exception('Userwarning: attempting to set identical bottom == top in function axis(); automatically expanding.')
if fenetre[2]==fenetre[3]:
if fenetre[2]==0:
fenetre[2:4]=[-0.05,0.05]
else:
fenetre[2:4]=[0.95*fenetre[2],1.05*fenetre[2]]
raise Exception('Userwarning: attempting to set identical bottom == top in function axis(); automatically expanding.')
win_scaling='fixed'
axis_display='on'
return fenetre
elif L[0]=='off':
axis_display='off'
elif L[0]=='on':
axis_display='on'
elif L[0]=='auto':
win_scaling='auto'
if xmin==xmax:
if xmin==0:
fenetre[0:2]=[-0.05,0.05]
else:
fenetre[0:2]=[0.95*xmin,1.05*xmin]
else:
fenetre[0:2]=[xmin-0.05*(xmax-xmin),xmax+0.05*(xmax-xmin)]
if ymin==ymax:
if ymin==0:
fenetre[2:4]=[-0.05,0.05]
else:
fenetre[2:4]=[0.95*ymin,1.05*ymin]
else:
fenetre[2:4]=[ymin-0.05*(ymax-ymin),ymax+0.05*(ymax-ymin)]
return fenetre
else:
raise Exception('function axis() : error using arguments')
def text(x,y,txt):
global textes
if textes==[[]]:
textes[0]=[x,y,txt]
else:
if [x,y,txt] not in textes :
textes+=[[x,y,txt]]
def plot(*L,**kwargs):
global color_count,win_scaling
# if len(L)==2:
# L=([list(L[0]),list(L[1])])
def plotpoint(x,y,c):
global points,xmin,xmax,ymin,ymax
if points==[[]]:
points[0]=[x,y,c]
xmin=xmax=x
ymin=ymax=y
else:
if [x,y,c] not in points :
points+=[[x,y,c]]
xmin=min(x,xmin)
xmax=max(x,xmax)
ymin=min(y,ymin)
ymax=max(y,ymax)
def plotline(x1,y1,x2,y2,c):
global lines,xmin,xmax,ymin,ymax
if lines==[[]]:
lines[0]=[x1,y1,x2,y2,c]
xmin=min(x1,x2)
xmax=max(x1,x2)
ymin=min(y1,y2)
ymax=max(y1,y2)
else:
if [x1,y1,x2,y2,c] not in lines :
lines+=[[x1,y1,x2,y2,c]]
xmin=min(x1,x2,xmin)
xmax=max(x1,x2,xmax)
ymin=min(y1,y2,ymin)
ymax=max(y1,y2,ymax)
color=kwargs.get('color',None)
if color!=None and not color in ['b','r','g','k','m','c','y','w','blue','red','green','black','magenta','cyan','yellow','white']:
raise ValueError('function plot() : unknown color code')
if len(L)==2 and isinstance(L[0],(int,float)) and isinstance(L[1],(int,float)):
plotpoint(L[0],L[1],color)
if win_scaling=='init':
win_scaling='auto'
elif len(L)==2 and isinstance(L[0],(list,tuple)) and isinstance(L[1],(list,tuple)):
if (len(L[0])==len(L[1])):
if color==None:
color=color_auto[color_count%7]
color_count+=1
for i in range(len(L[0])-1):
plotline(L[0][i],L[1][i],L[0][i+1],L[1][i+1],color)
if win_scaling=='init':
win_scaling='auto'
else:
raise ValueError('function plot() : x and y must have same dimension')
elif len(L)==1 and isinstance(L[0],(list,tuple)):
if color==None:
color=color_auto[color_count%7]
color_count+=1
for i in range(len(L[0])-1):
plotline(i,L[0][i],i+1,L[0][i+1],color)
if win_scaling=='init':
win_scaling='auto'
elif len(L)==3 and isinstance(L[0],(int,float)) and isinstance(L[1],(int,float)) and isinstance(L[2],(str)):
color=L[2]
if (len(color)==2 and color[0] in ['b','r','g','k','m','c','y','w']) and color[1] in ['o','.','+','*','-']:
plotpoint(L[0],L[1],color[0])
if win_scaling=='init':
win_scaling='auto'
elif color in ['b','r','g','k','m','c','y','w','blue','red','green','black','magenta','cyan','yellow','white']:
plotpoint(L[0],L[1],color)
if win_scaling=='init':
win_scaling='auto'
elif color in ['o','.','+','*','-']:
color=color_auto[color_count%7]
color_count+=1
plotpoint(L[0],L[1],color)
if win_scaling=='init':
win_scaling='auto'
else:
raise ValueError('function plot() : available color codes are b,r,g,k,m,c,y,w')
elif len(L)==3 and isinstance(L[0],(list,tuple)) and isinstance(L[1],(list,tuple)) and isinstance(L[2],(str)):
if (len(L[0])==len(L[1])):
color=L[2]
if (len(color)==2 and color[0] in ['b','r','g','k','m','c','y','w']) and color[1] in ['o','.','+','*','-']:
for i in range(len(L[0])-1):
plotline(L[0][i],L[1][i],L[0][i+1],L[1][i+1],color[0])
if win_scaling=='init':
win_scaling='auto'
elif color in ['b','r','g','k','m','c','y','w','blue','red','green','black','magenta','cyan','yellow','white']:
for i in range(len(L[0])-1):
plotline(L[0][i],L[1][i],L[0][i+1],L[1][i+1],color)
if win_scaling=='init':
win_scaling='auto'
elif color in ['o','.','+','*','-']:
color=color_auto[color_count%7]
color_count+=1
for i in range(len(L[0])-1):
plotline(L[0][i],L[1][i],L[0][i+1],L[1][i+1],color)
if win_scaling=='init':
win_scaling='auto'
else:
raise ValueError('function plot() : available color codes are b,r,g,k,m,c,y,w')
else:
raise ValueError('function plot() : x and y must have same dimension')
elif len(L)==2 and isinstance(L[0],(list,tuple)) and isinstance(L[1],(str)):
color=L[1]
if (len(color)==2 and color[0] in ['b','r','g','k','m','c','y','w']) and color[1] in ['o','.','+','*','-']:
for i in range(len(L[0])-1):
plotline(i,L[0][i],i+1,L[0][i+1],color[0])
if win_scaling=='init':
win_scaling='auto'
elif color in ['b','r','g','k','m','c','y','w','blue','red','green','black','magenta','cyan','yellow','white']:
for i in range(len(L[0])-1):
plotline(i,L[0][i],i+1,L[0][i+1],color)
if win_scaling=='init':
win_scaling='auto'
elif color in ['o','.','+','*','-']:
color=color_auto[color_count%7]
color_count+=1
for i in range(len(L[0])-1):
plotline(i,L[0][i],i+1,L[0][i+1],color)
if win_scaling=='init':
win_scaling='auto'
else:
raise ValueError('function plot() : available color codes are b,r,g,k,m,c,y,w')
else:
raise Exception('function plot() : error using arguments')
def show():
global fenetre, limits, points, lines, textes, xmin, ymin, xmax, ymax, win_scaling, axis_display, color_count
def RGB(c):
if c=="k" or c=="black":
return (0,0,0)
elif c=="b" or c=="blue":
return (0,0,255)
elif c=="g" or c=="green":
return (0,255,0)
elif c=="r" or c=="red":
return (255,0,0)
elif c=="c" or c=="cyan":
return (0,255,255)
elif c=="y" or c=="yellow":
return (255,255,0)
elif c=="m" or c=="magenta":
return (255,0,255)
elif c=="w" or c=="white":
return (255,255,255)
else:
raise ValueError("invalid color code")
def printable(x,y):
global limits
return(limits[0]<=x<=limits[2] and limits[3]<=y<=limits[1])
def echelle(a,b):
k=0
e=abs(b-a)
while e>=10 :
e/=10
k+=1
while e<1 :
e*=10
k-=1
return k
def pas(a,b):
pas=10**echelle(a,b)
while (abs(b-a))//pas<4:
pas/=2
return pas
def converttopixel(x,y):
global fenetre,limits
ax=(limits[2]-limits[0])/(fenetre[1]-fenetre[0])
bx=limits[0]-ax*fenetre[0]
xpixel=round(ax*x+bx)
ay=(limits[3]-limits[1])/(fenetre[3]-fenetre[2])
by=limits[1]-ay*fenetre[2]
ypixel=round(ay*y+by)
return xpixel,ypixel
color_count=0
plt.clear_screen()
if win_scaling=='auto':
if xmin==xmax:
if xmin==0:
fenetre[0:2]=[-0.05,0.05]
else:
fenetre[0:2]=[0.95*xmin,1.05*xmin]
else:
fenetre[0:2]=[xmin-0.05*(xmax-xmin),xmax+0.05*(xmax-xmin)]
if ymin==ymax:
if ymin==0:
fenetre[2:4]=[-0.05,0.05]
else:
fenetre[2:4]=[0.95*ymin,1.05*ymin]
else:
fenetre[2:4]=[ymin-0.05*(ymax-ymin),ymax+0.05*(ymax-ymin)]
if axis_display=='on' or axis_display=='boxplot':
for i in range(limits[0],limits[2]+1):
plt.set_pixel(i,limits[1],RGB("k"))
for j in range(limits[3],limits[1]+1):
plt.set_pixel(limits[0],j,RGB("k"))
fenetreb=sorted([fenetre[0],fenetre[1]])+sorted([fenetre[2],fenetre[3]])
gx=roundedpython(fenetreb[0],-echelle(fenetreb[0],fenetreb[1]))
gy=roundedpython(fenetreb[2],-echelle(fenetreb[2],fenetreb[3]))
if axis_display=='boxplot':
for i in range(nbre_boite):
y=fenetre[2]
xpixel,ypixel=converttopixel(i+1,y)
plt.set_pixel(xpixel,ypixel+1,RGB("k"))
plt.draw_string(xpixel,ypixel+3,str(i+1),[0,0,0],"small")
else :
for i in range(-11,11):
x=gx+i*pas(fenetreb[0],fenetreb[1])
y=fenetre[2]
xpixel,ypixel=converttopixel(x,y)
if roundedpython(x,4)==int(x):
x=int(roundedpython(x,4))
if printable(xpixel,ypixel):
plt.set_pixel(xpixel,ypixel+1,RGB("k"))
plt.draw_string(xpixel,ypixel+3,str(x),[0,0,0],"small")
for j in range(-11,11):
x=fenetre[0]
y=gy+j*pas(fenetreb[2],fenetreb[3])
xpixel,ypixel=converttopixel(x,y)
if roundedpython(y,4)==int(y):
y=int(roundedpython(y,4))
if printable(xpixel,ypixel):
plt.set_pixel(xpixel-1,ypixel,RGB("k"))
plt.draw_string(xpixel-17,ypixel,str(y),[0,0,0],"small")
if points!=[[]]:
if points[0]==[]:
del points[0]
for i in range(len(points)):
xpixel,ypixel=converttopixel(points[i][0],points[i][1])
if printable(xpixel,ypixel) and points[i][2]!=None:
for j in range(-2,3):
plt.set_pixel(xpixel+j,ypixel,RGB(points[i][2]))
plt.set_pixel(xpixel,ypixel+j,RGB(points[i][2]))
if textes!=[[]]:
if textes[0]==[]:
del textes[0]
for i in range(len(textes)):
xpixel,ypixel=converttopixel(textes[i][0],textes[i][1])
if printable(xpixel,ypixel):
plt.draw_string(xpixel,ypixel,textes[i][2],[0,0,0],"small")
if lines!=[[]]:
if lines[0]==[]:
del lines[0]
for i in range(len(lines)):
xpixel1,ypixel1=converttopixel(lines[i][0],lines[i][1])
xpixel2,ypixel2=converttopixel(lines[i][2],lines[i][3])
deltax=abs(xpixel2-xpixel1)
deltay=abs(ypixel2-ypixel1)
if deltax==deltay==0:
if printable(xpixel1,ypixel1):
plt.set_pixel(xpixel1,ypixel1,RGB(lines[i][4]))
if deltax<=1 and deltay<=1:
if printable(xpixel1,ypixel1):
plt.set_pixel(xpixel1,ypixel1,RGB(lines[i][4]))
plt.set_pixel(xpixel2,ypixel2,RGB(lines[i][4]))
if deltax>=deltay and deltax!=0:
m=(ypixel2-ypixel1)/(xpixel2-xpixel1)
p=ypixel1-m*xpixel1
xpixelmin=max(limits[0],min(xpixel1,xpixel2))
xpixelmax=min(limits[2],max(xpixel1,xpixel2))
if xpixelmin<=limits[2] and xpixelmax>=limits[0]:
for xpixel in range(xpixelmin,xpixelmax+1):
ypixel=round(m*xpixel+p)
if printable(xpixel,ypixel):
plt.set_pixel(xpixel,ypixel,RGB(lines[i][4]))
if deltay>deltax:
m=(xpixel2-xpixel1)/(ypixel2-ypixel1)
p=xpixel1-m*ypixel1
ypixelmin=max(limits[3],min(ypixel1,ypixel2))
ypixelmax=min(limits[1],max(ypixel1,ypixel2))
if ypixelmin<=limits[1] and ypixelmax>=limits[3]:
for ypixel in range(ypixelmin,ypixelmax+1):
xpixel=round(m*ypixel+p)
if printable(xpixel,ypixel):
plt.set_pixel(xpixel,ypixel,RGB(lines[i][4]))
axis([limits[0]-50,limits[2],limits[1]+50,limits[3]])
axis("off")
plt.show_screen()
points=[[]]
lines=[[]]
textes=[[]]
xmin,xmax,ymin,ymax=0,1,0,1
fenetre=[0,1,0,1]
axis_display='on'
win_scaling='init'
color_count=0
def bar(val,eff,lar=0.8):
val=list(val)
eff=list(eff)
global color_count
if isinstance(val,(list,tuple)) and isinstance(eff,(list,tuple)):
if len(val)==len(eff):
for i in range(len(val)):
plot([val[i]-lar/2,val[i]-lar/2],[0,eff[i]],color_auto[color_count%7])
plot([val[i]+lar/2,val[i]+lar/2],[0,eff[i]],color_auto[color_count%7])
plot([val[i]-lar/2,val[i]+lar/2],[eff[i],eff[i]],color_auto[color_count%7])
color_count+=1
else:
raise ValueError('function bar() : lists must have same dimension')
elif isinstance(val,(int,float)) and isinstance(eff,(int,float)):
for i in range(len(val)):
plot([val[i]-lar/2,val[i]-lar/2],[0,eff[i]],color_auto[color_count%7])
plot([val[i]+lar/2,val[i]+lar/2],[0,eff[i]],color_auto[color_count%7])
plot([val[i]-lar/2,val[i]+lar/2],[eff[i],eff[i]],color_auto[color_count%7])
color_count+=1
else:
raise ValueError('function bar() : error using arguments or arguments not available in this version')
def scatter(xlist,ylist):
xlist=list(xlist)
ylist=list(ylist)
global color_count
if isinstance(xlist,(list,tuple)) and isinstance(ylist,(list,tuple)):
if len(xlist)==len(ylist):
for i in range(len(xlist)):
plot(xlist[i],ylist[i],color_auto[color_count%7])
color_count+=1
else:
raise ValueError('function scatter() : x and y must have same dimension')
elif isinstance(xlist,(int,float)) and isinstance(ylist,(int,float)):
plot(xlist,ylist,color_auto[color_count%7])
color_count+=1
else:
raise ValueError('function scatter() : error using arguments or arguments not available in this version')
def boxplotFR(L):
L=list(L)
global fenetre,color_count,nbre_boite, axis_display,win_scaling
print("boxplotFR:definition \nfrancaise du \ndiagramme en boite")
axis_display='boxplot'
n=len(L)
if type(L[0])==int or type(L[0])==float:
n=1
nbre_boite=n
largeur=0.3/n
def mediane(l):
l=sorted(l)
r=len(l)
if r%2==0:
return (l[r//2]+l[r//2-1])/2
else:
return l[r//2]
def quartiles(l):
l=sorted(l)
r=len(l)
return (l[r//4],l[(3*r)//4])
def deciles(l):
l=sorted(l)
r=len(l)
return (l[r//10],l[(9*r)//10])
for i in range(n):
if n==1:
if type(L[0])==int or type(L[0])==float:
K=L
else:
K=L[0]
else :
K=L[i]
if type(K)==int or type(K)==float:
plot([i+1-largeur,i+1+largeur],[K,K],'r')
elif type(K[0])==int or type(K[0])==float:
K=sorted(K)
p=len(K)
Q1=quartiles(K)[0]
Q3=quartiles(K)[1]
D1=deciles(K)[0]
D9=deciles(K)[1]
plot([i+1-largeur,i+1+largeur,i+1+largeur,i+1-largeur,i+1-largeur],[Q1,Q1,Q3,Q3,Q1],'k')
plot([i+1,i+1],[Q1,D1],'k')
plot([i+1,i+1],[Q3,D9],'k')
plot([i+1-largeur/2,i+1+largeur/2],[D1,D1],'k')
plot([i+1-largeur/2,i+1+largeur/2],[D9,D9],'k')
plot(i+1,K[0],'k')
plot(i+1,K[p-1],'k')
plot([i+1-largeur,i+1+largeur],[mediane(K),mediane(K)],'r')
elif type(min(L[0]))!=int and type(min(L[0]))!=float:
raise ValueError('wrong type of argument')
if type(L[0])==int or type(L[0])==float:
fenetre=[0,2,min(L)-1,max(L)+1]
Max=max(L)
else:
Min=min(L[0])
Max=max(L[0])
for i in range(len(L)):
if type(L[i])==int or type(L[i])==float:
if L[i]<Min:
Min=L[i]
if L[i]>Max:
Max=L[i]
else:
if min(L[i])<Min:
Min=min(L[i])
if max(L[i])>Max:
Max=max(L[i])
fenetre=[0,len(L)+1,Min-1,Max+1]
win_scaling='fixed'
text(len(L)+1/4,Max+1/2,"boxplotFR")
def boxplot(L,**kwargs):
L=list(L)
global fenetre,color_count,nbre_boite, axis_display,win_scaling
whis=kwargs.get('whis',1.5)
axis_display='boxplot'
n=len(L)
if type(L[0])==int or type(L[0])==float:
n=1
nbre_boite=n
largeur=0.3/n
def mediane(l):
r=1
if type(l)!=int and type(l)!=float:
l=sorted(l)
r=len(l)
if r%2==0 and r//2>0:
return (l[r//2]+l[r//2-1])/2,l[:r//2],l[r//2:]
else:
return l[r//2],l[:r//2],l[r//2+1:]
return l,l,l
if type(L[0])==int or type(L[0])==float:
if min(L)==max(L):
ampl=1
else:
ampl=max(L)-min(L)
fenetre=[0,2,min(L)-ampl/20,max(L)+ampl/20]
else:
Min=min(L[0])
Max=max(L[0])
for i in range(len(L)):
if type(L[i])==int or type(L[i])==float:
if L[i]<Min:
Min=L[i]
if L[i]>Max:
Max=L[i]
else:
if min(L[i])<Min:
Min=min(L[i])
if max(L[i])>Max:
Max=max(L[i])
if Min==Max:
ampl=1
else:
ampl=Max-Min
fenetre=[0,len(L)+1,Min-ampl/20,Max+ampl/20]
win_scaling='fixed'
for i in range(n):
if n==1:
if type(L[0])==int or type(L[0])==float:
K=L
else:
K=L[0]
else :
K=L[i]
if type(K)==int or type(K)==float:
plot([i+1-largeur,i+1+largeur],[K,K],'r')
elif type(K[0])==int or type(K[0])==float:
K=sorted(K)
p=len(K)
Q1,Q3=mediane(mediane(K)[1])[0],mediane(mediane(K)[2])[0]
down=0
if Q1-whis*(Q3-Q1)<=K[0]:
down=0
else :
while Q1-whis*(Q3-Q1)>K[down]:
down+=1
up=p-1
if Q3+whis*(Q3-Q1)>=K[p-1]:
up=p-1
else :
while Q3+whis*(Q3-Q1)<K[up]:
up-=1
plot([i+1-largeur,i+1+largeur,i+1+largeur,i+1-largeur,i+1-largeur],[Q1,Q1,Q3,Q3,Q1],'k')
plot([i+1,i+1],[Q1,K[down]],'k')
plot([i+1,i+1],[Q3,K[up]],'k')
plot([i+1-largeur/2,i+1+largeur/2],[K[down],K[down]],'k')
plot([i+1-largeur/2,i+1+largeur/2],[K[up],K[up]],'k')
from math import pi
from math import cos
from math import sin
if down>0:
for t in range(down):
x=[i+1+0.05*(fenetre[1])/3*cos(2*j*pi/50) for j in range(50)]
y=[K[t]+0.05*(fenetre[3]-fenetre[2])/3*sin(2*j*pi/50) for j in range(50)]
plot(x,y,'k')
if up<p-1:
for t in range(p-1-up):
x=[i+1+0.05*(fenetre[1])/3*cos(2*j*pi/50) for j in range(50)]
y=[K[p-1-t]+0.05*(fenetre[3]-fenetre[2])/3*sin(2*j*pi/50) for j in range(50)]
plot(x,y,'k')
plot([i+1-largeur,i+1+largeur],[mediane(K)[0],mediane(K)[0]],'r')
elif type(min(L[0]))!=int and type(min(L[0]))!=float:
raise ValueError('wrong type of argument')
def arrow(x,y,dx,dy,**kwargs):
global win_scaling
a=x+dx
b=y+dy
win_scaling='fixed'
color=kwargs.get('ec','k')
color=kwargs.get('edgecolor',color)
headcolor=kwargs.get('fc',color)
headcolor=kwargs.get('facecolor',headcolor)
L=kwargs.get('head_width',0.003)
l=kwargs.get('head_length',1.5*L)
plot((x,a),(y,b),color)
def resol(A,B,C):
D=B**2-4*A*C
if D>0:
return((-B-D**0.5)/(2*A),(-B+D**0.5)/(2*A))
if dx==0:
if dy>=0:
c=1
else:
c=-1
plot((a-L/2,a+L/2,a,a-L/2),(b,b,b+c*l,b),color)
elif dy==0:
if dx>=0:
c=1
else:
c=-1
plot((a,a,a+c*l,a),(b-L/2,b+L/2,b,b-L/2),color)
else:
m=dy/dx
p=y-m*x
S=resol(m**2+1,2*(-a-b*m+m*p),p**2+a**2+b**2-l**2-2*b*p)
if S[0]*dx<0:
X=S[0]
else:
X=S[1]
Y=m*X+p
k=b+a/m
T=resol(1+1/m**2,2*(-a-k/m+b/m),a**2+k**2-2*b*k+b**2-(L**2)/4)
plot((T[0],T[1],X,T[0]),(-T[0]/m+k,-T[1]/m+k,Y,-T[0]/m+k),headcolor)

View file

@ -0,0 +1,33 @@
from casioplot import *
from gint import *
B=(0,0,0)
W=(255,255,255)
clear_screen()
set_pixel(1, 1, B)
for x in range(10):
set_pixel(x+1,3,B)
for y in range(40):
for x in range(10):
set_pixel(x+1,y+5,B)
draw_string(20,1,"Hello,",B,"large")
draw_string(20,11,"World!",B,"small")
img = b'\x04@"\x00\x0e\xa6W\x00\x0e\xafW\x00\x05\x1f\x89\x00u/J\xc0\xf5F*\xe0'+\
b'\xe4\xc92\xe0\x8cP\xa1 \x8c{\xe1 \x8c\xbf\xb1 \x8c\xb1\xb1 \x9c\x950'+\
b'\xa0\x9e\xb1\x90\xa0\x8e\x7f\xc3 \xc3\xfb\xfc`\xe0\x1d\xc0\xe0\xbf\x12'+\
b'\x1f\xa0_\t\x1f@ \x89 \x80\x1f\x92?\x00'
for y in range(20):
for x in range(27):
offset = y * 4 + (x // 8)
bit = 0x80 >> (x & 7)
if img[offset] & bit:
set_pixel(x+30,y+30,B)
show_screen()
k=getkey()

View file

@ -0,0 +1,11 @@
import matplotl as p
import gint as g
g.dclear(g.C_WHITE)
x=[119.1,119.3,119.5,119.6,119.9,120.0,120.1,120.3,120.4]
y=[1,3,4,3,1,3,1,3,1]
p.bar(x,y,0.08)
p.show()
g.getkey()

View file

@ -0,0 +1,27 @@
from casioplot import *
from turtle import *
import gint as g
def koch(n,l):
if n==0:
forward(l)
else:
koch(n-1,l/3)
left(60)
koch(n-1,l/3)
right(120)
koch(n-1,l/3)
left(60)
koch(n-1,l/3)
g.dclear(g.C_WHITE)
pencolor("black")
penup()
goto(-120,-10)
pendown()
koch(4,120)
show_screen()
g.getkey()

View file

@ -0,0 +1,347 @@
#import casioplot
from casioplot import *
from math import sqrt
from math import pi
from math import cos
from math import sin
from math import atan2
# Added by SlyVTT : round() is not implemented in math but in builtins module of MicroPython
from builtins import round
turtleshapes={"classic":[[-9,5],[-9,4],[-8,4],[-8,3],[-8,2],[-8,-2],[-8,-3],[-8,-4],[-9,-4],[-9,-5],[-7,4],[-7,1],[-7,0],[-7,-1],[-7,-4],[-6,3],[-6,-3],[-5,3],[-5,-3],[-4,2],[-4,-2],[-3,2],[-3,-2],[-2,1],[-2,-1],[-1,1],[-1,-1],[0,0]],"turtle": [[-3,3],[2,3],[-2,2],[-1,2],[0,2],[1,2],[-2,1],[-1,1],[1,1],[0,1],[2,1],[3,1],[-2,0],[-1,0],[0,0],[1,0],[-1,-1],[-2,-1],[0,-1],[1,-1],[2,0],[3,0],[-3,-2],[2,-2]]}
turtle_name="classic"
turtle_data=turtleshapes[turtle_name]
turtle_pos=[0,0]
turtle_angle=0
turtle_color=(0,0,0)
writing=True
pen_size=1
turtle_buffer=[[]]
turtle_speed=5
frame_count=0
turtle_visible=True
# Added by SlyVTT : round() is not implemented in math but in builtins module of MicroPython
# So I added this simple function aiming at replacing round( n, nbdigits )
def roundedpython( n, nbdigits ):
nbis = n * pow(10, nbdigits)
r = round( nbis )
return r / pow(10, nbdigits)
def draw_turtle(x,y,a,c):
global turtle_buffer
def inbuffer(x,y):
inlist=False
for i in range(1,len(turtle_buffer)):
if x==turtle_buffer[i][0] and y==turtle_buffer[i][1]:
inlist=True
return inlist
if turtle_visible==True:
u=cos(a*pi/180)
v=sin(a*pi/180)
for point in turtle_data:
xx=x+(point[0]*u-point[1]*v)
yy=y+(point[1]*u+point[0]*v)
xpixel=int(round(xx+64))
ypixel=int(round(-yy+32))
if (0<=xpixel<=127 and 0<=ypixel<=63):
if not inbuffer(xpixel,ypixel):
turtle_buffer+=[[xpixel,ypixel,get_pixel(xpixel,ypixel)]]
set_pixel(xpixel,ypixel,c)
def erase_turtle():
global turtle_buffer
for i in range(1,len(turtle_buffer)):
xpixel=turtle_buffer[i][0]
ypixel=turtle_buffer[i][1]
if turtle_buffer[i][2]!=None :
lastcolor=turtle_buffer[i][2]
else:
lastcolor=(255,255,255)
set_pixel(xpixel,ypixel,lastcolor)
turtle_buffer=[[]]
def pen_brush(x,y,turtle_color):
global frame_count
erase_turtle()
xpixel=int(round(x+64))
ypixel=int(round(-y+32))
if writing==True and (0<=xpixel<=127 and 0<=ypixel<=63) :
colorpixel=(int(turtle_color[0]*255), int(turtle_color[1]*255),int(turtle_color[2]*255))
set_pixel(xpixel,ypixel,colorpixel)
frame_count+=1
if turtle_speed!=0:
if frame_count%(turtle_speed*2)==0:
draw_turtle(x,y,turtle_angle,colorpixel)
show_screen()
else :
if frame_count%200==0:
draw_turtle(x,y,turtle_angle,colorpixel)
show_screen()
def refresh_turtle():
c=(int(turtle_color[0]*255), int(turtle_color[1]*255),int(turtle_color[2]*255))
erase_turtle()
draw_turtle(turtle_pos[0],turtle_pos[1],turtle_angle,c)
show_screen()
def back(n):
forward(-n)
def backward(n):
back(n)
def bk(n):
back(n)
def circle(radius,extent=360):
global turtle_angle, turtle_pos
x1=turtle_pos[0]
y1=turtle_pos[1]
if round(radius)==0:
pen_brush(x1,y1,turtle_color)
turtle_angle+=extent
elif roundedpython(extent,8)==0:
pen_brush(x1,y1,turtle_color)
else:
e=radius/abs(radius)
theta=extent*pi/180*e
Rx=cos(theta)
Ry=sin(theta)
Dx=radius*sin(turtle_angle*pi/180)
Dy=-radius*cos(turtle_angle*pi/180)
xcenter=x1-Dx
ycenter=y1-Dy
nbpixelarc=int(round(abs(radius*theta*1.05)))
angle=turtle_angle
if nbpixelarc!=0:
alpha=theta/nbpixelarc
for k in range(nbpixelarc+1):
x=xcenter+Dx*cos(alpha*k)-Dy*sin(alpha*k)
y=ycenter+Dx*sin(alpha*k)+Dy*cos(alpha*k)
turtle_angle+=alpha*180/pi
pen_brush(x,y,turtle_color)
turtle_pos[0]=xcenter+Dx*Rx-Dy*Ry
turtle_pos[1]=ycenter+Dx*Ry+Dy*Rx
turtle_angle=angle+extent*e
refresh_turtle()
def clear():
erase_turtle()
clear_screen()
show_screen()
refresh_turtle()
def distance(x,y):
return sqrt((x-turtle_pos[0])**2+(y-turtle_pos[1])**2)
def down():
global writing
writing=True
def fd(d):
forward(d)
def forward(d):
global turtle_pos
dx=d*cos(turtle_angle*pi/180)
dy=d*sin(turtle_angle*pi/180)
x1=turtle_pos[0]
y1=turtle_pos[1]
if round(abs(d))==0:
pen_brush(x1+dx,y1+dy,turtle_color)
elif abs(dx)>=abs(dy):
e=int(dx/abs(dx))
m=dy/dx
p=y1-m*x1
for x in range(int(round(x1)),int(round(x1+dx)),e):
pen_brush(x,m*x+p,turtle_color)
else:
e=int(dy/abs(dy))
m=dx/dy
p=x1-m*y1
for y in range(int(round(y1)),int(round(y1+dy)),e):
pen_brush(m*y+p,y,turtle_color)
turtle_pos[0]+=dx
turtle_pos[1]+=dy
refresh_turtle()
def goto(x,y):
a=turtle_angle
setheading(towards(x,y))
forward(distance(x,y))
setheading(a)
refresh_turtle()
def heading():
return turtle_angle
def hideturtle():
global turtle_visible
turtle_visible=False
refresh_turtle()
def home():
global turtle_pos,turtle_angle
turtle_pos[0]=turtle_pos[1]=0
turtle_angle=0
refresh_turtle()
def ht():
hideturtle()
def isdown():
return writing
def isvisible():
return turtle_visible
def left(a):
right(-a)
def lt(a):
right(-a)
def pd():
down()
def pencolor(*c):
global turtle_color
colornames={"black":(0,0,0),"blue":(0,0,1),"green":(0,1,0),"red":(1,0,0),"cyan":(0,1,1),"yellow":(1,1,0),"magenta":(1,0,1),"white":(1,1,1),"orange":(1,0.65,0),"purple":(0.66,0,0.66),"brown":(0.75,0.25,0.25),"pink":(1,0.75,0.8),"grey":(0.66,0.66,0.66)}
if c==():
return turtle_color
elif c[0] in colornames:
turtle_color=colornames[c[0]]
elif isinstance(c[0],(list,tuple)) and len(c[0])==3 and isinstance(c[0][0],(int,float)) and isinstance(c[0][1],(int,float)) and isinstance(c[0][2],(int,float)) and 0<=c[0][0]<=1 and 0<=c[0][1]<=1 and 0<=c[0][2]<=1:
turtle_color=list(c[0])
else:
raise ValueError('error using pencolor : enter a color text or 3 floats between 0 and 1')
refresh_turtle()
def pendown():
down()
def pensize(n):
global pen_size
pen_size=n
refresh_turtle()
def penup():
global writing
writing=False
def pos():
return (xcor(),ycor())
def position():
return (xcor(),ycor())
def pu():
penup()
def reset():
global turtle_color,writing,pen_size,speed,turtle_visible
clear()
turtle_color=(0,0,0)
home()
writing=True
pen_size=1
speed=5
turtle_visible=True
shape("classic")
refresh_turtle()
def right(a):
global turtle_angle
turtle_angle-=a
refresh_turtle()
def rt(a):
right(a)
def seth(a):
setheading(a)
def setheading(a):
global turtle_angle
turtle_angle=a
refresh_turtle()
def setpos(x,y):
goto(x,y)
refresh_turtle()
def setposition(x,y):
setpos(x,y)
def setx(x):
global turtle_pos
turtle_pos[0]=x
refresh_turtle()
def sety(y):
global turtle_pos
turtle_pos[1]=y
refresh_turtle()
def shape(text=None):
global turtle_name,turtle_data
if text==None:
return turtle_name
elif text in turtleshapes:
turtle_name=text
turtle_data=turtleshapes[text]
else:
raise ValueError('available shapes: "classic" or "turtle"')
refresh_turtle()
def showturtle():
global turtle_visible
turtle_visible=True
refresh_turtle()
def speed(v=None):
global turtle_speed
speedwords = {'fastest':0, 'fast':10, 'normal':6, 'slow':3, 'slowest':1 }
if v==None:
pass
elif isinstance(v,(int,float)) and (v<=0.5 or v>=10.5):
turtle_speed=0
elif isinstance(v,(int,float)) and (0.5<v<10.5):
turtle_speed=int(round(v))
elif isinstance(v,str) and v in speedwords:
turtle_speed=speedwords[v]
else:
raise ValueError("Error using function speed: enter a real between 0 & 10")
def st():
showturtle()
def towards(x,y):
global turtle_pos
if roundedpython(x-turtle_pos[0],8)==0 and roundedpython(y-turtle_pos[1],8)==0:
return 0
else:
return (atan2(y-turtle_pos[1],x-turtle_pos[0])*180/pi)
def up():
penup()
def width(n):
pensize(n)
def write(text):
xpixel=int(round(turtle_pos[0]+64))
ypixel=int(round(-turtle_pos[1]+32))
c=(int(turtle_color[0]*255), int(turtle_color[1]*255),int(turtle_color[2]*255))
draw_string(xpixel,ypixel,str(text),c,"small")
show_screen()
def xcor():
global turtle_pos
return roundedpython(turtle_pos[0],6)
def ycor():
global turtle_pos
return roundedpython(turtle_pos[1],6)

View file

@ -0,0 +1,635 @@
import casioplot as plt
from math import pow
from builtins import round
limits=[40,165,384,0]
fenetre=[0,1,0,1]
points=[[]]
lines=[[]]
textes=[[]]
xmin,xmax,ymin,ymax=0,1,0,1
win_scaling='init'
axis_display='on'
color_auto=['b','r','g','k','m','c','y']
color_count=0
def roundedpython( n, nbdigits ):
nbis = n * pow(10, nbdigits)
r = round( nbis )
return r / pow(10, nbdigits)
def axis(*L):
global fenetre,win_scaling,axis_display
if L==():
if win_scaling=='auto':
if xmin==xmax:
if xmin==0:
fenetre[0:2]=[-0.05,0.05]
else:
fenetre[0:2]=[0.95*xmin,1.05*xmin]
else:
fenetre[0:2]=[xmin-0.05*(xmax-xmin),xmax+0.05*(xmax-xmin)]
if ymin==ymax:
if ymin==0:
fenetre[2:4]=[-0.05,0.05]
else:
fenetre[2:4]=[0.95*ymin,1.05*ymin]
else:
fenetre[2:4]=[ymin-0.05*(ymax-ymin),ymax+0.05*(ymax-ymin)]
return fenetre
elif isinstance(L[0],(list,tuple)) and len(L[0])==4:
fenetre=list(L[0])
if fenetre[0]==fenetre[1]:
if fenetre[0]==0:
fenetre[0:2]=[-0.05,0.05]
else:
fenetre[0:2]=[0.95*fenetre[0],1.05*fenetre[0]]
raise Exception('Userwarning: attempting to set identical bottom == top in function axis(); automatically expanding.')
if fenetre[2]==fenetre[3]:
if fenetre[2]==0:
fenetre[2:4]=[-0.05,0.05]
else:
fenetre[2:4]=[0.95*fenetre[2],1.05*fenetre[2]]
raise Exception('Userwarning: attempting to set identical bottom == top in function axis(); automatically expanding.')
win_scaling='fixed'
axis_display='on'
return fenetre
elif L[0]=='off':
axis_display='off'
elif L[0]=='on':
axis_display='on'
elif L[0]=='auto':
win_scaling='auto'
if xmin==xmax:
if xmin==0:
fenetre[0:2]=[-0.05,0.05]
else:
fenetre[0:2]=[0.95*xmin,1.05*xmin]
else:
fenetre[0:2]=[xmin-0.05*(xmax-xmin),xmax+0.05*(xmax-xmin)]
if ymin==ymax:
if ymin==0:
fenetre[2:4]=[-0.05,0.05]
else:
fenetre[2:4]=[0.95*ymin,1.05*ymin]
else:
fenetre[2:4]=[ymin-0.05*(ymax-ymin),ymax+0.05*(ymax-ymin)]
return fenetre
else:
raise Exception('function axis() : error using arguments')
def text(x,y,txt):
global textes
if textes==[[]]:
textes[0]=[x,y,txt]
else:
if [x,y,txt] not in textes :
textes+=[[x,y,txt]]
def plot(*L,**kwargs):
global color_count,win_scaling
# if len(L)==2:
# L=([list(L[0]),list(L[1])])
def plotpoint(x,y,c):
global points,xmin,xmax,ymin,ymax
if points==[[]]:
points[0]=[x,y,c]
xmin=xmax=x
ymin=ymax=y
else:
if [x,y,c] not in points :
points+=[[x,y,c]]
xmin=min(x,xmin)
xmax=max(x,xmax)
ymin=min(y,ymin)
ymax=max(y,ymax)
def plotline(x1,y1,x2,y2,c):
global lines,xmin,xmax,ymin,ymax
if lines==[[]]:
lines[0]=[x1,y1,x2,y2,c]
xmin=min(x1,x2)
xmax=max(x1,x2)
ymin=min(y1,y2)
ymax=max(y1,y2)
else:
if [x1,y1,x2,y2,c] not in lines :
lines+=[[x1,y1,x2,y2,c]]
xmin=min(x1,x2,xmin)
xmax=max(x1,x2,xmax)
ymin=min(y1,y2,ymin)
ymax=max(y1,y2,ymax)
color=kwargs.get('color',None)
if color!=None and not color in ['b','r','g','k','m','c','y','w','blue','red','green','black','magenta','cyan','yellow','white']:
raise ValueError('function plot() : unknown color code')
if len(L)==2 and isinstance(L[0],(int,float)) and isinstance(L[1],(int,float)):
plotpoint(L[0],L[1],color)
if win_scaling=='init':
win_scaling='auto'
elif len(L)==2 and isinstance(L[0],(list,tuple)) and isinstance(L[1],(list,tuple)):
if (len(L[0])==len(L[1])):
if color==None:
color=color_auto[color_count%7]
color_count+=1
for i in range(len(L[0])-1):
plotline(L[0][i],L[1][i],L[0][i+1],L[1][i+1],color)
if win_scaling=='init':
win_scaling='auto'
else:
raise ValueError('function plot() : x and y must have same dimension')
elif len(L)==1 and isinstance(L[0],(list,tuple)):
if color==None:
color=color_auto[color_count%7]
color_count+=1
for i in range(len(L[0])-1):
plotline(i,L[0][i],i+1,L[0][i+1],color)
if win_scaling=='init':
win_scaling='auto'
elif len(L)==3 and isinstance(L[0],(int,float)) and isinstance(L[1],(int,float)) and isinstance(L[2],(str)):
color=L[2]
if (len(color)==2 and color[0] in ['b','r','g','k','m','c','y','w']) and color[1] in ['o','.','+','*','-']:
plotpoint(L[0],L[1],color[0])
if win_scaling=='init':
win_scaling='auto'
elif color in ['b','r','g','k','m','c','y','w','blue','red','green','black','magenta','cyan','yellow','white']:
plotpoint(L[0],L[1],color)
if win_scaling=='init':
win_scaling='auto'
elif color in ['o','.','+','*','-']:
color=color_auto[color_count%7]
color_count+=1
plotpoint(L[0],L[1],color)
if win_scaling=='init':
win_scaling='auto'
else:
raise ValueError('function plot() : available color codes are b,r,g,k,m,c,y,w')
elif len(L)==3 and isinstance(L[0],(list,tuple)) and isinstance(L[1],(list,tuple)) and isinstance(L[2],(str)):
if (len(L[0])==len(L[1])):
color=L[2]
if (len(color)==2 and color[0] in ['b','r','g','k','m','c','y','w']) and color[1] in ['o','.','+','*','-']:
for i in range(len(L[0])-1):
plotline(L[0][i],L[1][i],L[0][i+1],L[1][i+1],color[0])
if win_scaling=='init':
win_scaling='auto'
elif color in ['b','r','g','k','m','c','y','w','blue','red','green','black','magenta','cyan','yellow','white']:
for i in range(len(L[0])-1):
plotline(L[0][i],L[1][i],L[0][i+1],L[1][i+1],color)
if win_scaling=='init':
win_scaling='auto'
elif color in ['o','.','+','*','-']:
color=color_auto[color_count%7]
color_count+=1
for i in range(len(L[0])-1):
plotline(L[0][i],L[1][i],L[0][i+1],L[1][i+1],color)
if win_scaling=='init':
win_scaling='auto'
else:
raise ValueError('function plot() : available color codes are b,r,g,k,m,c,y,w')
else:
raise ValueError('function plot() : x and y must have same dimension')
elif len(L)==2 and isinstance(L[0],(list,tuple)) and isinstance(L[1],(str)):
color=L[1]
if (len(color)==2 and color[0] in ['b','r','g','k','m','c','y','w']) and color[1] in ['o','.','+','*','-']:
for i in range(len(L[0])-1):
plotline(i,L[0][i],i+1,L[0][i+1],color[0])
if win_scaling=='init':
win_scaling='auto'
elif color in ['b','r','g','k','m','c','y','w','blue','red','green','black','magenta','cyan','yellow','white']:
for i in range(len(L[0])-1):
plotline(i,L[0][i],i+1,L[0][i+1],color)
if win_scaling=='init':
win_scaling='auto'
elif color in ['o','.','+','*','-']:
color=color_auto[color_count%7]
color_count+=1
for i in range(len(L[0])-1):
plotline(i,L[0][i],i+1,L[0][i+1],color)
if win_scaling=='init':
win_scaling='auto'
else:
raise ValueError('function plot() : available color codes are b,r,g,k,m,c,y,w')
else:
raise Exception('function plot() : error using arguments')
def show():
global fenetre, limits, points, lines, textes, xmin, ymin, xmax, ymax, win_scaling, axis_display, color_count
def RGB(c):
if c=="k" or c=="black":
return (0,0,0)
elif c=="b" or c=="blue":
return (0,0,255)
elif c=="g" or c=="green":
return (0,255,0)
elif c=="r" or c=="red":
return (255,0,0)
elif c=="c" or c=="cyan":
return (0,255,255)
elif c=="y" or c=="yellow":
return (255,255,0)
elif c=="m" or c=="magenta":
return (255,0,255)
elif c=="w" or c=="white":
return (255,255,255)
else:
raise ValueError("invalid color code")
def printable(x,y):
global limits
return(limits[0]<=x<=limits[2] and limits[3]<=y<=limits[1])
def echelle(a,b):
k=0
e=abs(b-a)
while e>=10 :
e/=10
k+=1
while e<1 :
e*=10
k-=1
return k
def pas(a,b):
pas=10**echelle(a,b)
while (abs(b-a))//pas<4:
pas/=2
return pas
def converttopixel(x,y):
global fenetre,limits
ax=(limits[2]-limits[0])/(fenetre[1]-fenetre[0])
bx=limits[0]-ax*fenetre[0]
xpixel=round(ax*x+bx)
ay=(limits[3]-limits[1])/(fenetre[3]-fenetre[2])
by=limits[1]-ay*fenetre[2]
ypixel=round(ay*y+by)
return xpixel,ypixel
color_count=0
plt.clear_screen()
if win_scaling=='auto':
if xmin==xmax:
if xmin==0:
fenetre[0:2]=[-0.05,0.05]
else:
fenetre[0:2]=[0.95*xmin,1.05*xmin]
else:
fenetre[0:2]=[xmin-0.05*(xmax-xmin),xmax+0.05*(xmax-xmin)]
if ymin==ymax:
if ymin==0:
fenetre[2:4]=[-0.05,0.05]
else:
fenetre[2:4]=[0.95*ymin,1.05*ymin]
else:
fenetre[2:4]=[ymin-0.05*(ymax-ymin),ymax+0.05*(ymax-ymin)]
if axis_display=='on' or axis_display=='boxplot':
for i in range(limits[0],limits[2]+1):
plt.set_pixel(i,limits[1],RGB("k"))
for j in range(limits[3],limits[1]+1):
plt.set_pixel(limits[0],j,RGB("k"))
fenetreb=sorted([fenetre[0],fenetre[1]])+sorted([fenetre[2],fenetre[3]])
gx=round(fenetreb[0],-echelle(fenetreb[0],fenetreb[1]))
gy=round(fenetreb[2],-echelle(fenetreb[2],fenetreb[3]))
if axis_display=='boxplot':
for i in range(nbre_boite):
y=fenetre[2]
xpixel,ypixel=converttopixel(i+1,y)
plt.set_pixel(xpixel,ypixel+1,RGB("k"))
plt.set_pixel(xpixel,ypixel+2,RGB("k"))
plt.set_pixel(xpixel,ypixel+3,RGB("k"))
plt.draw_string(xpixel,ypixel+13,str(round(i+1,8)),[0,0,0],"small")
else :
for i in range(-11,11):
x=gx+i*pas(fenetreb[0],fenetreb[1])
y=fenetre[2]
xpixel,ypixel=converttopixel(x,y)
if printable(xpixel,ypixel):
plt.set_pixel(xpixel,ypixel+1,RGB("k"))
plt.set_pixel(xpixel,ypixel+2,RGB("k"))
plt.set_pixel(xpixel,ypixel+3,RGB("k"))
plt.draw_string(xpixel,ypixel+13,str(round(x,8)),[0,0,0],"small")
for j in range(-11,11):
x=fenetre[0]
y=gy+j*pas(fenetreb[2],fenetreb[3])
xpixel,ypixel=converttopixel(x,y)
if printable(xpixel,ypixel):
plt.set_pixel(xpixel-1,ypixel,RGB("k"))
plt.set_pixel(xpixel-2,ypixel,RGB("k"))
plt.set_pixel(xpixel-3,ypixel,RGB("k"))
plt.draw_string(xpixel-40,ypixel,str(round(y,8)),[0,0,0],"small")
if points!=[[]]:
if points[0]==[]:
del points[0]
for i in range(len(points)):
xpixel,ypixel=converttopixel(points[i][0],points[i][1])
if printable(xpixel,ypixel) and points[i][2]!=None:
for j in range(-2,3):
plt.set_pixel(xpixel+j,ypixel,RGB(points[i][2]))
plt.set_pixel(xpixel,ypixel+j,RGB(points[i][2]))
if textes!=[[]]:
if textes[0]==[]:
del textes[0]
for i in range(len(textes)):
xpixel,ypixel=converttopixel(textes[i][0],textes[i][1])
if printable(xpixel,ypixel):
plt.draw_string(xpixel,ypixel,textes[i][2],[0,0,0],"small")
if lines!=[[]]:
if lines[0]==[]:
del lines[0]
for i in range(len(lines)):
xpixel1,ypixel1=converttopixel(lines[i][0],lines[i][1])
xpixel2,ypixel2=converttopixel(lines[i][2],lines[i][3])
deltax=abs(xpixel2-xpixel1)
deltay=abs(ypixel2-ypixel1)
if deltax==deltay==0:
if printable(xpixel1,ypixel1):
plt.set_pixel(xpixel1,ypixel1,RGB(lines[i][4]))
if deltax<=1 and deltay<=1:
if printable(xpixel1,ypixel1):
plt.set_pixel(xpixel1,ypixel1,RGB(lines[i][4]))
plt.set_pixel(xpixel2,ypixel2,RGB(lines[i][4]))
if deltax>=deltay and deltax!=0:
m=(ypixel2-ypixel1)/(xpixel2-xpixel1)
p=ypixel1-m*xpixel1
xpixelmin=max(limits[0],min(xpixel1,xpixel2))
xpixelmax=min(limits[2],max(xpixel1,xpixel2))
if xpixelmin<=limits[2] and xpixelmax>=limits[0]:
for xpixel in range(xpixelmin,xpixelmax+1):
ypixel=round(m*xpixel+p)
if printable(xpixel,ypixel):
plt.set_pixel(xpixel,ypixel,RGB(lines[i][4]))
if deltay>deltax:
m=(xpixel2-xpixel1)/(ypixel2-ypixel1)
p=xpixel1-m*ypixel1
ypixelmin=max(limits[3],min(ypixel1,ypixel2))
ypixelmax=min(limits[1],max(ypixel1,ypixel2))
if ypixelmin<=limits[1] and ypixelmax>=limits[3]:
for ypixel in range(ypixelmin,ypixelmax+1):
xpixel=round(m*ypixel+p)
if printable(xpixel,ypixel):
plt.set_pixel(xpixel,ypixel,RGB(lines[i][4]))
axis([limits[0]-50,limits[2],limits[1]+50,limits[3]])
axis("off")
plt.show_screen()
points=[[]]
lines=[[]]
textes=[[]]
xmin,xmax,ymin,ymax=0,1,0,1
fenetre=[0,1,0,1]
axis_display='on'
win_scaling='init'
color_count=0
def bar(val,eff,lar=0.8):
val=list(val)
eff=list(eff)
global color_count
if isinstance(val,(list,tuple)) and isinstance(eff,(list,tuple)):
if len(val)==len(eff):
for i in range(len(val)):
plot([val[i]-lar/2,val[i]-lar/2],[0,eff[i]],color_auto[color_count%7])
plot([val[i]+lar/2,val[i]+lar/2],[0,eff[i]],color_auto[color_count%7])
plot([val[i]-lar/2,val[i]+lar/2],[eff[i],eff[i]],color_auto[color_count%7])
color_count+=1
else:
raise ValueError('function bar() : lists must have same dimension')
elif isinstance(val,(int,float)) and isinstance(eff,(int,float)):
for i in range(len(val)):
plot([val[i]-lar/2,val[i]-lar/2],[0,eff[i]],color_auto[color_count%7])
plot([val[i]+lar/2,val[i]+lar/2],[0,eff[i]],color_auto[color_count%7])
plot([val[i]-lar/2,val[i]+lar/2],[eff[i],eff[i]],color_auto[color_count%7])
color_count+=1
else:
raise ValueError('function bar() : error using arguments or arguments not available in this version')
def scatter(xlist,ylist):
xlist=list(xlist)
ylist=list(ylist)
global color_count
if isinstance(xlist,(list,tuple)) and isinstance(ylist,(list,tuple)):
if len(xlist)==len(ylist):
for i in range(len(xlist)):
plot(xlist[i],ylist[i],color_auto[color_count%7])
color_count+=1
else:
raise ValueError('function scatter() : x and y must have same dimension')
elif isinstance(xlist,(int,float)) and isinstance(ylist,(int,float)):
plot(xlist,ylist,color_auto[color_count%7])
color_count+=1
else:
raise ValueError('function scatter() : error using arguments or arguments not available in this version')
def boxplotFR(L):
L=list(L)
global fenetre,color_count,nbre_boite, axis_display,win_scaling
print("boxplotFR:definition \nfrancaise du \ndiagramme en boite")
axis_display='boxplot'
n=len(L)
if type(L[0])==int or type(L[0])==float:
n=1
nbre_boite=n
largeur=0.3/n
def mediane(l):
l=sorted(l)
r=len(l)
if r%2==0:
return (l[r//2]+l[r//2-1])/2
else:
return l[r//2]
def quartiles(l):
l=sorted(l)
r=len(l)
return (l[r//4],l[(3*r)//4])
def deciles(l):
l=sorted(l)
r=len(l)
return (l[r//10],l[(9*r)//10])
for i in range(n):
if n==1:
if type(L[0])==int or type(L[0])==float:
K=L
else:
K=L[0]
else :
K=L[i]
if type(K)==int or type(K)==float:
plot([i+1-largeur,i+1+largeur],[K,K],'r')
elif type(K[0])==int or type(K[0])==float:
K=sorted(K)
p=len(K)
Q1=quartiles(K)[0]
Q3=quartiles(K)[1]
D1=deciles(K)[0]
D9=deciles(K)[1]
plot([i+1-largeur,i+1+largeur,i+1+largeur,i+1-largeur,i+1-largeur],[Q1,Q1,Q3,Q3,Q1],'k')
plot([i+1,i+1],[Q1,D1],'k')
plot([i+1,i+1],[Q3,D9],'k')
plot([i+1-largeur/2,i+1+largeur/2],[D1,D1],'k')
plot([i+1-largeur/2,i+1+largeur/2],[D9,D9],'k')
plot(i+1,K[0],'k')
plot(i+1,K[p-1],'k')
plot([i+1-largeur,i+1+largeur],[mediane(K),mediane(K)],'r')
elif type(min(L[0]))!=int and type(min(L[0]))!=float:
raise ValueError('wrong type of argument')
if type(L[0])==int or type(L[0])==float:
fenetre=[0,2,min(L)-1,max(L)+1]
Max=max(L)
else:
Min=min(L[0])
Max=max(L[0])
for i in range(len(L)):
if type(L[i])==int or type(L[i])==float:
if L[i]<Min:
Min=L[i]
if L[i]>Max:
Max=L[i]
else:
if min(L[i])<Min:
Min=min(L[i])
if max(L[i])>Max:
Max=max(L[i])
fenetre=[0,len(L)+1,Min-1,Max+1]
win_scaling='fixed'
text(len(L)+1/4,Max+1/2,"boxplotFR")
def boxplot(L,**kwargs):
L=list(L)
global fenetre,color_count,nbre_boite, axis_display,win_scaling
whis=kwargs.get('whis',1.5)
axis_display='boxplot'
n=len(L)
if type(L[0])==int or type(L[0])==float:
n=1
nbre_boite=n
largeur=0.3/n
def mediane(l):
r=1
if type(l)!=int and type(l)!=float:
l=sorted(l)
r=len(l)
if r%2==0 and r//2>0:
return (l[r//2]+l[r//2-1])/2,l[:r//2],l[r//2:]
else:
return l[r//2],l[:r//2],l[r//2+1:]
return l,l,l
if type(L[0])==int or type(L[0])==float:
if min(L)==max(L):
ampl=1
else:
ampl=max(L)-min(L)
fenetre=[0,2,min(L)-ampl/20,max(L)+ampl/20]
else:
Min=min(L[0])
Max=max(L[0])
for i in range(len(L)):
if type(L[i])==int or type(L[i])==float:
if L[i]<Min:
Min=L[i]
if L[i]>Max:
Max=L[i]
else:
if min(L[i])<Min:
Min=min(L[i])
if max(L[i])>Max:
Max=max(L[i])
if Min==Max:
ampl=1
else:
ampl=Max-Min
fenetre=[0,len(L)+1,Min-ampl/20,Max+ampl/20]
win_scaling='fixed'
for i in range(n):
if n==1:
if type(L[0])==int or type(L[0])==float:
K=L
else:
K=L[0]
else :
K=L[i]
if type(K)==int or type(K)==float:
plot([i+1-largeur,i+1+largeur],[K,K],'r')
elif type(K[0])==int or type(K[0])==float:
K=sorted(K)
p=len(K)
Q1,Q3=mediane(mediane(K)[1])[0],mediane(mediane(K)[2])[0]
down=0
if Q1-whis*(Q3-Q1)<=K[0]:
down=0
else :
while Q1-whis*(Q3-Q1)>K[down]:
down+=1
up=p-1
if Q3+whis*(Q3-Q1)>=K[p-1]:
up=p-1
else :
while Q3+whis*(Q3-Q1)<K[up]:
up-=1
plot([i+1-largeur,i+1+largeur,i+1+largeur,i+1-largeur,i+1-largeur],[Q1,Q1,Q3,Q3,Q1],'k')
plot([i+1,i+1],[Q1,K[down]],'k')
plot([i+1,i+1],[Q3,K[up]],'k')
plot([i+1-largeur/2,i+1+largeur/2],[K[down],K[down]],'k')
plot([i+1-largeur/2,i+1+largeur/2],[K[up],K[up]],'k')
from math import pi
from math import cos
from math import sin
if down>0:
for t in range(down):
x=[i+1+0.05*(fenetre[1])/3*cos(2*j*pi/50) for j in range(50)]
y=[K[t]+0.05*(fenetre[3]-fenetre[2])/3*sin(2*j*pi/50) for j in range(50)]
plot(x,y,'k')
if up<p-1:
for t in range(p-1-up):
x=[i+1+0.05*(fenetre[1])/3*cos(2*j*pi/50) for j in range(50)]
y=[K[p-1-t]+0.05*(fenetre[3]-fenetre[2])/3*sin(2*j*pi/50) for j in range(50)]
plot(x,y,'k')
plot([i+1-largeur,i+1+largeur],[mediane(K)[0],mediane(K)[0]],'r')
elif type(min(L[0]))!=int and type(min(L[0]))!=float:
raise ValueError('wrong type of argument')
def arrow(x,y,dx,dy,**kwargs):
global win_scaling
a=x+dx
b=y+dy
win_scaling='fixed'
color=kwargs.get('ec','k')
color=kwargs.get('edgecolor',color)
headcolor=kwargs.get('fc',color)
headcolor=kwargs.get('facecolor',headcolor)
L=kwargs.get('head_width',0.003)
l=kwargs.get('head_length',1.5*L)
plot((x,a),(y,b),color)
def resol(A,B,C):
D=B**2-4*A*C
if D>0:
return((-B-D**0.5)/(2*A),(-B+D**0.5)/(2*A))
if dx==0:
if dy>=0:
c=1
else:
c=-1
plot((a-L/2,a+L/2,a,a-L/2),(b,b,b+c*l,b),color)
elif dy==0:
if dx>=0:
c=1
else:
c=-1
plot((a,a,a+c*l,a),(b-L/2,b+L/2,b,b-L/2),color)
else:
m=dy/dx
p=y-m*x
S=resol(m**2+1,2*(-a-b*m+m*p),p**2+a**2+b**2-l**2-2*b*p)
if S[0]*dx<0:
X=S[0]
else:
X=S[1]
Y=m*X+p
k=b+a/m
T=resol(1+1/m**2,2*(-a-k/m+b/m),a**2+k**2-2*b*k+b**2-(L**2)/4)
plot((T[0],T[1],X,T[0]),(-T[0]/m+k,-T[1]/m+k,Y,-T[0]/m+k),headcolor)

View file

@ -0,0 +1,33 @@
from casioplot import *
from gint import *
B=(0,0,0)
W=(255,255,255)
clear_screen()
set_pixel(1, 1, B)
for x in range(10):
set_pixel(x+1,3,B)
for y in range(40):
for x in range(10):
set_pixel(x+1,y+5,B)
draw_string(20,1,"Hello,",B,"large")
draw_string(20,11,"World!",B,"small")
img = b'\x04@"\x00\x0e\xa6W\x00\x0e\xafW\x00\x05\x1f\x89\x00u/J\xc0\xf5F*\xe0'+\
b'\xe4\xc92\xe0\x8cP\xa1 \x8c{\xe1 \x8c\xbf\xb1 \x8c\xb1\xb1 \x9c\x950'+\
b'\xa0\x9e\xb1\x90\xa0\x8e\x7f\xc3 \xc3\xfb\xfc`\xe0\x1d\xc0\xe0\xbf\x12'+\
b'\x1f\xa0_\t\x1f@ \x89 \x80\x1f\x92?\x00'
for y in range(20):
for x in range(27):
offset = y * 4 + (x // 8)
bit = 0x80 >> (x & 7)
if img[offset] & bit:
set_pixel(x+30,y+30,B)
show_screen()
k=getkey()

View file

@ -0,0 +1,11 @@
import matplotl as p
import gint as g
g.dclear(g.C_WHITE)
x=[119.1,119.3,119.5,119.6,119.9,120.0,120.1,120.3,120.4]
y=[1,3,4,3,1,3,1,3,1]
p.bar(x,y,0.08)
p.show()
g.getkey()

View file

@ -0,0 +1,27 @@
from casioplot import *
from turtle import *
import gint as g
def koch(n,l):
if n==0:
forward(l)
else:
koch(n-1,l/3)
left(60)
koch(n-1,l/3)
right(120)
koch(n-1,l/3)
left(60)
koch(n-1,l/3)
g.dclear(g.C_WHITE)
pencolor("black")
penup()
goto(-120,-10)
pendown()
koch(4,120)
show_screen()
g.getkey()

View file

@ -0,0 +1,348 @@
#import casioplot
from casioplot import *
from math import sqrt
from math import pi
from math import cos
from math import sin
from math import atan2
# Added by SlyVTT : round() is not implemented in math but in builtins module of MicroPython
from builtins import round
turtleshapes={"classic":[[-9,5],[-9,4],[-8,4],[-8,3],[-8,2],[-8,-2],[-8,-3],[-8,-4],[-9,-4],[-9,-5],[-7,4],[-7,1],[-7,0],[-7,-1],[-7,-4],[-6,3],[-6,-3],[-5,3],[-5,-3],[-4,2],[-4,-2],[-3,2],[-3,-2],[-2,1],[-2,-1],[-1,1],[-1,-1],[0,0]],"turtle": [[-3,3],[2,3],[-2,2],[-1,2],[0,2],[1,2],[-2,1],[-1,1],[1,1],[0,1],[2,1],[3,1],[-2,0],[-1,0],[0,0],[1,0],[-1,-1],[-2,-1],[0,-1],[1,-1],[2,0],[3,0],[-3,-2],[2,-2]]}
turtle_name="classic"
turtle_data=turtleshapes[turtle_name]
turtle_pos=[0,0]
turtle_angle=0
turtle_color=(0,0,0)
writing=True
pen_size=1
turtle_buffer=[[]]
turtle_speed=5
frame_count=0
turtle_visible=True
# Added by SlyVTT : round() is not implemented in math but in builtins module of MicroPython
# So I added this simple function aiming at replacing round( n, nbdigits )
def roundedpython( n, nbdigits ):
nbis = n * pow(10, nbdigits)
r = round( nbis )
return r / pow(10, nbdigits)
def draw_turtle(x,y,a,c):
global turtle_buffer
def inbuffer(x,y):
inlist=False
for i in range(1,len(turtle_buffer)):
if x==turtle_buffer[i][0] and y==turtle_buffer[i][1]:
inlist=True
return inlist
if turtle_visible==True:
u=cos(a*pi/180)
v=sin(a*pi/180)
for point in turtle_data:
xx=x+(point[0]*u-point[1]*v)
yy=y+(point[1]*u+point[0]*v)
xpixel=int(round(xx+192))
ypixel=int(round(-yy+96))
if (0<=xpixel<=383 and 0<=ypixel<=191):
if not inbuffer(xpixel,ypixel):
turtle_buffer+=[[xpixel,ypixel,get_pixel(xpixel,ypixel)]]
set_pixel(xpixel,ypixel,c)
def erase_turtle():
global turtle_buffer
for i in range(1,len(turtle_buffer)):
xpixel=turtle_buffer[i][0]
ypixel=turtle_buffer[i][1]
if turtle_buffer[i][2]!=None :
lastcolor=turtle_buffer[i][2]
else:
lastcolor=(255,255,255)
set_pixel(xpixel,ypixel,lastcolor)
turtle_buffer=[[]]
def pen_brush(x,y,turtle_color):
global frame_count
erase_turtle()
xpixel=int(round(x+192))
ypixel=int(round(-y+96))
if writing==True and (0<=xpixel<=383 and 0<=ypixel<=191) :
colorpixel=(int(turtle_color[0]*255), int(turtle_color[1]*255),int(turtle_color[2]*255))
set_pixel(xpixel,ypixel,colorpixel)
frame_count+=1
if turtle_speed!=0:
if frame_count%(turtle_speed*4)==0:
draw_turtle(x,y,turtle_angle,colorpixel)
show_screen()
else :
if frame_count%500==0:
draw_turtle(x,y,turtle_angle,colorpixel)
show_screen()
def refresh_turtle():
c=(int(turtle_color[0]*255), int(turtle_color[1]*255),int(turtle_color[2]*255))
erase_turtle()
draw_turtle(turtle_pos[0],turtle_pos[1],turtle_angle,c)
show_screen()
def back(n):
forward(-n)
def backward(n):
back(n)
def bk(n):
back(n)
def circle(radius,extent=360):
global turtle_angle, turtle_pos
x1=turtle_pos[0]
y1=turtle_pos[1]
if round(radius)==0:
pen_brush(x1,y1,turtle_color)
turtle_angle+=extent
elif roundedpython(extent,8)==0:
pen_brush(x1,y1,turtle_color)
else:
e=radius/abs(radius)
theta=extent*pi/180*e
Rx=cos(theta)
Ry=sin(theta)
Dx=radius*sin(turtle_angle*pi/180)
Dy=-radius*cos(turtle_angle*pi/180)
xcenter=x1-Dx
ycenter=y1-Dy
nbpixelarc=int(round(abs(radius*theta*1.05)))
angle=turtle_angle
if nbpixelarc!=0:
alpha=theta/nbpixelarc
for k in range(nbpixelarc+1):
x=xcenter+Dx*cos(alpha*k)-Dy*sin(alpha*k)
y=ycenter+Dx*sin(alpha*k)+Dy*cos(alpha*k)
turtle_angle+=alpha*180/pi
pen_brush(x,y,turtle_color)
turtle_pos[0]=xcenter+Dx*Rx-Dy*Ry
turtle_pos[1]=ycenter+Dx*Ry+Dy*Rx
turtle_angle=angle+extent*e
refresh_turtle()
def clear():
erase_turtle()
clear_screen()
show_screen()
refresh_turtle()
def distance(x,y):
return sqrt((x-turtle_pos[0])**2+(y-turtle_pos[1])**2)
def down():
global writing
writing=True
def fd(d):
forward(d)
def forward(d):
global turtle_pos
dx=d*cos(turtle_angle*pi/180)
dy=d*sin(turtle_angle*pi/180)
x1=turtle_pos[0]
y1=turtle_pos[1]
if round(abs(d))==0:
pen_brush(x1+dx,y1+dy,turtle_color)
elif abs(dx)>=abs(dy):
e=int(dx/abs(dx))
m=dy/dx
p=y1-m*x1
for x in range(int(round(x1)),int(round(x1+dx)),e):
pen_brush(x,m*x+p,turtle_color)
else:
e=int(dy/abs(dy))
m=dx/dy
p=x1-m*y1
for y in range(int(round(y1)),int(round(y1+dy)),e):
pen_brush(m*y+p,y,turtle_color)
turtle_pos[0]+=dx
turtle_pos[1]+=dy
refresh_turtle()
def goto(x,y):
a=turtle_angle
setheading(towards(x,y))
forward(distance(x,y))
setheading(a)
refresh_turtle()
def heading():
return turtle_angle
def hideturtle():
global turtle_visible
turtle_visible=False
refresh_turtle()
def home():
global turtle_pos,turtle_angle
turtle_pos[0]=turtle_pos[1]=0
turtle_angle=0
refresh_turtle()
def ht():
hideturtle()
def isdown():
return writing
def isvisible():
return turtle_visible
def left(a):
right(-a)
def lt(a):
right(-a)
def pd():
down()
def pencolor(*c):
global turtle_color
colornames={"black":(0,0,0),"blue":(0,0,1),"green":(0,1,0),"red":(1,0,0),"cyan":(0,1,1),"yellow":(1,1,0),"magenta":(1,0,1),"white":(1,1,1),"orange":(1,0.65,0),"purple":(0.66,0,0.66),"brown":(0.75,0.25,0.25),"pink":(1,0.75,0.8),"grey":(0.66,0.66,0.66)}
if c==():
return turtle_color
elif c[0] in colornames:
turtle_color=colornames[c[0]]
elif isinstance(c[0],(list,tuple)) and len(c[0])==3 and isinstance(c[0][0],(int,float)) and isinstance(c[0][1],(int,float)) and isinstance(c[0][2],(int,float)) and 0<=c[0][0]<=1 and 0<=c[0][1]<=1 and 0<=c[0][2]<=1:
turtle_color=list(c[0])
else:
raise ValueError('error using pencolor : enter a color text or 3 floats between 0 and 1')
refresh_turtle()
def pendown():
down()
def pensize(n):
global pen_size
pen_size=n
refresh_turtle()
def penup():
global writing
writing=False
def pos():
return (xcor(),ycor())
def position():
return (xcor(),ycor())
def pu():
penup()
def reset():
global turtle_color,writing,pen_size,speed,turtle_visible
clear()
turtle_color=(0,0,0)
home()
writing=True
pen_size=1
speed=5
turtle_visible=True
shape("classic")
refresh_turtle()
def right(a):
global turtle_angle
turtle_angle-=a
refresh_turtle()
def rt(a):
right(a)
def seth(a):
setheading(a)
def setheading(a):
global turtle_angle
turtle_angle=a
refresh_turtle()
def setpos(x,y):
goto(x,y)
refresh_turtle()
def setposition(x,y):
setpos(x,y)
def setx(x):
global turtle_pos
turtle_pos[0]=x
refresh_turtle()
def sety(y):
global turtle_pos
turtle_pos[1]=y
refresh_turtle()
def shape(text=None):
global turtle_name,turtle_data
if text==None:
return turtle_name
elif text in turtleshapes:
turtle_name=text
turtle_data=turtleshapes[text]
else:
raise ValueError('available shapes: "classic" or "turtle"')
refresh_turtle()
def showturtle():
global turtle_visible
turtle_visible=True
refresh_turtle()
def speed(v=None):
global turtle_speed
speedwords = {'fastest':0, 'fast':10, 'normal':6, 'slow':3, 'slowest':1 }
if v==None:
pass
elif isinstance(v,(int,float)) and (v<=0.5 or v>=10.5):
turtle_speed=0
elif isinstance(v,(int,float)) and (0.5<v<10.5):
turtle_speed=int(round(v))
elif isinstance(v,str) and v in speedwords:
turtle_speed=speedwords[v]
else:
raise ValueError("Error using function speed: enter a real between 0 & 10")
def st():
showturtle()
def towards(x,y):
global turtle_pos
if roundedpython(x-turtle_pos[0],8)==0 and roundedpython(y-turtle_pos[1],8)==0:
return 0
else:
return (atan2(y-turtle_pos[1],x-turtle_pos[0])*180/pi)
def up():
penup()
def width(n):
pensize(n)
def write(text):
xpixel=int(round(turtle_pos[0]+192))
ypixel=int(round(-turtle_pos[1]+96))
c=(int(turtle_color[0]*255), int(turtle_color[1]*255),int(turtle_color[2]*255))
draw_string(xpixel,ypixel,str(text),c,"small")
show_screen()
def xcor():
global turtle_pos
return roundedpython(turtle_pos[0],6)
def ycor():
global turtle_pos
return roundedpython(turtle_pos[1],6)

View file

@ -0,0 +1,7 @@
import gint
dclear(C_WHITE)
dtext( 1, 1, C_BLACK, "Hello" )
dupdate()
k=getkey()

View file

@ -0,0 +1,7 @@
import gint as g
g.dclear(g.C_WHITE)
g.dtext( 1, 1, g.C_BLACK, "Hello" )
g.dupdate()
k=g.getkey()

View file

@ -0,0 +1,7 @@
from gint import *
dclear(C_WHITE)
dtext( 1, 1, C_BLACK, "Hello" )
dupdate()
k=getkey()

View file

@ -0,0 +1,8 @@
from time import *
t1 = time()
for i in range(100000):
print(i)
t2 = time()
print(f"{t2-t1} seconds")

View file

@ -0,0 +1,36 @@
from gint import *
dclear(C_WHITE)
dtext(1,1,3,"test touche")
dupdate()
a=["time","mod","shift","alpha","type","touche"]
while True:
k=getkey()
dclear(C_WHITE)
for i in range(0,6):
dtext(1,i*10,3,a[i])
dtext(60,i*10,3,str(k[i]))
dtext(1,70,3,"press VARS to skip")
dupdate()
if k.key==KEY_VARS: break
#dgrayon()
dclear(C_WHITE)
#if dgrayenabled:
# dtext( 1,70,C_LIGHT,"Gray Mode Enabled")
dcircle( 20, 20, 15, C_BLACK )
dcirclefill( 50, 20, 15, C_LIGHT, C_BLACK )
dellipse( 20, 40, 10, 15, C_BLACK )
dellipsefill( 50, 40, 10, 15, C_DARK, C_BLACK )
dellipserect( 70, 20, 90, 40, C_LIGHT )
dellipserectfill( 70, 40, 90, 60, C_LIGHT, C_DARK )
dupdate()
#dgrayoff();
#if not dgrayenabled:
# dtext( 1,90,C_BLACK,"Gray Mode Disabled")
#dupdate()
k=getkey()

View file

@ -152,6 +152,7 @@ extern font_t const font_4x4, font_4x6, font_5x7;
#define _(fx, cg) (fx)
#else
extern bopti_image_t const img_modifier_states;
extern font_t const font_4x4, font_4x6, font_5x7;
#define _(fx, cg) (cg)
#endif

View file

@ -16,9 +16,15 @@ extern font_t font_4x4;
extern font_t font_4x6;
extern font_t font_5x7;
#else
<<<<<<< HEAD
extern font_t font_4x4;
extern font_t font_4x6;
extern font_t font_5x7;
=======
extern font_t font_9;
extern font_t font_13;
extern font_t font_19;
>>>>>>> upstream/dev
#endif
/* TODO: casioplot: Call show_screen() when program finishes */
@ -133,7 +139,14 @@ static mp_obj_t draw_string(size_t n, mp_obj_t const *args)
#ifdef FX9860G
font_t const *fonts[3] = { &font_4x4, &font_4x4, &font_5x7 };
#else
<<<<<<< HEAD
/* TODO: casioplot: draw_string(): Add fonts for CG50 */
//font_t const *fonts[3] = {
// dfont_default(), dfont_default(), dfont_default() };
font_t const *fonts[3] = { &font_4x4, &font_4x6, &font_5x7 };
=======
font_t const *fonts[3] = { &font_9, &font_13, &font_19 };
>>>>>>> upstream/dev
#endif
color_t color = C_BLACK;

View file

@ -13,6 +13,9 @@
#include "py/objtuple.h"
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/gray.h>
#include "primitives.h"
void pe_enter_graphics_mode(void);
@ -249,6 +252,72 @@ STATIC mp_obj_t modgint_dvline(mp_obj_t arg1, mp_obj_t arg2)
return mp_const_none;
}
<<<<<<< HEAD
STATIC mp_obj_t modgint_dellipse(size_t n, mp_obj_t const *args)
{
mp_int_t xm = mp_obj_get_int(args[0]);
mp_int_t ym = mp_obj_get_int(args[1]);
mp_int_t a = mp_obj_get_int(args[2]);
mp_int_t b = mp_obj_get_int(args[3]);
mp_int_t color = mp_obj_get_int(args[4]);
dellipse(xm, ym, a, b, color);
return mp_const_none;
}
STATIC mp_obj_t modgint_dellipserect(size_t n, mp_obj_t const *args)
{
mp_int_t x0 = mp_obj_get_int(args[0]);
mp_int_t y0 = mp_obj_get_int(args[1]);
mp_int_t x1 = mp_obj_get_int(args[2]);
mp_int_t y1 = mp_obj_get_int(args[3]);
mp_int_t color = mp_obj_get_int(args[4]);
dellipserect(x0, y0, x1, y1, color);
return mp_const_none;
}
STATIC mp_obj_t modgint_dcircle(size_t n, mp_obj_t const *args)
{
mp_int_t xm = mp_obj_get_int(args[0]);
mp_int_t ym = mp_obj_get_int(args[1]);
mp_int_t r = mp_obj_get_int(args[2]);
mp_int_t color = mp_obj_get_int(args[3]);
dcircle(xm, ym, r, color);
return mp_const_none;
}
STATIC mp_obj_t modgint_dellipsefill(size_t n, mp_obj_t const *args)
{
mp_int_t xm = mp_obj_get_int(args[0]);
mp_int_t ym = mp_obj_get_int(args[1]);
mp_int_t a = mp_obj_get_int(args[2]);
mp_int_t b = mp_obj_get_int(args[3]);
mp_int_t color_fill = mp_obj_get_int(args[4]);
mp_int_t color_border = mp_obj_get_int(args[5]);
dellipse_fill(xm, ym, a, b, color_fill, color_border);
return mp_const_none;
}
STATIC mp_obj_t modgint_dellipserectfill(size_t n, mp_obj_t const *args)
{
mp_int_t x0 = mp_obj_get_int(args[0]);
mp_int_t y0 = mp_obj_get_int(args[1]);
mp_int_t x1 = mp_obj_get_int(args[2]);
mp_int_t y1 = mp_obj_get_int(args[3]);
mp_int_t color_fill = mp_obj_get_int(args[4]);
mp_int_t color_border = mp_obj_get_int(args[5]);
dellipserect_fill(x0, y0, x1, y1, color_fill, color_border);
return mp_const_none;
}
STATIC mp_obj_t modgint_dcirclefill(size_t n, mp_obj_t const *args)
{
mp_int_t xm = mp_obj_get_int(args[0]);
mp_int_t ym = mp_obj_get_int(args[1]);
mp_int_t r = mp_obj_get_int(args[2]);
mp_int_t color_fill = mp_obj_get_int(args[3]);
mp_int_t color_border = mp_obj_get_int(args[4]);
dcircle_fill(xm, ym, r, color_fill, color_border);
=======
STATIC mp_obj_t modgint_dcircle(size_t n_args, const mp_obj_t *args)
{
mp_int_t x = mp_obj_get_int(args[0]);
@ -271,6 +340,7 @@ STATIC mp_obj_t modgint_dellipse(size_t n_args, const mp_obj_t *args)
mp_int_t border = mp_obj_get_int(args[5]);
dellipse(x1, y1, x2, y2, fill, border);
>>>>>>> upstream/dev
return mp_const_none;
}
@ -319,6 +389,15 @@ FUN_BETWEEN(dellipse, 6, 6);
FUN_BETWEEN(dtext_opt, 8, 8);
FUN_BETWEEN(dtext, 4, 4);
/*Added some basic cicle/ellipse primitives*/
/*SlyVTT 2024/01/02 - all code in sh/primitives.c & sh/primitives.h*/
FUN_BETWEEN(dellipse, 5, 5);
FUN_BETWEEN(dellipserect, 5, 5);
FUN_BETWEEN(dcircle, 4, 4);
FUN_BETWEEN(dellipsefill, 6, 6);
FUN_BETWEEN(dellipserectfill, 6, 6);
FUN_BETWEEN(dcirclefill, 5, 5);
/* Module definition */
// Helper: define object "modgint_F_obj" as object "F" in the module
@ -473,6 +552,16 @@ STATIC const mp_rom_map_elem_t modgint_module_globals_table[] = {
OBJ(dellipse),
OBJ(dtext_opt),
OBJ(dtext),
/*Added some basic cicle/ellipse primitives*/
/*SlyVTT 2024/01/02 - all code in sh/primitives.c & sh/primitives.h*/
OBJ(dellipse),
OBJ(dellipserect),
OBJ(dcircle),
OBJ(dellipsefill),
OBJ(dellipserectfill),
OBJ(dcirclefill),
};
STATIC MP_DEFINE_CONST_DICT(
modgint_module_globals, modgint_module_globals_table);

163
ports/sh/primitives.c Normal file
View file

@ -0,0 +1,163 @@
/*Added some basic cicle/ellipse primitives*/
/*SlyVTT 2024/01/02 - all code in sh/primitives.c & sh/primitives.h*/
#include <gint/display.h>
#include "./primitives.h"
#define abs(x) ((x)>=0 ? (x) : (-x))
void dellipse(int xm, int ym, int a, int b, int c) {
long x = -a, y = 0; /* II. quadrant from bottom left to top right */
long e2 = b, dx = (1 + 2 * x) * e2 * e2; /* error increment */
long dy = x * x, err = dx + dy; /* error of 1.step */
long a2 = (long)a * a;
long b2 = (long)b * b;
do {
dpixel(xm - x, ym + y, c); /* I. Quadrant */
dpixel(xm + x, ym + y, c); /* II. Quadrant */
dpixel(xm + x, ym - y, c); /* III. Quadrant */
dpixel(xm - x, ym - y, c); /* IV. Quadrant */
e2 = 2 * err;
if (e2 >= dx) {
x++;
err += dx += 2 * b2;
} /* x step */
if (e2 <= dy) {
y++;
err += dy += 2 * a2;
} /* y step */
} while (x <= 0);
while (y++ < b) { /* to early stop for flat ellipses with a=1, */
dpixel(xm, ym + y, c); /* -> finish tip of ellipse */
dpixel(xm, ym - y, c);
}
}
void dellipserect(int x0, int y0, int x1, int y1,
int c) { /* rectangular parameter enclosing the ellipse */
long a = abs(x1 - x0), b = abs(y1 - y0), b1 = b & 1; /* diameter */
double dx = 4 * (1.0 - a) * b * b,
dy = 4 * (b1 + 1) * a * a; /* error increment */
double err = dx + dy + b1 * a * a, e2; /* error of 1.step */
if (x0 > x1) {
x0 = x1;
x1 += a;
} /* if called with swapped points */
if (y0 > y1)
y0 = y1; /* .. exchange them */
y0 += (b + 1) / 2;
y1 = y0-b1; /* starting pixel */
a = 8 * a * a;
b1 = 8 * b * b;
do {
dpixel(x1, y0, c); /* I. Quadrant */
dpixel(x0, y0, c); /* II. Quadrant */
dpixel(x0, y1, c); /* III. Quadrant */
dpixel(x1, y1, c); /* IV. Quadrant */
e2 = 2 * err;
if (e2 <= dy) {
y0++;
y1--;
err += dy += a;
} /* y step */
if (e2 >= dx || 2 * err > dy) {
x0++;
x1--;
err += dx += b1;
} /* x */
} while (x0 <= x1);
while (y0 - y1 <= b) { /* to early stop of flat ellipses a=1 */
dpixel(x0 - 1, y0, c); /* -> finish tip of ellipse */
dpixel(x1 + 1, y0++, c);
dpixel(x0 - 1, y1, c);
dpixel(x1 + 1, y1--, c);
}
}
void dcircle(int xm, int ym, int r, int c)
{
dellipse( xm, ym, r, r, c);
}
void dellipse_fill(int xm, int ym, int a, int b, int cback, int cborder) {
long x = -a, y = 0; /* II. quadrant from bottom left to top right */
long e2 = b, dx = (1 + 2 * x) * e2 * e2; /* error increment */
long dy = x * x, err = dx + dy; /* error of 1.step */
long a2 = (long)a * a;
long b2 = (long)b * b;
do {
dline(xm - x, ym + y, xm + x, ym + y, cback );
dpixel(xm - x, ym + y, cborder); /* I. Quadrant */
dpixel(xm + x, ym + y, cborder); /* II. Quadrant */
dline(xm - x, ym - y, xm + x, ym - y, cback );
dpixel(xm + x, ym - y, cborder); /* III. Quadrant */
dpixel(xm - x, ym - y, cborder); /* IV. Quadrant */
e2 = 2 * err;
if (e2 >= dx) {
x++;
err += dx += 2 * b2;
} /* x step */
if (e2 <= dy) {
y++;
err += dy += 2 * a2;
} /* y step */
} while (x <= 0);
while (y++ < b) { /* to early stop for flat ellipses with a=1, */
dpixel(xm, ym + y, cborder); /* -> finish tip of ellipse */
dpixel(xm, ym - y, cborder);
}
}
void dellipserect_fill(int x0, int y0, int x1, int y1,
int cback, int cborder) { /* rectangular parameter enclosing the ellipse */
long a = abs(x1 - x0), b = abs(y1 - y0), b1 = b & 1; /* diameter */
double dx = 4 * (1.0 - a) * b * b,
dy = 4 * (b1 + 1) * a * a; /* error increment */
double err = dx + dy + b1 * a * a, e2; /* error of 1.step */
if (x0 > x1) {
x0 = x1;
x1 += a;
} /* if called with swapped points */
if (y0 > y1)
y0 = y1; /* .. exchange them */
y0 += (b + 1) / 2;
y1 = y0-b1; /* starting pixel */
a = 8 * a * a;
b1 = 8 * b * b;
do {
dline( x0, y0, x1, y0, cback );
dpixel(x1, y0, cborder); /* I. Quadrant */
dpixel(x0, y0, cborder); /* II. Quadrant */
dline( x0, y1, x1, y1, cback );
dpixel(x0, y1, cborder); /* III. Quadrant */
dpixel(x1, y1, cborder); /* IV. Quadrant */
e2 = 2 * err;
if (e2 <= dy) {
y0++;
y1--;
err += dy += a;
} /* y step */
if (e2 >= dx || 2 * err > dy) {
x0++;
x1--;
err += dx += b1;
} /* x */
} while (x0 <= x1);
while (y0 - y1 <= b) { /* to early stop of flat ellipses a=1 */
dpixel(x0 - 1, y0, cborder); /* -> finish tip of ellipse */
dpixel(x1 + 1, y0++, cborder);
dpixel(x0 - 1, y1, cborder);
dpixel(x1 + 1, y1--, cborder);
}
}
void dcircle_fill(int xm, int ym, int r, int cback, int cborder)
{
dellipse_fill( xm, ym, r, r, cback, cborder );
}

19
ports/sh/primitives.h Normal file
View file

@ -0,0 +1,19 @@
/*Added some basic cicle/ellipse primitives*/
/*SlyVTT 2024/01/02 - all code in sh/primitives.c & sh/primitives.h*/
#ifndef PRIMITIVES_GINT_H
#define PRIMITIVES_GINT_H
void dellipse(int xm, int ym, int a, int b, int c);
void dellipserect(int x0, int y0, int x1, int y1, int c);
void dcircle(int xm, int ym, int r, int c);
void dellipse_fill(int xm, int ym, int a, int b, int cback, int cborder);
void dellipserect_fill(int x0, int y0, int x1, int y1, int cback, int cborder);
void dcircle_fill(int xm, int ym, int r, int cback, int cborder);
#endif