# compatibility with computer from tkinter import Tk, Canvas, PhotoImage, font try: from ppn_cpns import * except ImportError: raiseException('ppn_cpns.py missing') try: from ppn_all import * ppn_w, ppn_h, ppn_need_show = 384, 240, True _w = Tk() _c = Canvas(_w, width=ppn_w, height=ppn_h) _c.pack() ppn_canvas = PhotoImage(width=ppn_w, height=ppn_h) _c.create_image((ppn_w/2, ppn_h/2), image=ppn_canvas) ppn_canvas.put(' '.join(['{' + ' '.join(['#ffffff' for i in range(ppn_w)]) + '}' for j in range(ppn_h)]), (0, 0)) def col_lst2str(c): return "#%02x%02x%02x" % (max(0, c[0]), max(0, c[1]), max(0, c[2])) # 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 ppn_canvas.get(x, y) def set_pixel(x, y, c): if x >= 0 and x < ppn_w and y >= 0 and y < ppn_h: ppn_canvas.put(col_lst2str(c), (x, y)) def clear_screen(): ppn_canvas.put(' '.join(['{' + ' '.join(['#ffffff' for i in range(ppn_w)]) + '}' for j in range(ppn_h)]), (0, 0)) 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.put(col_lst2str(c), (x0 + ppn_font_cas[t][0][2] + x, y0 + + ppn_font_cas[t][0][3] + y)) v >>= 1 y += 1 x += 1 x0 += ppn_font_cas[t][0][0] or x + ppn_font_cas[t][0][4] show_screen = _c.update # for NumWorks scripts def fill_rect(x, y, w, h, c): ppn_canvas.put(' '.join(['{' + ' '.join([col_lst2str(c) for i in range(w)]) + '}' for j in range(h)]), (x, y)) # for TI-83P/84+CE Python Edition scripts ppn_conf_ce = ['#000000', 1, (1, 1), 30] def getPixel(x, y): return x >= 0 and x < ppn_w and y >= 0 and y < ppn_h and ppn_canvas.get(x, y - ppn_conf_ce[3]) def setPixel(x, y, c): if x >= 0 and x < ppn_w and y >= 0 and y < ppn_h: ppn_canvas.put(col_lst2str(c), (x, y - ppn_conf_ce[3])) 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_lst2str(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 = x2 - x1 and int(y1 + (y2 - y1)*k/(x2 - x1)) or y1 for i in range(-ppn_conf_ce[1], ppn_conf_ce[1] + 1, 1): ppn_canvas.put(ppn_conf_ce[0], (x, y + i - ppn_conf_ce[3])) 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.put(ppn_conf_ce[0], (x + i, y - ppn_conf_ce[3])) 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): ppn_canvas.put(' '.join(['{' + ' '.join([ppn_conf_ce[0] for i in range(w)]) + '}' for j in range(h)]), (x, y - ppn_conf_ce[3])) def drawString(s, x, y): 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.put(ppn_conf_ce[0], (x0 + ppn_font_ce[0][2] + x, y0 + ppn_font_ce[0][3] + y - ppn_conf_ce[3])) v >>= 1 y += 1 x+=1 x0 += ppn_font_ce[0][0] cls = _c.update # for TI-Nspire Ndless scripts def getPx(x, y): return x >= 0 and x < ppn_w and y >= 0 and y < ppn_h and col_lst2int(ppn_canvas.get(x, y)) def setPx(x, y, c): if x >= 0 and x < ppn_w and y >= 0 and y < ppn_h: ppn_canvas.put(x, y, col_int2str(c)) display = _c.update clear_screen() except: myInternalException('Python with tkinter')