Skip to content

Instantly share code, notes, and snippets.

View skiptomyliu's full-sized avatar
🫐
🥗 🥐

Dean Liu skiptomyliu

🫐
🥗 🥐
View GitHub Profile
def luminance(r,g,b):
return math.sqrt(0.299 * math.pow(r,2) + 0.587 * math.pow(g,2) + 0.114 * math.pow(b,2))
def tint_to_lum(color, lum):
r,g,b = color
nR,nG,nB = r,g,b
while True:
tint_factor = .005
nR = nR + (255 - nR) * tint_factor
DEG30 = 30/360.
def adjacent_colors((r, g, b), d=DEG30): # Assumption: r, g, b in [0, 255]
r, g, b = map(lambda x: x/255., [r, g, b]) # Convert to [0, 1]
h, l, s = colorsys.rgb_to_hls(r, g, b) # RGB -> HLS
h = [(h+d) % 1 for d in (-d, d)] # Rotation by d
adjacent = [map(lambda x: int(round(x*255)), colorsys.hls_to_rgb(hi, l, s))
for hi in h] # H'LS -> new RGB
adjacent[0] = tuple(adjacent[0])
def average_color(image):
w,h = image.size
x0,y0 = (0,0)
x1,y1 = (w,h)
r,g,b = 0,0,0
area = w*h
for x in range(x0, x1):
for y in range(y0, y1):
@skiptomyliu
skiptomyliu / slope.py
Last active March 9, 2017 03:34
1st degree polynomial
def get_slope(img_seg):
x,y = np.where(img_seg==True)
slope,_ = np.polyfit(x,y,1)
return -1*slope
@skiptomyliu
skiptomyliu / build.sh
Created February 25, 2017 04:48
codesign script
# Name of your app.
APP="mosaicshapes"
# The path of your app to sign.
APP_PATH="/Users/dean/Desktop/m/mosaicshapes.app"
# The path to the location you want to put the signed package.
RESULT_PATH="/Users/dean/Desktop/$APP.pkg"
# The name of certificates you requested.
APP_KEY="3rd Party Mac Developer Application: [Redacted]"
INSTALLER_KEY="3rd Party Mac Developer Installer: [Redacted]"
#APP_KEY=”Developer ID Application: [redacted]”