Last active
November 11, 2018 08:34
-
-
Save SubhrajitPrusty/e994ce8f3b643382328c1c779893a721 to your computer and use it in GitHub Desktop.
Make a gradient creation video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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