Skip to content
Open

#7 #17

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 55 additions & 10 deletions ASCII.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
import math
import os
import sys
#library keyboard please import
import keyboard
import numpy as np

#library for ss
import pyautogui
#library for image
#from PIL import Image,text_to_image
#from Screenshot import Screenshot_clipping
f = open("color.txt",'w')
z = open("char.txt","w")

os.system("clear|cls")

Expand All @@ -19,7 +28,7 @@ def map_color_value(old_value):

for i in range(256):
pixel_hash.append(pixel_map[map_color_value(i)])

#putting capture under a function because nice to work with
def s():
while True :
#print('ok')
Expand All @@ -34,23 +43,59 @@ def s():
for i,row in enumerate(image_gray):
for j,column in enumerate(row):
r,g,b = image[i][j]
#print(r,g,b)
#print(pixel_map[map_color_value(column)], end="")
print(f"\x1b[38;2;{r};{g};{b}m{pixel_hash[column]}\x1b[0m", end='')
print(f"\x1b[48;2;{r};{g};{b}m{pixel_hash[column]}\x1b[0m", end='')
f.writelines(f"[{r},{g},{b}],\n")
z.writelines(f"[{pixel_hash[column]}]\n")

print()


sys.stdout.write(f"\033[{0};{0}H")
sys.stdout.flush()
#releasing capture when keyboard click event for b
if keyboard.read_key()=="b":
cap.release()
#cap.pause()
cv.destroyAllWindows()
#cv.destroyAllWindows()
#calling the capture function when keyboard click event for button a happens
def ss():

image = pyautogui.screenshot()
image = cv.cvtColor(np.array(image), cv.COLOR_BGR2RGB)
cv.imwrite("image1.png", image)


def v():
image = cv.imread('image1.png',cv.COLOR_BGR2RGB)
cv.imshow('pic',image)
cv.waitKey(0)
f = open("color.txt",'r')
z = open("char.txt",'r')
#data=f.readlines()
#dat=z.readlines()
for i in f:
cr = i
for j in z:
ch =j
print(f"\x1b[48;2;{i[0]};{i[1]};{i[2]}m{j}\x1b[0m", end='')




while True:
if keyboard.read_key() == 'a':
s()
elif keyboard.read_key()=='s':
ss()
elif keyboard.read_key()=='v':
v()







if keyboard.read_key() == 'a':
s()

'''else:
#while True:
cap.release()
#cap.pause()
cv.destroyAllWindows()'''
Loading