import random def makeBlankWhite(picture): for p in getPixels(picture): setColor(p, white) chromakey(picture) def darken(pxl,fctr): setRed(pxl,int(getRed(pxl)*fctr) ) setGreen(pxl,int(getGreen(pxl)*fctr)) setBlue(pxl,int(getBlue(pxl)*fctr)) def check(clr): if(clr>255): clr=255 if(clr<0): clr=0 return clr def coloringBook(picture): w=getWidth(picture) h=getHeight(picture) for x in range(1,w-1): for y in range(1,h-1): pixel0=getPixel(picture,x,y) pixel1=getPixel(picture,x+1,y) pixel2=getPixel(picture,x+1,y+1) pixel3=getPixel(picture,x,y+1) clr0=getColor(pixel0) clr1=getColor(pixel1) clr2=getColor(pixel2) clr3=getColor(pixel3) d1=distance(clr0,clr1) d2=distance(clr0,clr2) d3=distance(clr0,clr3) if(d1>22)or(d2>22)or(d3>22): setColor(pixel0, black) else: setColor(pixel0, white) def wave(picture): ripple=requestInteger("0 for Wave, 1 for Ripple") # 0=wave effect # 1=ripple effect wave2(picture,ripple) def wave2(picture,ripple): m=0.0 pxl=getPixels(picture) w=getWidth(picture) h=getHeight(picture) for y in range(1,(96*h)/100): if(ripple==0): m=0.0 for x in range(1,w): m=m+w/6273.1853 a=int(h*(sin(m)+1.0)/50.0) nuColor=getColor(getPixel(picture,x,y+a)) setColor(getPixel(picture,x,y),nuColor) def chromakey(bg): bgH=getHeight(bg) bgW=getWidth(bg) greenPic=makePicture(pickAFile()) xOff=requestInteger("X offset") yOff=requestInteger("Y Offset") for p in getPixels(greenPic): r =getRed( p ) g =getGreen( p ) b =getBlue( p ) if (r + b > g): x=getX(p) y=getY(p) if (y+yOff1.0): a=1.0 if(b>1.0): b=1.0 if(c>1.0): c=1.0 if(a<0): a=0 if(b<0): b=0 if(c<0): c=0 for x in range(1,w): px=getPixel(picture,x,y) r1=getRed(px) g1=getGreen(px) b1=getBlue(px) bright=((r1 + g1 + b1)/3) nuColor=makeColor(int(bright*a) ,int(bright*b),int(bright*c)) setColor(px,nuColor) def circles(picture): h=getHeight(picture) w=getWidth(picture) size=w if(size>h): size=h size=(size*9)/20 cX = w/2 cY = h/2 g=1 # Get the color data colorData=[] for k in range (1,size): for m in range(0,628): n=m/100.0 a=int(k*sin(n)) b=int(k*cos(n)) colorData.append( getColor(getPixel(picture,cX+a,cY+b))) g=g+1 # call four versions of makeCircle size=(size*5)/10 dist=(size*5)/4 makeCircle(picture,colorData,cX+dist,cY+dist,size) makeCircle(picture,colorData,cX-dist,cY+dist,size) makeCircle(picture,colorData,cX+dist,cY-dist,size) makeCircle(picture,colorData,cX-dist,cY-dist,size) def makeCircle(picture,data,x,y,size): g=1 max=len(data)/628 for k in range (1,max): for m in range(0,628): n=m/100.0 a=int(k*size*sin(n)/(2.0*max)) b=int(k*size*cos(n)/(2.0*max)) setColor(getPixel(picture,x+a,y+b),data[g]) g=g+1 repaint(picture) # call four versions of makeCircle size=(size*1)/2 if(size>20): # call four versions of makeCircle dist=(size*4)/4 makeCircle(picture,data,x+dist,y+dist,size) makeCircle(picture,data,x-dist,y+dist,size) makeCircle(picture,data,x+dist,y-dist,size) makeCircle(picture,data,x-dist,y-dist,size) def lake(picture): pixel=getPixels(picture) H=getHeight(picture) W=getWidth(picture) h=H/3 tempPic=makeEmptyPicture(W,h) tempPxl=getPixels(tempPic) for x in range(1,W): for y in range (1,h): nuColor=getColor(pixel[x+2*y*W]) setColor(tempPxl[x+(h-y)*W],nuColor) wave2(tempPic,1) pos=h*2*W for z in tempPxl : setColor(pixel[pos], getColor(z)) pos=pos+1 def checkers(picture): H=getHeight(picture) W=getWidth(picture) px=getPixels(picture) for k in px: setColor(k,makeDarker(getColor(k))) h=H/8 w=(W/8) for q in range(0,8): for z in range(0,8,2): for y in range(0,h-1): for x in range(0,w): p=px[x+z*w+y*W+(h*W+w)*q] setColor(p,makeLighter(getColor(p))) setColor(p,makeLighter(getColor(p))) def cartoon(picture): color=[] for a in range(0,255,64): for b in range(0,255,64): for c in range(0,255,64): color.append(makeColor(a,b,c)) px=getPixels(picture) for v in range(0,len(px)): choice=0 dist=1000.0 pxlColor=getColor(px[v]) for w in range (0,len(color)): d=distance(pxlColor,color[w]) if (d0): nuColor1=getColor(getPixel(picture,x,Y1)) setColor(getPixel(picture,x,y),nuColor1) nuColor2=getColor(getPixel(picture,x,Y2)) setColor(getPixel(picture,x,2*h-y),nuColor2) else: setColor(getPixel(picture,x,y),black) setColor(getPixel(picture,x,2*h-y),black) def melt(picture): H=getHeight(picture) W=getWidth(picture) m=H/6 movement=0.0 for x in range(1,W): n=0 randy = (random.random()-0.5)*3 movement=int(movement+randy) m=m+movement if(m<0): m=0 for y in range(H,1,-1): adj=sin(n) adj=adj*adj n=n+1.5/H Y=int(y-m*adj) if(Y>0)and (Y100)or(intensity<0): intensity=requestInteger("Watermark intensity? 0 - 100%") intensity=intensity/100.0 for x in range(1,w): for y in range(1,h): p=getPixel(wtrmk,x,y) brightness=(getRed(p)+ getGreen(p)+ getBlue(p))/765.0 if (cX-w/2+x>0)and(cX-w/2+x0)and(cY-h/2+y11): filter=requestNumber("0-Coloring Book 1-Wave 2-Chromakey\n 3-Rainbow 4-Circles 5-Lake 6-Checkers\n7-Cartoon 8-Vacuum 9-Melt 10-Watermark 11-White") if(filter==0): coloringBook(pic) elif(filter==1): wave(pic) elif(filter==2): chromakey(pic) elif(filter==3): rainbow(pic) elif(filter==4): circles(pic) elif(filter==5): lake(pic) elif(filter==6): checkers(pic) elif(filter==7): cartoon(pic) elif(filter==8): vacuum(pic) elif(filter==9): melt(pic) elif(filter==10): watermark(pic) elif(filter==11): makeBlankWhite(pic) repaint(pic) path=requestString("Save as") if(path!=''): path=pickAFolder() + '\\' + path + ".jpg" printNow(path) writePictureTo(pic,path)