#cas 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, y + h, col3_2_rgb(c, [8, 8, 8], 1)) def kc1_draw_line(x1, y1, x2, y2, c): draw_line(int(x1), int(y1), int(x2), int(y2), not col3_2_rgb(c, [1, 1, 1], 0)) def kc16_draw_line(x1, y1, x2, y2, c): draw_line(int(x1), int(y1), int(x2), int(y2), col3_2_rgb(c, [5, 6, 5], 1)) def hp_clean_screen(): rect_p(0, 0, 319, 239, 16777215) def hp_pause(): wait() tcanvas = None def get_infos(): global hp_draw_line, hp_fill_rect, kc1_draw_line, kc16_draw_line, hp_clean_screen, hp_pause, tcanvas fnop = lambda : None screen_w, screen_h, screen_y0, color_bits, poly_set_pixel, poly_show, poly_draw_line, poly_fill_rect, poly_clean_screen, poly_pause, need_clean, need_pause, need_line, need_rect = 0, 0, 0, [5, 6, 5], fnop, fnop, fnop, fnop, fnop, fnop, 0, 0, 1, 1 try: if chr(256)==chr(0): # KhiCAS Python compat. need_line = 0 if "HP" in version(): kc1_draw_line, kc16_draw_line = None, None screen_w, screen_h, need_pause, need_rect = 320, 240, 1, 0 def poly_set_pixel(x, y, c): set_pixel(x, y, col3_2_rgb(c, [8, 8, 8], 1)) poly_draw_line = hp_draw_line poly_fill_rect = hp_fill_rect poly_clean_screen = hp_clean_screen poly_pause = hp_pause else: # Graph 35+E II / NumWorks or Nspire / Graph 90+E hp_draw_line, hp_fill_rect, hp_clean_screen, hp_pause = None, None, None, None t1, t2, need_clean = not white, "Numworks" in version() or "Nspire" in version(), 1 screen_w, screen_h = 384 - t2*64 - t1*256, 192 + t2*30 - t1*128 if t1: kc16_draw_line = None def poly_set_pixel(x, y, c): set_pixel(x, y, not col3_2_rgb(c, [1,1,1], 0)) poly_draw_line = kc1_draw_line else: kc1_draw_line = None def poly_set_pixel(x, y, c): set_pixel(x, y, col3_2_rgb(c, [5,6,5], 0)) poly_draw_line = kc16_draw_line except: pass if not screen_w: hp_draw_line, hp_fill_rect, kc1_draw_line, kc16_draw_line, hp_clean_screen, hp_pause = None, None, None, None, None, None try: import sys try: if sys.platform == "nspire" or sys.platform == "numworks": try: # KhiCAS Micropython import graphic 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) screen_w, screen_h, poly_set_pixel, need_clean, need_line, need_rect = 320, 222, graphic.set_pixel, 1, 0, 0 except: # Nspire MicroPython import nsp screen_w, screen_h, need_clean, need_pause = 320, 240, 1, 1 tcanvas = nsp.Texture(screen_w, screen_h, 0) def poly_set_pixel(x, y, c): 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_image screen_w, screen_h = 318, 212 tcanvas = ti_image.new_image(screen_w, screen_h, (255, 255, 255)) def poly_set_pixel(x, y, c): tcanvas.set_pixel(x, y, tuple(c)) poly_show = tcanvas.show_image elif sys.platform.startswith('TI-Python'): import ti_graphics import ti_system screen_y0, need_line, need_rect = 30, 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) screen_w, screen_h, poly_pause, need_clean, need_pause = 320, 210, 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_set_pixel, poly_show = t and 128 or 384, t and 64 or 192, casioplot.set_pixel, casioplot.show_screen except: pass if not screen_w: try: # NumWorks import kandinsky screen_w, screen_h, poly_set_pixel, need_rect = 320, 222, kandinsky.set_pixel, 0 def poly_fill_rect(x, y, w, h, c): kandinsky.fill_rect(int(x), int(y), int(w), int(h), c) except: try: # HP Prime import hpprime screen_w, screen_h, color_bits, need_clean, need_pause = 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_clean: def poly_clean_screen(): poly_fill_rect(0, 0, screen_w, screen_h, [255, 255, 255]) if need_pause: def poly_show_pause(): poly_show() poly_pause() else: poly_show_pause = poly_show return screen_w, screen_h, poly_set_pixel, poly_draw_line, poly_fill_rect, poly_clean_screen, poly_show_pause