# compatibility with TI-Nspire Ndless from nsp import Texture try: from ppn_cpns import * except ImportError: raiseException('ppn_cpns.py missing') try: from ppn_all import * ppn_w, ppn_h, ppn_need_show = 320, 240, True ppn_canvas = Texture(ppn_w, ppn_h, None) # for Casio fx-CG / USB Power Graphic 3 + NumWorks scripts def get_pixel(x, y): return x >= 0 and x < ppn_w and y >= 0 and y < ppn_h and col_int2lst(ppn_canvas.getPx(x, y)) def set_pixel(x, y, c): if x >= 0 and x < ppn_w and y >= 0 and y < ppn_h: ppn_canvas.setPx(x, y, col_lst2int(c)) show_screen = ppn_canvas.display def clear_screen(): ppn_canvas.fill(0xffff) def draw_string(x0, y0, s, c=(0, 0, 0), t='medium'): t = t == 'large' and 2 or t == 'medium' and 1 or 0 for ch in s: x = 0 if ord(ch) < 32 or ord(ch) >= 127: ch = ' ' for v in ppn_font_cas[t][1][ord(ch) - 32]: y = 0 while v: if v % 2: ppn_canvas.setPx(x0 + ppn_font_cas[t][0][2] + x, y0 + + ppn_font_cas[t][0][3] + y, col_lst2int(c)) v >>= 1 y += 1 x += 1 x0 += ppn_font_cas[t][0][0] or x + ppn_font_cas[t][0][4] # for NumWorks scripts def fill_rect(x, y, w, h, c): for i in range(h): for j in range(w): ppn_canvas.setPx(x + j, y + i, c) # for TI-83P/84+ CE Python Edition scripts ppn_conf_ce = [0, 1, (1, 1), 30] def getPixel(x, y): return x >= 0 and x < ppn_w and y >= 0 and y < ppn_h and col_int2lst(ppn_canvas.getPx(x, y - ppn_conf_ce[3])) or (0, 0, 0) def setPixel(x, y, c): if x >= 0 and x < ppn_w and y >= 0 and y < ppn_h: ppn_canvas.setPx(x, y - ppn_conf_ce[3], col_lst2int(c)) def setPen(s, t): s, t = int(s), int(t) ppn_conf_ce[1], ppn_conf_ce[2] = (s < 0 or s > 3) and 2 or s, t == 0 and (1, 1) or t == 1 and (2, 4) or t == 3 and (1, 4) or (4, 6) def setColor(c): ppn_conf_ce[0] = col_lst2int(c) def drawLine(x1, y1, x2, y2): x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2) if (x2 - x1) ** 2 >= (y2 - y1) ** 2: if min(x1, x2) != x1: x1, y1, x2, y2 = x2, y2, x1, y1 for k in range(x2 - x1 + 1): x = x1 + k if x % (ppn_conf_ce[2][1] * (ppn_conf_ce[1]+1)) < ppn_conf_ce[2][0] * (ppn_conf_ce[1] + 1): y = int(y1 + (y2 - y1)*k/(x2 - x1)) for i in range(-ppn_conf_ce[1], ppn_conf_ce[1] + 1, 1): ppn_canvas.setPx(x, y + i - ppn_conf_ce[3], ppn_conf_ce[0]) else: if min(y1, y2) != y1: x1, y1, x2, y2 = x2, y2, x1, y1 for k in range(y2 - y1 + 1): y = y1 + k if y % (ppn_conf_ce[2][1] * (ppn_conf_ce[1] + 1)) < ppn_conf_ce[2][0] * (ppn_conf_ce[1] + 1): x = int(x1 + (x2 - x1)*k/(y2 - y1)) for i in range(-ppn_conf_ce[1], ppn_conf_ce[1] + 1, 1): ppn_canvas.setPx(x + i, y - ppn_conf_ce[3], ppn_conf_ce[0]) def drawPolyLine(l): for k in range(len(l) - 1): drawLine(l[k][0], l[k][1], l[k + 1][0], l[k + 1][1]) def drawRect(x, y, w, h): drawLine(x, y, x + w - 1, y) drawLine(x, y + h - 1, x + w - 1, y + h - 1) drawLine(x, y + 1, x, y + h - 2) drawLine(x + w - 1, y + 1, x + w - 1, y + h - 2) def fillRect(x, y, w, h): for i in range(h): for j in range(w): ppn_canvas.setPx(x + j, y + i - ppn_conf_ce[3], ppn_conf_ce[0]) cls = clear_screen def drawString(s, x0, y0): for ch in s: t = [] for v in ppn_font_ce[1][ord(ch) % 256]: t+=[v % (1 << ppn_font_ce[0][1]), v >> ppn_font_ce[0][1]] x = 0 for v in t: y = 0 while v: if v % 2: ppn_canvas.setPx(x0 + ppn_font_ce[0][2] + x, y0 + ppn_font_ce[0][3] + y - ppn_conf_ce[3], ppn_conf_ce[0]) v >>= 1 y += 1 x+=1 x0 += ppn_font_ce[0][0] set_pixel(0, 0, (0, 127, 255)) _col = get_pixel(0, 0) ppn_has_color = _col[0] != _col[1] or _col[1] != _col[2] clear_screen() except: myInternalException('TI-Nspire + Ndless + micropython')