Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Make a gradient creation video
#! /usr/bin/python3
from wallgen import *
import os
from PIL import Image
import numpy as np
import cv2
import sys
ERASE_LINE = '\x1b[2K'
CURSOR_UP_ONE = '\x1b[1A'
width = 1920
height = 1080
img = Image.new("RGB", (width, height), "#000000")
draw = ImageDraw.Draw(img)
rgb1 = input("Enter color 1 : ")
rgb2 = input("Enter color 2 : ")
vidname = input("Enter name for videofile : ")
print("Starting ... ")
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter(f'{vidname}.avi', fourcc, 120, (width, height))
try:
rgb1 = tuple(bytes.fromhex(rgb1[1:]))
rgb2 = tuple(bytes.fromhex(rgb2[1:]))
except Exception as e:
print("Invalid color. Example #ff00ff")
sys.exit(1)
r,g,b = rgb1
r2,g2,b2 = rgb2
dr, dg, db = (r2-r)/width, (g2-g)/width, (b2-b)/width
for i in range(width+1):
r,g,b = r+dr, g+dg, b+db
draw.line((i,0,i,height), fill=(int(r),int(g),int(b)))
print(CURSOR_UP_ONE + ERASE_LINE + CURSOR_UP_ONE)
print(i)
img_np = np.array(img)
cimg = cv2.cvtColor(img_np, cv2.COLOR_RGB2BGR)
cv2.imshow("Preview", cimg)
cv2.waitKey(1)
out.write(cimg)
out.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment