gradient

import math
import random
from PIL import Image

RES_X=1024
RES_Y=1024

def pixel(x,y):
    if math.floor(x/256)%2 == 0:
        red = x % 256
    else:
        red = 256 - (x%256)

    if math.floor(y/256)%2 == 0:
        blue = y % 256
    else:
        blue = 256 - (y%256)

    green = 0

    if y-100 < x < y + 100 :
        blue -= 50
        red -= 50

    if y-100 < RES_X-x < y + 100 :
        blue += 50
        red += 50

    return (math.floor(red), math.floor(green), math.floor(blue))

def in_image(p):
    x = p[0]
    y = p[1]
    return 0 <= x < RES_X and 0 <= y < RES_Y

def brush(img, position, radius, color):
    x,y = position
    for i in range(x-radius, x+radius+1):
        for j in range(y-radius, y+radius +1):
            dist = math.sqrt((x-i)**2 + (y-j)**2)
            if dist <= radius and in_image((i,j)):
                pix = color(i,j)
                r = pix[0] - int(dist/radius * pix[0])
                g = pix[1] - int(dist/radius * pix[1])
                b = pix[2] - int(dist/radius * pix[2])
                img.putpixel((i,j),(r,g,b))
    return img

img = Image.new("RGB",(RES_X,RES_Y))
img = brush(img, (512,512), 512, pixel)
img.save("result.png")