polysol.py

Created by parisseb

Created on November 10, 2020

3.8 KB

Utilitaire de compatibilite Python, par X. Andreani.


#cas

def get_infos():
  fnop = lambda : None
  screen_w, screen_h, color_bits, font_w, font_h, poly_has_color, poly_set_pixel, poly_show, poly_fill_rect, poly_fill_circle, poly_draw_ellipse, poly_sleep, poly_get_key, poly_draw_string, poly_pause, poly_set_buffer, poly_sleep, show_need_pause_on_exit = 320, 222, [5, 6, 5], 0, 18, 1, fnop, fnop, fnop, fnop, fnop, fnop, fnop, fnop, fnop, fnop, fnop, 0
  try:
    import graphic, nsp, cas, time
    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 poly_fill_rect(x1, y1, x2, y2, c):
      graphic.draw_filled_rectangle(int(x1), int(y1), int(x2), int(y2), c)
    def poly_fill_circle(x, y, r, c):
      graphic.draw_filled_circle(int(x), int(y), int(r), c)
    def poly_draw_ellipse(x, y, rx, ry, c):
      graphic.draw_arc(int(x), int(y), int(rx), int(ry), 0, 360, c)
    def poly_draw_string(s, x, y, cf, cb):
      st = 'draw_string("' + s + '", ' + str(float(x)) + ', ' + str(float(y)) + ', ' + str(col3_2_rgb(cf, color_bits, 1)) + ', ' + str(col3_2_rgb(cb, color_bits, 1)) + ')'
      print(s)
      cas.caseval(st)
    def poly_get_key():
      key = int(cas.caseval("get_key()"))
      #    left up   down rightenteresc  (       )
      d = {2:0, 3:1, 4:2, 1:3, 5:4, 9:5, 133:40, 134:41}
      for k in d:
        if key == d[k]:
          return k
      return 0
    def poly_sleep(d):
      s = time.monotonic() + d*1000
      while time.monotonic() < s:
        pass
    font_w, poly_set_pixel, poly_show, poly_pause = 15, graphic.set_pixel, graphic.show_screen, nsp.waitKeypress
  except:
    try: # NumWorks
      import kandinsky, ion, time
      from math import sqrt
      font_w, poly_set_pixel, poly_draw_string, poly_sleep = 11, kandinsky.set_pixel, kandinsky.draw_string, time.sleep
      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], c)
      def poly_fill_rect(x, y, w, h, c):
        kandinsky.fill_rect(int(x), int(y), int(w), int(h), c)
      def poly_draw_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 = int(x - w), int(x + w)
          yc = y + h
          poly_set_pixel(x1, yc, c)
          poly_set_pixel(x2, yc, c)
        for w in range(-int(rx), int(rx)+1):
          h = sqrt(max(0, ry*ry*(1-w*w/rx/rx)))
          y1, y2 = int(y - h), int(y + h)
          xc = x + w
          poly_set_pixel(xc, y1, c)
          poly_set_pixel(xc, y2, c)
      def poly_fill_circle(x, y, r, c):
        for h in range(-int(r), int(r)+1):
          w = sqrt(max(0, r*r*(1-h*h/r/r)))
          x1, x2 = int(x - w), int(x + w)
          yc = y + h
          poly_draw_line(x1, yc, x2, yc, 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
      def poly_draw_string(s, x, y, cf, cb):
        kandinsky.draw_string(s, x, y, cf, cb)
      def poly_get_key():
        # left up down right enter esc ( )
        d = {2:0, 3:1, 4:2, 1:3, 5:52, 9:5, 133:33, 134:34}
        for k in d:
          if ion.keydown(d[k]):
            return k
        return 0
    except:
      pass

  return screen_w, screen_h, font_h, poly_set_pixel, poly_fill_rect, poly_fill_circle, poly_draw_ellipse, poly_draw_string, poly_show, poly_pause, poly_get_key, poly_sleep

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.