Last active
September 15, 2021 19:33
-
-
Save CenTdemeern1/e1e4ef5fa16ce3dff69aec13b1f0e3bc to your computer and use it in GitHub Desktop.
Command generator for Robot is You / Robot is Chill, please credit CenTdemeern1 for making the program when posting your creations
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
import numpy,cv2 | |
def rgbtohex(v): | |
return "#"+hex(v[0])[2:].zfill(2)+hex(v[1])[2:].zfill(2)+hex(v[2])[2:].zfill(2) | |
def bgrtohex(v): | |
return "#"+hex(v[2])[2:].zfill(2)+hex(v[1])[2:].zfill(2)+hex(v[0])[2:].zfill(2) | |
def gendisplace(x,y): | |
return "displace"+str(-12+x-(24*x))+"/"+str(-12+y-(24*y)) | |
def gendisplace2(x,y): | |
return "displace"+str(-12+x-(24*floor(x/24)))+"/"+str(-12+y-(24*floor(y/24))) | |
def gendisplace3(x,y): | |
return "displace"+str(-12+x)+"/"+str(-12+y) | |
def genpixel(x,y,color): | |
return ":".join(["pixel",bgrtohex(color),"scale.05/.05",gendisplace3(x,y)]) | |
def genpixelb(x,y,color): | |
return ":".join(["b",bgrtohex(color),"scale.05/.05",gendisplace3(x,y)]) | |
def gentile(x,y,color): | |
return ":".join(["pixel",bgrtohex(color)]) | |
def genimage(img): | |
cmd=[] | |
for ny,y in enumerate(img): | |
for nx,x in enumerate(y): | |
cmd.append(genpixel(nx,ny,x)) | |
return "&".join(cmd) | |
def genimageb(img): | |
cmd=[] | |
for ny,y in enumerate(img): | |
for nx,x in enumerate(y): | |
cmd.append(genpixelb(nx,ny,x)) | |
return "&".join(cmd) | |
def gentileimage(img): | |
cmd="" | |
for ny,y in enumerate(img): | |
for nx,x in enumerate(y): | |
cmd+=" "+gentile(nx,ny,x) | |
cmd+="\n" | |
return cmd | |
if __name__ == "__main__": | |
r=cv2.imread("rickastley.png") | |
print(genimage(r)) |
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
import numpy,cv2 | |
def bgrtohex(v): | |
return "#"+hex(v[2])[2:].zfill(2)+hex(v[1])[2:].zfill(2)+hex(v[0])[2:].zfill(2) | |
def gentile(x,y,color): | |
return "pixel:"+bgrtohex(color) | |
def gentileimage(img): | |
cmd="" | |
for ny,y in enumerate(img): | |
for nx,x in enumerate(y): | |
cmd+=" "+gentile(nx,ny,x) | |
cmd+="\n" | |
return cmd | |
if __name__ == "__main__": | |
r=cv2.imread(input("File name> ")) | |
print(gentileimage(r)) |
Update: added a second file that contains a more minimal and more user-friendly version of the program.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn’t sound very happy without capital letters