#cas from math import pi, asin def fix_angle(a): return a * 2 * asin(1) / pi 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]) def hp_draw_line(x1, y1, x2, y2, c): line_p(x1, y1, x2, y2, col3_2_rgb(c, [8, 8, 8], 1)) def hp_fill_rect(x, y, w, h, c): rect_p(x, y, x + w - 1, y + h - 1, col3_2_rgb(c, [8, 8, 8], 1)) def hp_fill_ellipse(x, y, rx, ry, c): global L1, L2 c, L1 = col3_2_rgb(c, [8, 8, 8], 1), [rx, ry] L2 = [c, c] arc_p(x, y, L1, 0, fix_angle(2*pi), L2) def hp_draw_string(s, x, y, cf, cb): textout_p(s, x, y, 1, col3_2_rgb(cf, [8, 8, 8], 1), len(s) * 9, col3_2_rgb(cb, [8, 8, 8], 1)) def hp_clean_screen(): rect_p(0, 0, 319, 239, 16777215) def hp_pause(): wait() def kc1_draw_line(x1, y1, x2, y2, c): draw_line(float(x1), float(y1), float(x2), float(y2), not(col3_2_rgb(c, [1, 1, 1], 0))) def kc1_fill_rect(x, y, w, h, c): draw_rectangle(float(x), float(y), float(w), float(h), (not (col3_2_rgb(c, [1, 1, 1], 0))) + filled) def kc1_draw_string(s, x, y, cf, cb): draw_string(s, float(x), float(y), col3_2_rgb(cf, [1, 1, 1], 1), col3_2_rgb(cb, [1, 1, 1], 1)) def kc16_draw_line(x1, y1, x2, y2, c): draw_line(float(x1), float(y1), float(x2), float(y2), col3_2_rgb(c, [5, 6, 5], 1)) def kc16_fill_rect(x, y, w, h, c): draw_rectangle(float(x), float(y), float(w), float(h), col3_2_rgb(c, [5, 6, 5], 1) + filled) def kc16_fill_ellipse(x, y, rx, ry, c): draw_arc(float(x), float(y), float(rx), float(ry), 0, 2*pi, col3_2_rgb(c, [5, 6, 5], 1) + filled) def kc16_draw_string(s, x, y, cf, cb): draw_string(s, float(x), float(y), col3_2_rgb(cf, [5, 6, 5], 1), col3_2_rgb(cb, [5, 6, 5], 1)) def kc_pause(): get_key() tcanvas = None def get_infos(): global hp_draw_line, hp_fill_rect, hp_fill_ellipse, hp_draw_string, kc1_draw_line, kc1_fill_rect, kc1_fill_ellipse, kc1_draw_string, kc16_draw_line, kc16_fill_rect, kc16_fill_ellipse, kc16_draw_string, kc_pause, hp_clean_screen, hp_pause, tcanvas fnop = lambda : None screen_w, screen_h, screen_y0, color_bits, font_w, font_h, poly_has_color, poly_set_pixel, poly_show, poly_draw_line, poly_fill_rect, poly_fill_ellipse, poly_draw_string, poly_clean_screen, poly_pause, poly_set_buffered, need_clean, show_need_pause_on_exit, need_line, need_rect, need_ellipse, need_string = 0, 0, 0, [5, 6, 5], 0, 0, 1, fnop, fnop, fnop, fnop, fnop, fnop, fnop, fnop, fnop, 0, 0, 1, 1, 1, 1 try: if chr(256)==chr(0): # KhiCAS Python compat. need_line, need_rect, need_ellipse, need_string = 0, 0, 0, 0 if "HP" in version(): kc1_draw_line, kc1_fill_rect, kc1_fill_ellipse, kc1_draw_string, kc16_draw_line, kc16_fill_rect, kc16_fill_ellipse, kc16_draw_string, kc_pause = None, None, None, None, None, None, None, None, None screen_w, screen_h, font_w, font_h, show_need_pause_on_exit = 320, 240, 9, 11, 1 def poly_set_pixel(x, y, c): set_pixel(x, y, col3_2_rgb(c, [8, 8, 8], 1)) poly_draw_line, poly_fill_rect, poly_fill_ellipse, poly_draw_string, poly_clean_screen, poly_pause = hp_draw_line, hp_fill_rect, hp_fill_ellipse, hp_draw_string, hp_clean_screen, hp_pause else: # Graph 35+E II / NumWorks or Nspire / Graph 90+E hp_draw_line, hp_fill_rect, hp_draw_string, hp_clean_screen, hp_pause = None, None, None, None, None t_mono, t_ns, t_nw, need_clean = not (white), "Numworks" in version(), "Nspire" in version(), 1 screen_w, screen_h, font_w, font_h, poly_pause = 384 - (t_ns or t_nw)*64 - t_mono*256, 192 + (t_ns or t_nw)*30 - t_mono*128, 10 - 4*t_mono + 5*t_ns + t_nw, 10 - 5*t_mono + 8*(t_ns or t_nw), kc_pause if t_mono: kc16_draw_line, kc16_fill_rect, kc16_fill_ellipse, kc16_draw_string = None, None, None, None def poly_set_pixel(x, y, c): set_pixel(x, y, not(col3_2_rgb(c, [1,1,1], 0))) poly_draw_line, poly_fill_rect, poly_fill_ellipse, poly_draw_string = kc1_draw_line, kc1_fill_rect, kc1_fill_ellipse, kc1_draw_string else: kc1_draw_line, kc1_fill_rect, kc1_fill_ellipse, kc1_draw_string = None, None, None, None def poly_set_pixel(x, y, c): set_pixel(x, y, col3_2_rgb(c, [5,6,5], 0)) poly_draw_line, poly_fill_rect, poly_fill_ellipse, poly_draw_string = kc16_draw_line, kc16_fill_rect, kc16_fill_ellipse, kc16_draw_string except: pass if not (screen_w): hp_draw_line, hp_fill_rect, hp_fill_ellipse, hp_draw_string, kc1_draw_line, kc1_fill_rect, kc1_fill_ellipse, kc1_draw_string, kc16_draw_line, kc16_fill_rect, kc16_fill_ellipse, kc16_draw_string, hp_clean_screen, hp_pause = None, None, None, None, None, None, None, None, None, None, None, None, None, None try: import sys try: if sys.platform == "nspire" or sys.platform == "numworks": try: # KhiCAS Micropython import graphic, nsp def poly_draw_line(x1, y1, x2, y2, c): graphic.draw_line(int(x1), int(y1), int(x2), int(y2), col3_2_rgb(c, color_bits, 1)) def poly_fill_rect(x1, y1, x2, y2, c): graphic.draw_filled_rectangle(int(x1), int(y1), int(x2), int(y2), c) def poly_fill_ellipse(x, y, rx, ry, c): graphic.draw_filled_arc(int(x), int(y), int(rx), int(ry), 0, 360, c) def poly_draw_string(s, x, y, cf, cb): graphic.draw_string(x, y, s, (list(cf) == [255, 255, 255]) and cb or cf, "small") screen_w, screen_h, font_w, font_h, poly_set_pixel, poly_show, poly_pause, need_clean, need_line, need_rect, need_ellipse, need_string = 320, 222, 12, 14, graphic.set_pixel, graphic.show_screen, nsp.waitKeypress, 1, 0, 0, 0, 0 except: # Nspire MicroPython import nsp screen_w, screen_h, need_clean, show_need_pause_on_exit = 320, 240, 1, 1 tcanvas = nsp.Texture(screen_w, screen_h, 0) def poly_set_pixel(x, y, c): if x>=0 and x<=screen_w-1 and y>=0 and y <=screen_h-1: tcanvas.setPx(x, y, col3_2_rgb(c, color_bits, 1)) poly_show, poly_pause = tcanvas.display, nsp.waitKeypress elif sys.platform == "TI-Nspire": # CX II import ti_draw, ti_system screen_w, screen_h, font_w, font_h, poly_show, poly_set_buffered, need_line, need_rect, need_ellipse, need_string = 318, 212, 12, 12, ti_draw.paint_buffer, ti_draw.use_buffer, 0, 0, 0, 0 def poly_set_pixel(x, y, c): ti_draw.set_color(tuple(c)) ti_draw.plot_xy(x, y, 7) def poly_draw_line(x1, y1, x2, y2, c): ti_draw.set_color(tuple(c)) ti_draw.draw_line(x1, y1, x2, y2) def poly_fill_rect(x, y, w, h, c): ti_draw.set_color(tuple(c)) ti_draw.fill_rect(x, y, w, h) def poly_fill_ellipse(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 poly_draw_string(s, x, y, cf, cb): poly_fill_rect(x, y, font_w, font_h, cb) ti_draw.set_color(tuple(cf)) ti_draw.draw_text(x, y + font_h, s) def poly_pause(): while ti_system.get_key() != "": pass while ti_system.get_key() == "": pass elif sys.platform.startswith('TI-Python'): import ti_graphics, ti_system screen_y0, need_line, need_rect, need_ellipse, need_string = 30, 0, 0, 0, 0 def poly_draw_line(x1, y1, x2, y2, c): ti_graphics.setColor(c) ti_graphics.drawLine(x1, y1 + screen_y0, x2, y2 + screen_y0) def poly_fill_rect(x, y, w, h, c): ti_graphics.setColor(c) ti_graphics.fillRect(x, y + screen_y0, w, h) def poly_set_pixel(x, y, c): ti_graphics.setPixel(x, y + screen_y0, c) def poly_fill_ellipse(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 poly_draw_string(s, x, y, cf, cb): poly_fill_rect(x, y, font_w, font_h, cb) ti_graphics.setColor(cf) ti_graphics.drawString(x, y + screen_y0, s) screen_w, screen_h, font_w, font_h, poly_pause, need_clean, show_need_pause_on_exit = 320, 210, 10, 15, ti_system.disp_wait, 1, 1 except: # Graph 35+E/USB / 75/85/95 pass except: pass if not (screen_w): # Casio Graph 90/35+E II try: import casioplot casioplot.set_pixel(0, 0, (0, 0, 255)) col = casioplot.get_pixel(0, 0) t = col[0] == col[2] screen_w, screen_h, poly_has_color, font_w, font_h, poly_set_pixel, poly_show, need_string = t and 128 or 384, t and 64 or 192, not (t), t and 6 or 10, t and 5 or 10, casioplot.set_pixel, casioplot.show_screen, 0 def poly_draw_string(s, x, y, cf, cb): poly_fill_rect(x, y, font_w, font_h, cb) casioplot.draw_string(x, y, s, cf, "small") def poly_pause(): try: while(1): pass except KeyboardInterrupt: pass except: pass if not (screen_w): try: # NumWorks import kandinsky, ion screen_w, screen_h, font_w, font_h, poly_set_pixel, poly_draw_string, need_rect, need_string = 320, 222, 11, 18, kandinsky.set_pixel, kandinsky.draw_string, 0, 0 def poly_fill_rect(x, y, w, h, c): kandinsky.fill_rect(int(x), int(y), int(w), int(h), c) def poly_pause(): def key_down(): for k in range(53): if ion.keydown(k): return 1 return 0 while key_down(): pass while not (key_down()): pass except: try: # HP Prime import hpprime screen_w, screen_h, color_bits, need_clean, show_need_pause_on_exit = 320, 240, (8, 8, 8), 1, 1 def poly_set_pixel(x, y, c): hpprime.pixon(0, x, y, col3_2_rgb(c, color_bits, 1)) def poly_pause(): while hpprime.keyboard(): pass while not (hpprime.keyboard()): pass except: pass if screen_w: if need_line: def poly_draw_line(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 k in range(a2 - a1 + 1): a, b = a1 + k, int(b1 + (b2 - b1) * k / ((a2 - a1) or 1)) poly_set_pixel((a, b)[m], (b, a)[m] + screen_y0, c) if need_rect: def poly_fill_rect(x, y, w, h, c): for k in range(h): poly_draw_line(x, y + k, x + w - 1, y + k, c) if need_ellipse: from math import sqrt def poly_fill_ellipse(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 = x - w, x + w yc = y + h poly_draw_line(x1, yc, x2, yc, c) if need_string: from polyfont import poly_font font_w, font_h = 11, 10 def poly_draw_string(s, x, y, cf, cb): for c in s: c = ord(c) >= 33 and ord(c) <= 127 and ord(c) - 32 or 0 poly_fill_rect(x, y, font_w, font_h, cb) for v in (0,) + poly_font[c] + (0,): ty = y while v: if v & 1: poly_set_pixel(x, ty, cf) ty += 1 v //= 2 x += 1 if need_clean: def poly_clean_screen(): poly_fill_rect(0, 0, screen_w, screen_h, [255, 255, 255]) if show_need_pause_on_exit: def poly_show_pause(): poly_show() poly_pause() else: poly_show_pause = poly_show return screen_w, screen_h, poly_has_color, font_w, font_h, poly_set_pixel, poly_draw_line, poly_fill_rect, poly_fill_ellipse, poly_draw_string, poly_clean_screen, poly_show_pause, poly_pause, poly_set_buffered