おはようございます。
暑いっす。。。
アクセスが意外と多いのでちょっと驚いています。
通勤の途中にありますので、いつも眺めています。
富士通さんといえば、富岳ですが、
2021年6月28日に発表されたTOP500においても首位を維持。物理現象をシミュレートするHPCG(High Performance Conjugate Gradient)、人工知能計算のベンチマークHPL-AI、ビッグデーター解析のGraph500においても首位を達成。
3期連続の4冠を達成ですよ。凄いですね。
「LINPACK/TOP500(標準性能指標)」で富岳は京の41倍、 富嶽三十六景でなくて、富岳41京 です。でも目標は100京なんだそうです。
で紹介したプログラム(MicroPython)をエミュレータへ、ベタ打ちして動作させてみようと思いましたが、その気力がありません。
この暑さのせいにしておきます。
その気力のある人のために、usergraphics.pyを改めて紹介します。
これは上記プログラムを動作させるために必要な関数群になります。私のfx-CG50では、動作実績ありのプログラムです。
Good luck!
#Last update 2021/2/6
"""user module
ver 1.0'
Functions:
---------
circle()
line()
locate()
orbit()
r_circle()
grp_color()
#Fontsize = 1point/pixel
X Y
small 8 12
medium 12 16
large 16 24
"""
XMAX = 383
YMAX = 191
from casioplot import *
from math import *
def circle(x, y, r, cp=1, color=7, start=0, stop=1, show=1):
"""
Draw circle around (x,y) with radius r
version 1.0'''
Parameters:
----------
x,y:int
center coordinate
r:float
radius
cp:0 or 1 (int/bool)
0: select rgbcmyk color
1: select rainbow color
default:1
color:
compatible with grp_color()
start:
from radian
default:0←0 radian
stop:
to radian
default:1←2π radian
show:0 or 1 (int/bool)
0: don't transfer to screen
1: transfer to screen
default:1
Returns:
-------
Non
"""
rgb = grp_color(cp, color) #select a color pallet
p = 2*r*2406/383 #pi = 2403/383
a = 2*pi/p
for i in range(p*start,p*stop): #
px = x+r*cos(i*a)
if px<0 or px>XMAX:
continue
py = y+r*sin(i*a)
if py<0 or py>YMAX:
continue
set_pixel(int(px), int(py), rgb)
if show:
show_screen()
def line(x1,y1,x2,y2,cp=0,color=1,show=1):
"""Draw line from (x1,y1) to (x2,y2)
version 1.2'
Parameters:
----------
x1,y1:int
starting coordinate
x2,y2:int
ending coordinate
cp:0 or 1 (int/bool)
0: select rgbcmyk color
1: select rainbow color
default:0
color:
compatible with grp_color()
show:0 or 1 (int/bool)
0: don't transfer to screen
1: transfer to screen
default:1
Returns:
------
Non
"""
rgb=grp_color(cp,color)
dx=x2-x1;dy=y2-y1
if dx==0 and dy==0: #avoid division by 0 error
set_pixel(x1,y1,rgb)
return
if abs(dx)>abs(dy):
if dx: #when dx is not 0
k=int(dx/abs(dx)) #k=1 or -1
slope=dy/dx
for x in range(0,dx,k):
set_pixel(x1+x,y1+int(x*slope),rgb)
else:
if dy: #when dy is not 0
k=int(dy/abs(dy)) #k=1 or -1
slope=dx/dy
for y in range(0,dy,k):
set_pixel(x1+int(y*slope),y1+y,rgb)
if show: #data transfer to screen
show_screen()
def locate(column,row,obj,color=1,size='m',show=1):
"""Locate number or string on graphic screen
version 1.0
Parameters:
----------
column:0-47, row:0-17 (small font)
0-31, 0-11 (medium font)
0-23, 0-7 (large font)
obj:number(int or float)
string(str)
size:'s'
'm'
'l'
default:'m'
color:
compatible with grp_color()
show:0 or 1 (int/bool)
0: don't transfer to screen
1: transfer to screen
default:1
Returns:
-------
None
"""
#set fontsize & pitch
#from 4th argument(size)
dx={'s':8,'m':12,'l':16}
dy={'s':12,'m':16,'l':24}
sz={'s':'small','m':'medium','l':'large'}
#data transfer to VRAM
draw_string(column*dx[size],row*dy[size],str(obj),grp_color(color),sz[size])
if show: #data transfer to screen
show_screen()
def orbit(x, y, r, rr, cp=0, color=7, start=0, stop=1, show=1):
"""
Draw orbit around (x,y) with radius r
version 1.1
Parameters:
----------
x,y:int
center coordinate for large circle
r:float
radius for large circle
rr:float
radius for small circle
step:
default:1
cp:0 or 1 (int/bool)
0: select rgbcmyk color for small circle
1: select rainbow color for small circle
default:0
color:
compatible with grp_color() for small circle
0:rgbcmyk
1:rainbow
start for large circle:
from radian
default:0 0radian
stop for large circle:
to radian
default:1
show:0 or 1 (int/bool)
0: don't transfer to screen
1: transfer to screen
default:1
Returns:
-------
Non
"""
p = 2*r*2403/383 #pi
a = 2*pi/p
rdx=r
rdy=0
for i in range(p*start,p*stop,5): ###
for rrr in range(1,rr):
circle(rdx,rdy,rrr,cp,"white",0,1,0)
px = x+r*cos(i*a)
if px<0 or px>XMAX:
continue
py = y+r*sin(i*a)
if py<0 or py>YMAX:
continue
rdx=int(px);rdy=int(py)
for rrr in range(1,rr):
circle(rdx,rdy,rrr,cp,color,0,1,0)
if show:
show_screen()
def r_circle(x, y, r, cp=1, color=7, start=0, stop=1, show=1):
"""
Draw circle around (x,y) with radius r /w reversing plot(anticlockwise rotation)
version 1.1
"""
rgb = grp_color(cp, color) #select a color palette
p = 2*r*pi
a = 2*pi/p
for i in range(p*stop,p*start,-1): #reversing
px = x+r*cos(i*a)
if px<0 or px>XMAX:
continue
py = y+r*sin(i*a)
if py<0 or py>YMAX:
continue
set_pixel(int(px), int(py), rgb)
if px < XMAX/2:
if py < YMAX/2:
set_pixel(int(px)+1, int(py)+1, rgb)
else:
set_pixel(int(px)+1, int(py)-1, rgb)
elif py < YMAX/2:
set_pixel(int(px)-1, int(py)+1, rgb)
else:
set_pixel(int(px)-1, int(py)-1, rgb)
if show:
show_screen()
def grp_color(cp=1,color=7):
"""Convert color parameter to rgb in tuple
version 1.0'
parameters:
----------
cp:0 or 1 (int/bool)
0: select rgbcmyk color
1: select rainbow color
default:1
color = 0:
code, name, rgb
0 'white' (255,255,255)
1 'red' (255,0,0)
2 'green' (0,255,0)
3 'blue' (0,0,255)
4 'cyan' (0,255,255)
5 'magenta' (255,0,255)
6 'yellow' (255,255,0)
7 'black' (0,0,0)
default:7 'black' (0,0,0)
color = 1:
code, name, rgb
0 'white' (255,255,255)
1 'violet' (128,0,128)
2 'indigo' (0,0,255)
3 'blue' (0,255,255)
4 'green' (0,128,0)
5 'yellow' (255,255,0)
6 'orange' (255,165,0)
7 'red' (255,0,0)
default:7 'red' (255,0,0)
Returns:
-------
tuple:(r,g,b)
"""
#select a color palette and set rgb from parameter (cp,color)
if cp == 0:
rgb=[(255,255,255),(255,0,0),(0,255,0),(0,0,255),(0,255,255),(255,0,255),(255,255,0),(0,0,0)]
c_name=['white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black']
else:
rgb=[(255,255,255),(128,0,128),(0,0,255),(0,255,255),(0,128,0),(255,255,0),(255,165,0),(255,0,0)]
c_name=['white', 'violet', 'indigo', 'blue', 'green', 'yellow', 'orange', 'red']
if type(color) is int:
if 0<=color<=7:
c_rgb = rgb[color]
else:
c_rgb = (0,0,0)
elif type(color) is str:
if color in c_name:
c_rgb = rgb[c_name.index(color)]
else:
c_rgb = (0,0,0)
elif type(color) is tuple:
c_rgb = color
else:
c_rgb = (0,0,0)
return c_rgb
"""user module
ver 1.0'
Functions:
---------
circle()
line()
locate()
orbit()
r_circle()
grp_color()
#Fontsize = 1point/pixel
X Y
small 8 12
medium 12 16
large 16 24
"""
XMAX = 383
YMAX = 191
from casioplot import *
from math import *
def circle(x, y, r, cp=1, color=7, start=0, stop=1, show=1):
"""
Draw circle around (x,y) with radius r
version 1.0'''
Parameters:
----------
x,y:int
center coordinate
r:float
radius
cp:0 or 1 (int/bool)
0: select rgbcmyk color
1: select rainbow color
default:1
color:
compatible with grp_color()
start:
from radian
default:0←0 radian
stop:
to radian
default:1←2π radian
show:0 or 1 (int/bool)
0: don't transfer to screen
1: transfer to screen
default:1
Returns:
-------
Non
"""
rgb = grp_color(cp, color) #select a color pallet
p = 2*r*2406/383 #pi = 2403/383
a = 2*pi/p
for i in range(p*start,p*stop): #
px = x+r*cos(i*a)
if px<0 or px>XMAX:
continue
py = y+r*sin(i*a)
if py<0 or py>YMAX:
continue
set_pixel(int(px), int(py), rgb)
if show:
show_screen()
def line(x1,y1,x2,y2,cp=0,color=1,show=1):
"""Draw line from (x1,y1) to (x2,y2)
version 1.2'
Parameters:
----------
x1,y1:int
starting coordinate
x2,y2:int
ending coordinate
cp:0 or 1 (int/bool)
0: select rgbcmyk color
1: select rainbow color
default:0
color:
compatible with grp_color()
show:0 or 1 (int/bool)
0: don't transfer to screen
1: transfer to screen
default:1
Returns:
------
Non
"""
rgb=grp_color(cp,color)
dx=x2-x1;dy=y2-y1
if dx==0 and dy==0: #avoid division by 0 error
set_pixel(x1,y1,rgb)
return
if abs(dx)>abs(dy):
if dx: #when dx is not 0
k=int(dx/abs(dx)) #k=1 or -1
slope=dy/dx
for x in range(0,dx,k):
set_pixel(x1+x,y1+int(x*slope),rgb)
else:
if dy: #when dy is not 0
k=int(dy/abs(dy)) #k=1 or -1
slope=dx/dy
for y in range(0,dy,k):
set_pixel(x1+int(y*slope),y1+y,rgb)
if show: #data transfer to screen
show_screen()
def locate(column,row,obj,color=1,size='m',show=1):
"""Locate number or string on graphic screen
version 1.0
Parameters:
----------
column:0-47, row:0-17 (small font)
0-31, 0-11 (medium font)
0-23, 0-7 (large font)
obj:number(int or float)
string(str)
size:'s'
'm'
'l'
default:'m'
color:
compatible with grp_color()
show:0 or 1 (int/bool)
0: don't transfer to screen
1: transfer to screen
default:1
Returns:
-------
None
"""
#set fontsize & pitch
#from 4th argument(size)
dx={'s':8,'m':12,'l':16}
dy={'s':12,'m':16,'l':24}
sz={'s':'small','m':'medium','l':'large'}
#data transfer to VRAM
draw_string(column*dx[size],row*dy[size],str(obj),grp_color(color),sz[size])
if show: #data transfer to screen
show_screen()
def orbit(x, y, r, rr, cp=0, color=7, start=0, stop=1, show=1):
"""
Draw orbit around (x,y) with radius r
version 1.1
Parameters:
----------
x,y:int
center coordinate for large circle
r:float
radius for large circle
rr:float
radius for small circle
step:
default:1
cp:0 or 1 (int/bool)
0: select rgbcmyk color for small circle
1: select rainbow color for small circle
default:0
color:
compatible with grp_color() for small circle
0:rgbcmyk
1:rainbow
start for large circle:
from radian
default:0 0radian
stop for large circle:
to radian
default:1
show:0 or 1 (int/bool)
0: don't transfer to screen
1: transfer to screen
default:1
Returns:
-------
Non
"""
p = 2*r*2403/383 #pi
a = 2*pi/p
rdx=r
rdy=0
for i in range(p*start,p*stop,5): ###
for rrr in range(1,rr):
circle(rdx,rdy,rrr,cp,"white",0,1,0)
px = x+r*cos(i*a)
if px<0 or px>XMAX:
continue
py = y+r*sin(i*a)
if py<0 or py>YMAX:
continue
rdx=int(px);rdy=int(py)
for rrr in range(1,rr):
circle(rdx,rdy,rrr,cp,color,0,1,0)
if show:
show_screen()
def r_circle(x, y, r, cp=1, color=7, start=0, stop=1, show=1):
"""
Draw circle around (x,y) with radius r /w reversing plot(anticlockwise rotation)
version 1.1
"""
rgb = grp_color(cp, color) #select a color palette
p = 2*r*pi
a = 2*pi/p
for i in range(p*stop,p*start,-1): #reversing
px = x+r*cos(i*a)
if px<0 or px>XMAX:
continue
py = y+r*sin(i*a)
if py<0 or py>YMAX:
continue
set_pixel(int(px), int(py), rgb)
if px < XMAX/2:
if py < YMAX/2:
set_pixel(int(px)+1, int(py)+1, rgb)
else:
set_pixel(int(px)+1, int(py)-1, rgb)
elif py < YMAX/2:
set_pixel(int(px)-1, int(py)+1, rgb)
else:
set_pixel(int(px)-1, int(py)-1, rgb)
if show:
show_screen()
def grp_color(cp=1,color=7):
"""Convert color parameter to rgb in tuple
version 1.0'
parameters:
----------
cp:0 or 1 (int/bool)
0: select rgbcmyk color
1: select rainbow color
default:1
color = 0:
code, name, rgb
0 'white' (255,255,255)
1 'red' (255,0,0)
2 'green' (0,255,0)
3 'blue' (0,0,255)
4 'cyan' (0,255,255)
5 'magenta' (255,0,255)
6 'yellow' (255,255,0)
7 'black' (0,0,0)
default:7 'black' (0,0,0)
color = 1:
code, name, rgb
0 'white' (255,255,255)
1 'violet' (128,0,128)
2 'indigo' (0,0,255)
3 'blue' (0,255,255)
4 'green' (0,128,0)
5 'yellow' (255,255,0)
6 'orange' (255,165,0)
7 'red' (255,0,0)
default:7 'red' (255,0,0)
Returns:
-------
tuple:(r,g,b)
"""
#select a color palette and set rgb from parameter (cp,color)
if cp == 0:
rgb=[(255,255,255),(255,0,0),(0,255,0),(0,0,255),(0,255,255),(255,0,255),(255,255,0),(0,0,0)]
c_name=['white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black']
else:
rgb=[(255,255,255),(128,0,128),(0,0,255),(0,255,255),(0,128,0),(255,255,0),(255,165,0),(255,0,0)]
c_name=['white', 'violet', 'indigo', 'blue', 'green', 'yellow', 'orange', 'red']
if type(color) is int:
if 0<=color<=7:
c_rgb = rgb[color]
else:
c_rgb = (0,0,0)
elif type(color) is str:
if color in c_name:
c_rgb = rgb[c_name.index(color)]
else:
c_rgb = (0,0,0)
elif type(color) is tuple:
c_rgb = color
else:
c_rgb = (0,0,0)
return c_rgb
上手く行ったらコメントを下さい。
【参考記事】