add mixbox for python

This commit is contained in:
Ondrej Jamriska
2022-09-21 05:05:52 +02:00
parent 4bfc462204
commit 334932d8fe
7 changed files with 384 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
import bpy
import mixbox
rgb1 = (0.0, 0.015, 0.235) # blue
rgb2 = (0.973, 0.651, 0.0) # yellow
n = 5
for i in range(0, n):
bpy.ops.mesh.primitive_cube_add(location = ((i - n/2 + 0.5) * 3, 0, 0))
mat = bpy.data.materials.new("material")
mat.diffuse_color = mixbox.lerp_linear_float(rgb1, rgb2, i / (n - 1))
bpy.context.object.active_material = mat

9
python/examples/hello.py Normal file
View File

@@ -0,0 +1,9 @@
import mixbox
rgb1 = (0, 33, 133) # blue
rgb2 = (252, 211, 0) # yellow
t = 0.5 # mixing ratio
rgb_mix = mixbox.lerp(rgb1, rgb2, t)
print(rgb_mix)

17
python/examples/npcv.py Normal file
View File

@@ -0,0 +1,17 @@
import cv2
import numpy as np
import mixbox
height = 256
width = 256
img = np.zeros((height, width, 3), np.uint8)
rgb1 = (0, 33, 133) # blue
rgb2 = (252, 211, 0) # yellow
for x in range(0, 256):
for y in range(0, 256):
img[x, y] = mixbox.lerp(rgb1, rgb2, x / 255.0)
cv2.imshow("image", cv2.cvtColor(img, cv2.COLOR_RGB2BGR))
cv2.waitKey(0)

29
python/examples/opengl.py Normal file
View File

@@ -0,0 +1,29 @@
import pygame as pg
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
import mixbox
pg.init()
pg.display.set_mode((640, 480), DOUBLEBUF | OPENGL)
while True:
rgb1 = (0.0, 0.129, 0.522) # blue
rgb2 = (0.988, 0.827, 0.0) # yellow
n = 640
glBegin(GL_LINES)
for i in range(0, n+1):
glColor(mixbox.lerp_float(rgb1, rgb2, i / n))
glVertex((i / n)*2 - 1, -1)
glVertex((i / n)*2 - 1, +1)
glEnd()
pg.display.flip()
for event in pg.event.get():
if event.type == pg.QUIT:
pg.quit()
quit()

16
python/examples/pillow.py Normal file
View File

@@ -0,0 +1,16 @@
from PIL import Image
import mixbox
rgb1 = (0, 33, 133) # blue
rgb2 = (252, 211, 0) # yellow
img = Image.new('RGB', (256, 256))
pixels = img.load()
width,height = img.size
for x in range(width):
for y in range(height):
pixels[x, y] = mixbox.lerp(rgb1, rgb2, x / 256.0)
img.show()