The sed is replacing the numbers from random.org to ANSI escape sequences for setting background colors to an RGB value (which is just the same number for R, G and B)
Yes, it is getting colors from an image on the internet. I also added the usual Python horror. It works most of the time... most.
try:
from PIL import Image
from urllib.request import urlopen
#use a fully grayscale image for program to work
img = Image.open(urlopen("https://i.pinimg.com/736x/86/39/fd/8639fd50a4f18ae041f636c1e51ce317--fifty-shades-of-grey--shades.jpg")).convert('RGB') #the forbidden sauce
shades = []
while True == True == True:
n = 0
from random import randint
rgb = img.getpixel((randint(1, img.size[0] - 1), randint(1, img.size[1] - 1)))
#check if christian grey is unique, cannot be too dark or too light
while False == False:
if n == len(shades): break
elif(shades[n] == rgb[0] and shades[n] == rgb[1] and shades[n] == rgb[2]
or rgb[0] + rgb[1] + rgb[2] < 69 or rgb[0] + rgb[1] + rgb[2] > 420 / (6 / 9)):
rgb = img.getpixel((randint(1, img.size[0] - 1), randint(1, img.size[1] - 1)))
n = 0
n += 3
shades.extend(rgb) #todo: use list.append instead
if 50 == len(shades) / 3:
n = 3
from random import choice
shades = sorted(shades, reverse=choice([False, True]))
#print greys in hex (i like hex)
while True != False:
print("#" + str(hex(shades[n - 3]))[2] + str(hex(shades[n - 3]))[3] + str(hex(shades[n - 2]))[2] + str(hex(shades[n - 2]))[3] + str(hex(shades[n - 1]))[2] + str(hex(shades[n - 1]))[3])
n += 3
if n == len(shades) + 3: quit() #end program, it doesn't deserve to live
except IndexError:
print("Whoops! Something went wrong!")
Did my best, it COULD be very fast, but it's pretty luck based. Generate random R, G and B, if they are all equal in the same loop it's a gray value, add to the list and try and find the next one. Discard doubles and print when the list is 50 items long
import random
rand1 = random.randrange(10, 220)
rand2 = random.randrange(10, 220)
rand3 = random.randrange(10, 220)
fiftylist = []
combinations = 0
converthex = ""
doubles = 0
converthex = "#" + '%02x%02x%02x' % (rand1, rand2, rand3)
def truerandom():
global rand1
global rand2
global rand3
global converthex
rand1 = random.randrange(10, 220)
rand2 = random.randrange(10, 220)
rand3 = random.randrange(10, 220)
converthex = "#" + '%02x%02x%02x' % (rand1, rand2, rand3)
global combinations
combinations += 1
print("Tried " + str(combinations) + " combinations, got " + str(len(fiftylist)) + " so far" + " and discarded " + str(doubles) + " doubles", end="\r")
def fsog():
global doubles
while True:
if (rand1 == rand3 and rand2 == rand3):
if converthex not in fiftylist:
fiftylist.append(converthex)
else:
doubles += 1
truerandom()
if len(fiftylist) == 50:
print(*fiftylist, sep = ", ")
break
else:
truerandom()
fsog()
14
u/Mabi19_ Nov 24 '20 edited Nov 24 '20
This isn't really a one-liner, but it is still tweetable!
I'd say it's fairly self-explanatory. Also, woo truly random numbers!
(Note: Tested using the GNU toolchain)
10
u/dodecakiwi Nov 26 '20
Uses Windows.Forms to open 50 windows along the top of the screen, in order, each with a different background color.
5
u/RecDep Nov 27 '20 edited Nov 27 '20
One liner in Haskell.
5
u/[deleted] Nov 25 '20
Yes, it is getting colors from an image on the internet. I also added the usual Python horror. It works most of the time... most.
4
u/allbyoneguy Nov 25 '20 edited Nov 28 '20
Did my best, it COULD be very fast, but it's pretty luck based.
Generate random R, G and B, if they are all equal in the same loop it's a gray value, add to the list and try and find the next one. Discard doubles and print when the list is 50 items long
0
u/[deleted] Nov 23 '20
[deleted] — view deleted comment