1308: "Christmas Lights"

This forum is for the individual discussion thread that goes with each new comic.

Moderators: Moderators General, Prelates, Magistrates

Kanawha
Posts: 1
Joined: Fri Dec 27, 2013 6:20 pm UTC

Re: 1308: "Christmas Lights"

There must be a blue star on top.

George2
Posts: 12
Joined: Sun Jul 13, 2008 3:41 pm UTC
Location: Egypt

Re: 1308: "Christmas Lights"

Spoiler:

Code: Select all

`#Python 2.5#open original comic in ms paint#pour pink (#ff0080) in the empty space#save as 24-bit bitmap with the name "christmas_lights.bmp"a=file('christmas_lights.bmp','rb+'); header=a.read(54)pixels=[['']*554 for y in range(282)]nonbgd=[]for y in range(282): for x in range(554):  pixcol=a.read(3); pixels[y][x]=pixcol  if pixcol=='\x80\x00\xff' or (x,y) in [(74,31),(75,31),(464,62),(464,63)]: pass  else: nonbgd.append((x,y)) k=a.read(2)a.close()nonbgd=set(nonbgd)def groupof(x,y): edges=set([(x,y)]); group=edges while edges:  newedges=reduce(lambda x,y: x+y, [[(px-1,py),(px+1,py),(px,py-1),(px,py+1)] for (px,py) in edges])  newedges=(set(newedges)-group)&nonbgd  group=group|newedges; edges=newedges return groupgroups=[]while nonbgd: curgroup=groupof(*nonbgd.pop()) nonbgd-=curgroup if set([(0,0),(47,80),(369,86)])&curgroup: pass else: groups.append(curgroup)def color(group): group=list(group); group.sort(); i=0; r,g,b=0,0,0; maxy=0 while i<len(group):  curx=group[i]; curcol=[]; miny=group[i]  while i<len(group) and group[i]==curx: curcol.append(pixels[group[i]][group[i]]); i+=1  colheight=group[i-1]-miny  if group[i-1]>maxy: maxy=group[i-1]  try:   b2,g2,r2 = [ord(c) for c in curcol]   r+=r2*colheight; g+=g2*colheight; b+=b2*colheight  except: pass maxc=max(r,g,b) miny=min(group, key=lambda x: x) color=(r*256/maxc,g*256/maxc,b*256/maxc) center=((group+group[-1])/2.,(miny+maxy)/2.) size=((group[-1]-group)*(maxy-miny))**0.5 print ((group[-1]-group),(maxy-miny)),maxy,group return color,center,sizeoutfile=file('lights.html','wb+')outfile.write('<!DOCTYPE html>\r\n<html>\r\n<body>\r\n<svg width="554" height="282">\r\n<rect width="554" height="282" style="fill:black"/>\r\n<defs>\r\n<radialGradient id="grad1" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">\r\n<stop offset="65%" style="stop-color:black;stop-opacity:0"/>\r\n<stop offset="100%" style="stop-color:black;stop-opacity:.9"/>\r\n</radialGradient>\r\n</defs>\r\n')for group in groups: k=color(group) outfile.write('<circle cx="%s" cy="%s" r="%s" fill="rgb%s"/>\r\n'%(k,281-k,k/2,k)) outfile.write('<circle cx="%s" cy="%s" r="%s" fill="url(#grad1)"/>\r\n'%(k,281-k,k*1.01/2))outfile.write('</svg>\r\n</body>\r\n</html>')`

I was bored.

Happy new year everyone Flumble
Yes Man
Posts: 2235
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: 1308: "Christmas Lights"

Darn, I ought to do exactly that, only in javascript. Congratulations on beating me to it and a happy new year. 