allColors.frink

Download or view allColors.frink in plain text format


/** program to make an image with each pixel in a different color.  Now what?
*/


stepsize = 4

colors = new array
multifor color = [new range[0, 255, stepsize], new range[0, 255, stepsize], new range[0, 255, stepsize]]
{
   colors.push[color]
}

colors.shuffle[]

side = ceil[sqrt[length[colors]]]
println["side is $side"]
img = new image[side, side]

idx = 0
for [r,g,b] = colors
{
   img.setPixelInt[idx div side, idx mod side, r,g,b]
   idx = idx + 1
}

img.show[]
img.write["allColors.png"]

g = new graphics
win = g.show[]

for t = 0 to side
{
   for y = 0 to side-2
   {
      for x=0 to side-1
      {
         [r1,g1,b1] = img.getPixelInt[x,y]
         [r2,g2,b2] = img.getPixelInt[x,y+1]
         if (g1 <=> g2) == 1
         {
            temp = img.getPixelAsColor[x,y]
            img.setPixel[x,y,img.getPixelAsColor[x,y+1]]
            img.setPixel[x,y+1, temp]
         }
      }
   }
   
   for x = 0 to side-2
   {
      for y=0 to side-1
      {
         [r1,g1,b1] = img.getPixelInt[x,y]
         [r2,g2,b2] = img.getPixelInt[x+1,y]
         if (r1 <=> r2) == 1
         {
            temp = img.getPixelAsColor[x,y]
            img.setPixel[x,y,img.getPixelAsColor[x+1,y]]
            img.setPixel[x+1,y, temp]
         }
      }
   }
   g = new graphics
   g.add[img]
   win.replaceGraphics[g]
}

img.show[]
img.write["allColors.png"]

//img2 = img.gaussianBlur[3]
//img2.show[]



Download or view allColors.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen, eliasen@mindspring.com