from pc7_keys import * fnop = lambda : None PC_spx, PC_gpx, PC_show, PC_pause, PC_clr, PC_init, PC_end, PC_clrevnts = fnop, fnop, fnop, fnop, fnop, fnop, fnop, fnop dline, PC_drect, PC_frect, PC_dell, PC_fell, PC_dcirc, PC_fcirc, PC_dstr = fnop, fnop, fnop, fnop, fnop, fnop, fnop, fnop PC_wstr, PC_wkey, PC_gkey, PC_tkey, PC_tesc, PC_tanykey, PC_wnokey = fnop, fnop, fnop, fnop, fnop, fnop, fnop PC_wanykey, PC_click, PC_wnoclick = fnop, fnop, fnop PC_hcol, PC_hgkey = 1, 0 PC_sw, PC_sh, PC_fw, PC_fh, screen_y0, PC_fwn, PC_fwm, need_init, need_end, PC_dirt = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 def col3_2_rgb(c, bits, bgr): return c[2*bgr]//2**(8-bits[0]) + c[1]//2**(8-bits[1])*2**bits[0] + c[2*(not(bgr))]//2**(8-bits[2])*2**(bits[0]+bits[1]) d_key = {} def PC_nkeys(): return len(d_key) color_bits = (5, 6, 5) try: import sys try: s = sys.platform ############ # HP Prime # ############ if s == "HP Prime": import hpprime PC_sw, PC_sh, PC_fh = 320, 240, 15 color_bits = (8, 8, 8) need_init, need_end, PC_hgkey, PC_dirt = 1, 1, 1, 1 hpprime.dimgrob(1, PC_sw, PC_sh, 0) def PC_spx(x, y, c): hpprime.pixon(1, x, y, col3_2_rgb(c, color_bits, 1)) def PC_show(): hpprime.strblit(0, 0, 0, PC_sw, PC_sh, 1) def dline(x1, y1, x2, y2, c): hpprime.line(1, x1, y1, x2, y2, col3_2_rgb(c, color_bits, 1)) def PC_drect(x, y, w, h, c): hpprime.rect(1, x, y, w, h, col3_2_rgb(c, color_bits, 1)) def PC_frect(x, y, w, h, c): hpprime.fillrect(1, x, y, w, h, col3_2_rgb(c, color_bits, 1), col3_2_rgb(c, color_bits, 1)) def PC_wstr(s): return hpprime.eval('TEXTSIZE("'+s+'")')[0] def PC_dstr(s, x, y, cf, cb=None): if cb: PC_frect(x, y, PC_wstr(s), PC_fh, cb) hpprime.textout(1, x, y, s, col3_2_rgb(cf, color_bits, 1)) d_key = { K_LEFT:7, K_UP:2, K_DOWN:12, K_RIGHT:8, K_ENTER:30, K_ENTER2:30, K_ESC:4, K_DEL:19, K_APPS:0, K_VARS:14, K_TBOX:15, K_MENU:13, K_0:47, K_1:42, K_2:43, K_3:44, K_4:37, K_5:38, K_6:39, K_7:32, K_8:33, K_9:34, K_DSEP:48, K_ADD:50, K_SUB:45, K_SUB2:27, K_MUL:40, K_DIV:35, K_DIV2:18, K_SHIFT:41, K_ALPHA:36, K_LEFTP:28, K_RIGHTP:28, K_HELP:3 } def PC_tanykey(): return hpprime.keyboard() def PC_tkey(v): return hpprime.keyboard() & (1 << d_key[v]) def PC_click(): xy = hpprime.mouse()[0] if not len(xy): xy = hpprime.mouse()[1] if not len(xy): return None return xy ################## # TI-83PCE/84+CE # ################## elif s == "TI-Python": import ti_graphic, ti_system screen_y0 = 30 PC_sw, PC_sh, PC_fw, PC_fh = 320, 210, 10, 15 need_init, need_end, PC_dirt = 1, 1, 1 PC_tesc, PC_pause = ti_system.escape, ti_system.disp_wait def PC_gpx(x, y): return ti_graphics.getPixel(x, y + screen_y0) def PC_spx(x, y, c): ti_graphics.setPixel(x, y + screen_y0, c) def dline(x1, y1, x2, y2, c): ti_graphics.setColor(c) ti_graphics.drawLine(x1, y1 + screen_y0, x2, y2 + screen_y0) def PC_drect(x, y, w, h, c): ti_graphics.setColor(c) ti_graphics.drawRect(x, y + screen_y0, w, h) def PC_frect(x, y, w, h, c): ti_graphics.setColor(c) ti_graphics.fillRect(x, y + screen_y0, w, h) def PC_dell(x, y, rx, ry, c): ti_graphics.setColor(c) x0, y0 = x - rx, y - ry for dy in range(1 + (y0 > int(y0))): for dx in range(1 + (x0 > int(x0))): ti_graphics.drawArc(x0 + dx, y0 + dy + screen_y0, 2 * rx, 2 * ry, 0, 3600) def PC_fell(x, y, rx, ry, c): ti_graphics.setColor(c) ti_graphics.fillArc(x - rx, y - ry + screen_y0, 2 * rx, 2 * ry, 0, 3600) def PC_fcirc(x, y, r, c): ti_graphics.setColor(c) ti_graphics.fillCircle(x, y + screen_y0, r) def PC_dstr(s, x, y, cf, cb=None): if cb: PC_frect(x, y, PC_fw * len(s), PC_fh, cb) ti_graphics.setColor(cf) ti_graphics.drawString(s, x, y + screen_y0) d_key = { K_LEFT:2, K_UP:3, K_DOWN:4, K_RIGHT:1, K_ENTER:5, K_ESC:9, K_DEL:10, K_APPS:55, K_VARS:53, K_TBOX:142, K_ON:0, K_0:142, K_1:143, K_2:144, K_3:145, K_4:146, K_5:147, K_6:148, K_7:149, K_8:150, K_9:151, K_DSEP:141, K_ADD:128, K_SUB:129, K_SUB2:140, K_MUL:130, K_DIV:131, K_DIV2:64458, K_F1:73, K_F2:72, K_F3:46, K_F4:90, K_F5:68, K_LEFTP:133, K_RIGHTP:134 } def PC_wkey(): key = ti_system.wait_key() return key in d_key.values() and list(d_key.keys())[list(d_key.values()).index(key)] ################### # TI-Nspire CX II # ################### elif s == "TI-Nspire": PC_sw, PC_sh, PC_fw, PC_fh = 318, 212, 12, 12 PC_fwn, PC_fwm = 7, 9 import ti_st PC_hgkey = 1 d_key = { K_LEFT:'left', K_UP:'up', K_DOWN:'down', K_RIGHT:'right', K_ENTER:'enter', K_ENTER2:'return', K_ESC:'esc', K_DEL:'del', K_APPS:'home', K_VARS:'var', K_TBOX:'cat', K_MENU:'menu', K_ON:'home', K_0:'0', K_1:'1', K_2:'2', K_3:'3', K_4:'4', K_5:'5', K_6:'6', K_7:'7', K_8:'8', K_9:'9', K_DSEP:'.', K_ADD:'+', K_SUB:'-', K_SUB2:'?', K_MUL:'*', K_DIV:'/', K_LEFTP:'(', K_RIGHTP:')', K_HELP:'trig' } def PC_gkey(): key = ti_st.getKey(0) return key in d_key.values() and list(d_key.keys())[list(d_key.values()).index(key)] or None def PC_wkey(): key = ti_st.getKey(1) return key in d_key.values() and list(d_key.keys())[list(d_key.values()).index(key)] def PC_click(): if ti_st.getKey(0) != 'center': return None xy = ti_st.getmouse() if xy[0] < 0: return None return xy # import ti_image # canvas = ti_image.new_image(PC_sw, PC_sh, (255,255,255)) # PC_gpx, PC_spx = canvas.get_pixel, canvas.set_pixel # def PC_show(): canvas.show_image(0,0) import ti_draw ti_draw.use_buffer() ti_draw.set_pen("thin","solid") PC_show = ti_draw.paint_buffer def PC_spx(x, y, c): ti_draw.set_color(tuple(c)) ti_draw.plot_xy(x, y, 7) def dline(x1, y1, x2, y2, c): ti_draw.set_color(tuple(c)) ti_draw.draw_line(x1, y1, x2, y2) def PC_drect(x, y, w, h, c): ti_draw.set_color(tuple(c)) ti_draw.draw_rect(x, y, w, h) def PC_frect(x, y, w, h, c): ti_draw.set_color(tuple(c)) ti_draw.fill_rect(x, y, w, h) def PC_dcirc(x, y, r, c): ti_draw.set_color(tuple(c)) ti_draw.draw_circle(x, y, r) def PC_fcirc(x, y, r, c): ti_draw.set_color(tuple(c)) ti_draw.fill_circle(x, y, r) def PC_dell(x, y, rx, ry, c): ti_draw.set_color(tuple(c)) x0, y0 = x - rx, y - ry for dy in range(1 + (y0 > int(y0))): for dx in range(1 + (x0 > int(x0))): ti_draw.draw_arc(x0 + dx, y0 + dy, 2 * rx, 2 * ry, 0, 360) def PC_fell(x, y, rx, ry, c): ti_draw.set_color(tuple(c)) ti_draw.fill_arc(x - rx, y - ry, 2 * rx, 2 * ry, 0, 360) def PC_dstr(s, x, y, cf, cb=None): if cb: PC_frect(x, y, PC_wstr(s), PC_fh, cb) ti_draw.set_color(tuple(cf)) ti_draw.draw_text(x, y + PC_fh, s) ################## # KhiCAS/Micropy # ################## elif s in ("nspire", "numworks", "prizm"): import graphic PC_gpx, PC_spx = graphic.get_pixel, graphic.set_pixel d_key = { K_LEFT:0, K_UP:1, K_DOWN:2, K_RIGHT:3, K_ENTER:4, K_ENTER2:30201, K_ESC:5, K_DEL:30025, K_APPS:30003, K_VARS:30030, K_TBOX:30100, K_ON:30003, K_0:48, K_1:49, K_2:50, K_3:51, K_4:52, K_5:53, K_6:54, K_7:55, K_8:56, K_9:57, K_DSEP:46, K_ADD:137, K_SUB:153, K_SUB2:135, K_MUL:169, K_DIV:47, K_DIV2:187, K_MENU:30008, K_F1:30009, K_F2:30010, K_F3:30011, K_F4:30012, K_F5:30013, K_F6:30014, K_LEFTP:40, K_RIGHTP:41, K_HELP:129 } PC_sw, PC_sh = 320, 222 if s == "nspire": ############################### # TI-Nspire + Ndless + KhiCAS # ############################### PC_spx(0, 0, 31) PC_hcol = PC_gpx(0, 0)[0] == 0 d_key[K_TBOX] = 31103 d_key[K_SUB2] = 45 PC_fw, PC_fh = 15, 18 PC_fwn, PC_fwm = 7, 11 ########################## # Casio + KhiCAS/Micropy # ########################## elif s == "prizm": PC_spx(0, 0, 31) PC_hcol = PC_gpx(0, 0)[2] != 0 d_key[K_DIV] = 185 d_key[K_ON] = 30015 d_key[K_VARS] = 30016 PC_sw, PC_sh, PC_fw, PC_fh, PC_fwn, PC_fwm = PC_hcol and (384, 192, 15, 18, 12, 14) or (128, 64, 6, 7, 6, 6) ###################### # NumWorks + KhiCAS # ###################### else: PC_fw, PC_fh = 11, 18 ################## # KhiCAS/Micropy # ################## PC_show = graphic.show_screen def dline(x1, y1, x2, y2, c): graphic.draw_line(int(x1), int(y1), int(x2), int(y2), col3_2_rgb(c, color_bits, 1)) def PC_drect(x1, y1, x2, y2, c): graphic.draw_rectangle(int(x1), int(y1), int(x2), int(y2), c) def PC_frect(x1, y1, x2, y2, c): graphic.draw_filled_rectangle(int(x1), int(y1), int(x2), int(y2), c) def PC_dcirc(x, y, r, c): graphic.draw_circle(int(x), int(y), int(r), c) def PC_fcirc(x, y, r, c): graphic.draw_filled_circle(int(x), int(y), int(r), c) def PC_dell(x, y, rx, ry, c): graphic.draw_arc(int(x), int(y), int(rx), int(ry), 0, 360, c) def PC_fell(x, y, rx, ry, c): graphic.draw_filled_arc(int(x), int(y), int(rx), int(ry), 0, 360, c) def PC_dstr(s, x, y, cf, cb=(255,255,255)): if cb: graphic.draw_string(int(x), int(y), s, cf, cb) else: graphic.draw_string(int(x), int(y), s, cf) need_init = 1 try: import nsp PC_pause = nsp.waitKeypress except: pass try: import ion PC_hgkey = 1 def PC_tkey(v): return ion.keydown(d_key[v]) >= 0 def PC_wkey(): key = ion.getkey() return key in d_key.values() and list(d_key.keys())[list(d_key.values()).index(key)] except: import cas def PC_wkey(): key = int(cas.caseval("get_key()")) return key in d_key.values() and list(d_key.keys())[list(d_key.values()).index(key)] except: pass if not PC_sw: try: s = sys.implementation #################### # Casio + PythonEx # #################### if s._machine == "sh7305 with sh-4a": import gint PC_gpx, PC_show = gint.dgetpixel, gint.dupdate def PC_spx(x, y, c): gint.dpixel(int(x), int(y), col3_2_rgb(c, color_bits, 1)) gint.dpixel(0, 0, 31) PC_hcol = PC_gpx(0, 0) == 31 PC_sw, PC_sh, PC_fw, PC_fh = PC_hcol and (396, 224, 9, 11) or (128, 64, 6, 5) PC_fwn = PC_hcol and 8 or 4 PC_fwm = PC_hcol and 8 or 3.5 need_init, PC_dirt = 1, 1 def PC_frect(x, y, w, h, c): gint.drect(int(x), int(y), int(x + w - 1), int(y + h - 1), col3_2_rgb(c, color_bits, 1)) def dline(x1, y1, x2, y2, c): gint.dline(int(x1), int(y1), int(x2), int(y2), col3_2_rgb(c, color_bits, 1)) def PC_dstr(s, x, y, cf, cb=None): if cb: PC_frect(x, y, PC_wstr(s), PC_fh, cb) gint.dtext(int(x), int(y), col3_2_rgb(cf, color_bits, 1), s) d_key = { K_LEFT:133, K_UP:134, K_DOWN:117, K_RIGHT:118, K_ENTER:21, K_ESC:116, K_DEL:0x44, K_APPS:132, K_VARS:131, K_TBOX:49, K_MENU:130, K_ON:7, K_0:16, K_1:33, K_2:34, K_3:35, K_4:49, K_5:50, K_6:51, K_7:65, K_8:66, K_9:67, K_DSEP:18, K_SHIFT:129, K_ALPHA:113, K_F1:145, K_F2:146, K_F3:147, K_F4:148, K_F5:149, K_F6:150, K_LEFTP:83, K_RIGHTP:84 } def PC_wkey(): key = gint.getkey().key return key in d_key.values() and list(d_key.keys())[list(d_key.values()).index(key)] except: pass if not PC_sw: try: ######################### # TI-83PCE/84+CE online # ######################### if "Copyright 2009-2010 Scott Graham" in sys.copyright: import ti_draw, ti_system screen_y0 = 30 PC_sw, PC_sh, PC_fw, PC_fh = 320, 210, 10, 15 need_init, need_end, PC_dirt = 1, 1, 1 PC_tesc, PC_pause = ti_system.escape, ti_system.disp_wait def PC_show(): ti_draw.show_draw(1) ti_draw.set_pen("thin","solid") def PC_spx(x, y, c): ti_draw.set_color(*c) ti_draw.plot_xy(x, y, 7) def dline(x1, y1, x2, y2, c): ti_draw.set_color(*c) ti_draw.draw_line(x1, y1, x2, y2) # def PC_drect(x, y, w, h, c): # ti_draw.set_color(*c) # ti_draw.draw_rect(x, y, w, h) # bad display on maclasseti.fr def PC_frect(x, y, w, h, c): ti_draw.set_color(*c) ti_draw.fill_rect(x, y, w, h) def PC_dcirc(x, y, r, c): ti_draw.set_color(*c) ti_draw.draw_circle(x, y, r) def PC_fcirc(x, y, r, c): ti_draw.set_color(*c) ti_draw.fill_circle(x, y, r) def PC_dstr(s, x, y, cf, cb=None): if cb: PC_frect(x, y, PC_wstr(s), PC_fh, cb) ti_draw.set_color(*cf) ti_draw.draw_text(x, y + PC_fh, s) d_key = { K_ENTER:5, K_ESC:9 } def PC_wkey(): key = ti_system.wait_key() return key in d_key.values() and list(d_key.keys())[list(d_key.values()).index(key)] except: pass except: pass if not PC_sw: try: ######### # Casio # ######### import casioplot PC_gpx, PC_spx = casioplot.get_pixel, casioplot.set_pixel ### Casio-CG or Casio-fx PC_spx(0, 0, (0, 0, 255)) col = PC_gpx(0, 0) PC_hcol = col[0] != col[2] PC_sw, PC_sh, PC_fw, PC_fh = PC_hcol and (384, 192, 10, 10) or (128, 64, 6, 5) PC_show, PC_clr = casioplot.show_screen, casioplot.clear_screen PC_hkey = 0 PC_fwn = PC_hcol and 8 or 4 PC_fwm = PC_hcol and 7.5 or 3.5 def PC_dstr(s, x, y, cf, cb=None): if cb: PC_frect(x, y, PC_wstr(s), PC_fh, cb) casioplot.draw_string(int(x), int(y), s, cf, "small") def PC_pause(): try: while(1): pass except KeyboardInterrupt: pass except: try: ############ # NumWorks # ############ import kandinsky, ion PC_gpx, PC_spx = kandinsky.get_pixel, kandinsky.set_pixel PC_hgkey = 1 PC_spx(320, 0, (255,0,0)) #### Omega/Casio-CG or NumWorks PC_sw, PC_sh = PC_gpx(320, 0) == (0,0,0) and (320, 222) or (396, 206) PC_fw, PC_fh = 11, 18 PC_fwn, PC_fwm = PC_fw, PC_fw PC_gpx, PC_spx = kandinsky.set_pixel, kandinsky.set_pixel def PC_frect(x, y, w, h, c): kandinsky.fill_rect(int(x), int(y), int(w), int(h), c) def PC_dstr(s, x, y, cf, cb=(255,255,255)): if cb: kandinsky.draw_string(s, x, y, cf, cb) else: kandinsky.draw_string(s, x, y, cf) d_key = { K_LEFT:0, K_UP:1, K_RIGHT:3, K_DOWN:2, K_ENTER:52, K_ENTER2:4, K_ESC:5, K_DEL:17, K_VARS:15, K_TBOX:16, K_0:48, K_1:42, K_2:43, K_3:44, K_4:36, K_5:37, K_6:38, K_7:30, K_8:31, K_9:32, K_DSEP:49, K_ADD:45, K_SUB:46, K_MUL:39, K_DIV:40, K_SHIFT:12, K_ALPHA:13, K_LEFTP:33, K_RIGHTP:34 } def PC_tkey(v): return ion.keydown(d_key[v]) except: try: #################################### # TI-Nspire + Ndless + Micropython # #################################### import nsp PC_sw, PC_sh, PC_dirt = 320, 240, 1 canvas = nsp.Texture(PC_sw, PC_sh, 0) PC_gpx = canvas.getPx def PC_spx(x, y, c): if x>=0 and x<=PC_sw-1 and y>=0 and y <=PC_sh-1: canvas.setPx(x, y, col3_2_rgb(c, color_bits, 1)) PC_show, PC_pause = canvas.display, nsp.waitKeypress need_init, need_end = 1, 1 except: try: ########################## # Computer + Python+SDL2 # ########################## import pc7_sdl2 as pc_sdl2 pc_sdl2._PC_init(640, 480, 2) PC_sw, PC_sh, PC_spx, PC_clr = pc_sdl2.WIDTH, pc_sdl2.HEIGHT, pc_sdl2.PC_spx, pc_sdl2.PC_clr PC_show, PC_pause, PC_wkey, PC_gkey = pc_sdl2.PC_show, pc_sdl2.PC_pause, pc_sdl2.PC_wkey, pc_sdl2.PC_gkey PC_tkey, PC_clrevnts, PC_tesc, PC_wnokey = pc_sdl2.PC_tkey, pc_sdl2.PC_clrevnts, pc_sdl2.PC_tesc, pc_sdl2.PC_wnokey d_key = pc_sdl2.d_key PC_sshot, PC_click = pc_sdl2.PC_sshot, pc_sdl2.PC_click #PC_frect = pc_sdl2.poly_fill_rect # bug need_init, need_end, PC_hgkey = 1, 1, 1 except Exception as e: print(e) pass if PC_dstr == fnop: from pc7_font import poly_font PC_fw, PC_fh = 11, 10 PC_fwn, PC_fwm = 9, 9 def PC_dstr(s, x, y, cf, cb=None): for c in s: c = ord(c) >= 33 and ord(c) <= 127 and ord(c) - 32 or 0 if cb: PC_frect(x, y, PC_fw, PC_fh, cb) for v in (0,) + poly_font[c] + (0,): ty = y while v: if v & 1: PC_spx(x, ty, cf) ty += 1 v //= 2 x += 1 if not PC_fwn: PC_fwn = PC_fw if not PC_fwm: PC_fwm = PC_fw if PC_wstr == fnop: def PC_wstr(s): try: i = int(s) cw = PC_fwn except: cw = len(s) <= 1 and PC_fw or PC_fwm return cw * len(s) if dline == fnop: def dline(x1, y1, x2, y2, c): m, a1, b1, a2, b2 = 0, int(x1), int(y1), int(x2), int(y2) if (x2 - x1) ** 2 < (y2 - y1) ** 2: m, a1, a2, b1, b2 = 1, b1, b2, a1, a2 if min(a1, a2) != a1: a1, b1, a2, b2 = a2, b2, a1, b1 for a in range(a1, a2 + 1): b = int(b1 + (b2 - b1) * (a - a1) / ((a2 - a1) or 1)) PC_spx((a, b)[m], (b, a)[m], c) if PC_frect == fnop: def PC_frect(x, y, w, h, c): for k in range(h): dline(x, y + k, x + w - 1, y + k, c) if PC_drect == fnop: def PC_drect(x, y, w, h, c): for dy in (0, h - 1): PC_frect(x, y + dy, w, 1, c) for dx in (0, w - 1): PC_frect(x + dx, y, 1, h, c) if PC_dell == fnop: from math import sqrt def PC_dell(x, y, rx, ry, c): for h in range(-int(ry), int(ry)+1): w = sqrt(max(0, rx*rx*(1-h*h/ry/ry))) x1, x2 = int(x - w), int(x + w) yc = int(y + h) PC_spx(x1, yc, c) PC_spx(x2, yc, c) for w in range(-int(rx), int(rx)+1): h = sqrt(max(0, ry*ry*(1-w*w/rx/rx))) y1, y2 = int(y - h), int(y + h) xc = int(x + w) PC_spx(xc, y1, c) PC_spx(xc, y2, c) if PC_fell == fnop: from math import sqrt def PC_fell(x, y, rx, ry, c): for h in range(-int(ry), int(ry)+1): w = sqrt(max(0, rx*rx*(1-h*h/ry/ry))) PC_frect(int(x - w), int(y + h), int(2 * w), 1, c) if PC_dcirc == fnop: def PC_dcirc(x, y, r, c): PC_dell(x, y, r, r, c) if PC_fcirc == fnop: def PC_fcirc(x, y, r, c): PC_fell(x, y, r, r, c) if PC_clr == fnop: def PC_clr(): PC_frect(0, 0, PC_sw, PC_sh, (255, 255, 255)) if need_init: PC_init = PC_clr if need_end: PC_end = PC_pause if PC_tesc == fnop: def PC_tesc(): return PC_tkey(K_ESC) if PC_tkey != fnop and PC_gkey == fnop: def PC_gkey(): for k in d_key: if PC_tkey(k): return k return None if PC_gkey != fnop and PC_tanykey == fnop: def PC_tanykey(): return PC_gkey() != None if PC_tanykey != fnop: if PC_wnokey == fnop: def PC_wnokey(): while PC_tanykey(): pass if PC_wanykey == fnop: def PC_wanykey(): while not PC_tanykey(): pass if PC_gkey != fnop and PC_wkey == fnop: def PC_wkey(): PC_wnokey() PC_wanykey() return PC_gkey() if PC_pause == fnop: def PC_pause(): PC_wnokey() PC_wanykey() if PC_click != fnop and PC_wnoclick == fnop: def PC_wnoclick(): while PC_click(): pass