示例#1
0
def draw_turtle(x, y, a, c):
    global turtle_buffer

    def inbuffer(x, y):
        inlist = False
        for i in range(1, len(turtle_buffer)):
            if x == turtle_buffer[i][0] and y == turtle_buffer[i][1]:
                inlist = True
        return inlist

    if turtle_visible == True:
        u = cos(a * pi / 180)
        v = sin(a * pi / 180)
        for point in turtle_data:
            xx = x + (point[0] * u - point[1] * v)
            yy = y + (point[1] * u + point[0] * v)
            xpixel = int(round(xx + 192))
            ypixel = int(round(-yy + 96))
            if (0 <= xpixel <= 383 and 0 <= ypixel <= 191):
                if not inbuffer(xpixel, ypixel):
                    turtle_buffer += [[
                        xpixel, ypixel,
                        casioplot.get_pixel(xpixel, ypixel)
                    ]]
                casioplot.set_pixel(xpixel, ypixel, c)
示例#2
0
def grad(x, y, w, h):
    for i in range(w):
        for j in range(h):
            arg1 = 2 * j / (h - 1)
            arg2 = i >= w // 2 and 1 or i / (w // 2 - 1)
            arg3 = i < w // 2 and 1 or (w - 1 - i) / ((w - w // 2) - 1)
            c = hsv2c(arg1, arg2, arg3)
            scr.set_pixel(x + i, y + j, c)
示例#3
0
def erase_turtle():
    global turtle_buffer
    for i in range(1, len(turtle_buffer)):
        xpixel = turtle_buffer[i][0]
        ypixel = turtle_buffer[i][1]
        if turtle_buffer[i][2] != None:
            lastcolor = turtle_buffer[i][2]
        else:
            lastcolor = (255, 255, 255)
        casioplot.set_pixel(xpixel, ypixel, lastcolor)
    turtle_buffer = [[]]
示例#4
0
def pen_brush(x, y, turtle_color):
    global frame_count
    erase_turtle()
    xpixel = int(round(x + 192))
    ypixel = int(round(-y + 96))
    if writing == True and (0 <= xpixel <= 383 and 0 <= ypixel <= 191):
        colorpixel = (int(turtle_color[0] * 255), int(turtle_color[1] * 255),
                      int(turtle_color[2] * 255))
        casioplot.set_pixel(xpixel, ypixel, colorpixel)
        frame_count += 1
        if turtle_speed != 0:
            if frame_count % (turtle_speed * 4) == 0:
                draw_turtle(x, y, turtle_angle, colorpixel)
                casioplot.show_screen()
        else:
            if frame_count % 500 == 0:
                draw_turtle(x, y, turtle_angle, colorpixel)
                casioplot.show_screen()
示例#5
0
def show():
    global fenetre, limits, points, lines, textes, xmin, ymin, xmax, ymax, win_scaling, axis_display, color_count

    def RGB(c):
        if c == "k" or c == "black":
            return (0, 0, 0)
        elif c == "b" or c == "blue":
            return (0, 0, 255)
        elif c == "g" or c == "green":
            return (0, 255, 0)
        elif c == "r" or c == "red":
            return (255, 0, 0)
        elif c == "c" or c == "cyan":
            return (0, 255, 255)
        elif c == "y" or c == "yellow":
            return (255, 255, 0)
        elif c == "m" or c == "magenta":
            return (255, 0, 255)
        elif c == "w" or c == "white":
            return (255, 255, 255)
        else:
            raise ValueError("invalid color code")

    def printable(x, y):
        global limits
        return (limits[0] <= x <= limits[2] and limits[3] <= y <= limits[1])

    def echelle(a, b):
        k = 0
        e = abs(b - a)
        while e >= 10:
            e /= 10
            k += 1
        while e < 1:
            e *= 10
            k -= 1
        return k

    def pas(a, b):
        pas = 10**echelle(a, b)
        while (abs(b - a)) // pas < 4:
            pas /= 2
        return pas

    def converttopixel(x, y):
        global fenetre, limits
        ax = (limits[2] - limits[0]) / (fenetre[1] - fenetre[0])
        bx = limits[0] - ax * fenetre[0]
        xpixel = round(ax * x + bx)
        ay = (limits[3] - limits[1]) / (fenetre[3] - fenetre[2])
        by = limits[1] - ay * fenetre[2]
        ypixel = round(ay * y + by)
        return xpixel, ypixel

    color_count = 0
    plt.clear_screen()
    if win_scaling == 'auto':
        if xmin == xmax:
            if xmin == 0:
                fenetre[0:2] = [-0.05, 0.05]
            else:
                fenetre[0:2] = [0.95 * xmin, 1.05 * xmin]
        else:
            fenetre[0:2] = [
                xmin - 0.05 * (xmax - xmin), xmax + 0.05 * (xmax - xmin)
            ]
        if ymin == ymax:
            if ymin == 0:
                fenetre[2:4] = [-0.05, 0.05]
            else:
                fenetre[2:4] = [0.95 * ymin, 1.05 * ymin]
        else:
            fenetre[2:4] = [
                ymin - 0.05 * (ymax - ymin), ymax + 0.05 * (ymax - ymin)
            ]
    if axis_display == 'on' or axis_display == 'boxplot':
        for i in range(limits[0], limits[2] + 1):
            plt.set_pixel(i, limits[1], RGB("k"))
        for j in range(limits[3], limits[1] + 1):
            plt.set_pixel(limits[0], j, RGB("k"))
        fenetreb = sorted([fenetre[0], fenetre[1]]) + sorted(
            [fenetre[2], fenetre[3]])
        gx = round(fenetreb[0], -echelle(fenetreb[0], fenetreb[1]))
        gy = round(fenetreb[2], -echelle(fenetreb[2], fenetreb[3]))
        if axis_display == 'boxplot':
            for i in range(nbre_boite):
                y = fenetre[2]
                xpixel, ypixel = converttopixel(i + 1, y)
                plt.set_pixel(xpixel, ypixel + 1, RGB("k"))
                plt.set_pixel(xpixel, ypixel + 2, RGB("k"))
                plt.set_pixel(xpixel, ypixel + 3, RGB("k"))
                plt.draw_string(xpixel, ypixel + 13, str(round(i + 1, 8)),
                                [0, 0, 0], "small")
        else:
            for i in range(-11, 11):
                x = gx + i * pas(fenetreb[0], fenetreb[1])
                y = fenetre[2]
                xpixel, ypixel = converttopixel(x, y)
                if printable(xpixel, ypixel):
                    plt.set_pixel(xpixel, ypixel + 1, RGB("k"))
                    plt.set_pixel(xpixel, ypixel + 2, RGB("k"))
                    plt.set_pixel(xpixel, ypixel + 3, RGB("k"))
                    plt.draw_string(xpixel, ypixel + 13, str(round(x, 8)),
                                    [0, 0, 0], "small")
        for j in range(-11, 11):
            x = fenetre[0]
            y = gy + j * pas(fenetreb[2], fenetreb[3])
            xpixel, ypixel = converttopixel(x, y)
            if printable(xpixel, ypixel):
                plt.set_pixel(xpixel - 1, ypixel, RGB("k"))
                plt.set_pixel(xpixel - 2, ypixel, RGB("k"))
                plt.set_pixel(xpixel - 3, ypixel, RGB("k"))
                plt.draw_string(xpixel - 40, ypixel, str(round(y, 8)),
                                [0, 0, 0], "small")
    if points != [[]]:
        if points[0] == []:
            del points[0]
        for i in range(len(points)):
            xpixel, ypixel = converttopixel(points[i][0], points[i][1])
            if printable(xpixel, ypixel) and points[i][2] != None:
                for j in range(-2, 3):
                    plt.set_pixel(xpixel + j, ypixel, RGB(points[i][2]))
                    plt.set_pixel(xpixel, ypixel + j, RGB(points[i][2]))
    if textes != [[]]:
        if textes[0] == []:
            del textes[0]
        for i in range(len(textes)):
            xpixel, ypixel = converttopixel(textes[i][0], textes[i][1])
            if printable(xpixel, ypixel):
                plt.draw_string(xpixel, ypixel, textes[i][2], [0, 0, 0],
                                "small")
    if lines != [[]]:
        if lines[0] == []:
            del lines[0]
        for i in range(len(lines)):
            xpixel1, ypixel1 = converttopixel(lines[i][0], lines[i][1])
            xpixel2, ypixel2 = converttopixel(lines[i][2], lines[i][3])
            deltax = abs(xpixel2 - xpixel1)
            deltay = abs(ypixel2 - ypixel1)
            if deltax == deltay == 0:
                if printable(xpixel1, ypixel1):
                    plt.set_pixel(xpixel1, ypixel1, RGB(lines[i][4]))
            if deltax <= 1 and deltay <= 1:
                if printable(xpixel1, ypixel1):
                    plt.set_pixel(xpixel1, ypixel1, RGB(lines[i][4]))
                    plt.set_pixel(xpixel2, ypixel2, RGB(lines[i][4]))
            if deltax >= deltay and deltax != 0:
                m = (ypixel2 - ypixel1) / (xpixel2 - xpixel1)
                p = ypixel1 - m * xpixel1
                xpixelmin = max(limits[0], min(xpixel1, xpixel2))
                xpixelmax = min(limits[2], max(xpixel1, xpixel2))
                if xpixelmin <= limits[2] and xpixelmax >= limits[0]:
                    for xpixel in range(xpixelmin, xpixelmax + 1):
                        ypixel = round(m * xpixel + p)
                        if printable(xpixel, ypixel):
                            plt.set_pixel(xpixel, ypixel, RGB(lines[i][4]))
            if deltay > deltax:
                m = (xpixel2 - xpixel1) / (ypixel2 - ypixel1)
                p = xpixel1 - m * ypixel1
                ypixelmin = max(limits[3], min(ypixel1, ypixel2))
                ypixelmax = min(limits[1], max(ypixel1, ypixel2))
                if ypixelmin <= limits[1] and ypixelmax >= limits[3]:
                    for ypixel in range(ypixelmin, ypixelmax + 1):
                        xpixel = round(m * ypixel + p)
                        if printable(xpixel, ypixel):
                            plt.set_pixel(xpixel, ypixel, RGB(lines[i][4]))
    axis([limits[0] - 50, limits[2], limits[1] + 50, limits[3]])
    axis("off")
    plt.show_screen()
    points = [[]]
    lines = [[]]
    textes = [[]]
    xmin, xmax, ymin, ymax = 0, 1, 0, 1
    fenetre = [0, 1, 0, 1]
    axis_display = 'on'
    win_scaling = 'init'
    color_count = 0
示例#6
0
文件: plot1.py 项目: mathwiz/euclid
def myplot(x, y, c=0):
    scr.set_pixel(x, y, c)
示例#7
0
def xy(x, y, c='k'):
  scr.set_pixel(x, 192-y, color(c))
示例#8
0
def plot(x, y, c):
    scr.set_pixel(x, y, c)