ppn_nw.py

Created by tlake

Created on August 07, 2024

2.36 KB


# compatibility with NumWorks

from kandinsky import get_pixel, set_pixel, fill_rect, draw_string

try:
  from ppn_all import *

  ppn_w, ppn_h = 320, 222

  # for Casio fx-CG / USB Power Graphic 3 scripts
  def clear_screen(): fill_rect(0, 0, ppn_w, ppn_h, (255, 255, 255))
  def draw_string(x, y, s, c=None, t=None): draw_string(x, y, s)
  show_screen = lambda: None # Ndless

  # for TI-83P/84+ CE scripts
  ppn_conf_ce = [(0, 0, 0), 1, (1, 1), 30]
  def getPixel(x, y): return getPixel(x, y - ppn_conf_ce[3])
  def setPixel(x, y, c): setPixel(x, y - ppn_conf_ce[3], 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] = 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): set_pixel(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): set_pixel(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): fill_rect(x, y - ppn_conf_ce[3], w, h, ppn_col)
  def drawString(s, x, y): draw_string(x, y - ppn_conf_ce[3], s)
  cls = clear_screen

  # for TI-Nspire Ndless scripts
  def getPx(x, y): return col_lst2int(get_pixel(x, y))
  def setPx(x, y, c): set_pixel(x, y, col_int2lst(c))
  def fill(c): fill_rect(0, 0, ppn_w, ppn_h, col_int2lst(c))

except: myInternalException('NumWorks')

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.