draw.py

Created by mino-1289

Created on June 29, 2021

1.69 KB

Dessine


from ion import *
from kandinsky import set_pixel, color, get_pixel, fill_circle
from time import sleep


def setpixel(x, y, c) -> None:
    if c != get_pixel(x, y):
        set_pixel(x, y, c)


def reset():
    for x in range(320):
        for y in range(222):
            setpixel(x, y, color(255, 255, 255))


def draw(x, y, c, r):
    if r >= 1:
        setpixel(x, y, c)
    fill_circle(x,y,r,c)
    return None


def paint():
    x, y = 160, 100
    run = True
    rad = 1
    r, g, b = 0, 0, 250
    while run:
        if keydown(KEY_LEFT):
            x -= 1
        if keydown(KEY_UP):
            y -= 1
        if keydown(KEY_RIGHT):
            x += 1
        if keydown(KEY_DOWN):
            y += 1

        if keydown(KEY_PLUS) and rad < 10:
            rad += 2
        if keydown(KEY_MINUS) and rad > 0:
            rad -= 2

        if keydown(KEY_SINE) and r >= 15:
            r -= 10
        if keydown(KEY_COSINE) and g >= 15:
            g -= 10
        if keydown(KEY_TANGENT) and b >= 15:
            b -= 10
        if keydown(KEY_EXP) and r <= 245:
            r += 10
        if keydown(KEY_LN) and g <= 245:
            g += 10
        if keydown(KEY_LOG) and b <= 245:
            b += 10

        if keydown(KEY_SHIFT):
            if keydown(KEY_BACKSPACE):
                reset()
            if keydown(KEY_LEFT):
                x = 0
            if keydown(KEY_UP):
                y = 222
            if keydown(KEY_RIGHT):
                x = 320
            if keydown(KEY_DOWN):
                y = 0

        c = color(r, g, b)
        draw(x, y, c, rad)
        sleep(0.1)
        if keydown(KEY_BACK):
            run = False
    if keydown(KEY_BACK):
        exit()


paint()

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.