Freeze

From Director Online Wiki
Jump to: navigation, search
--if b = 0 then
--  result := 0
--else begin
--  c := 255 - sqr(255-a) DIV b;
--  if c < 0 then result := 0 else result := c;
--end;
-- ******* freeze mode *************
on freezeBlendMode (image1, image2)
 
  theWidth = image1.width - 1
  theHeight = image1.height - 1
  theImage = image(theWidth + 1, theHeight + 1, 32)
 
  repeat with x = 0 to theWidth
    repeat with y = 0 to theHeight
      theColour1 = image1.getPixel(point(x,y))
      theColour2 = image2.getPixel(point(x,y))
      theNewColour = color(0,0,0)
 
      if theColour2.red = 0 then
        theNewColour.red = 0
      else
        theNewColour.red = max(255 - power(255 - theColour1.red,2) / float(theColour2.red) ,0)
      end if
      if theColour2.green = 0 then
        theNewColour.green = 0
      else
        theNewColour.green = max(255 - power(255 - theColour1.green,2) / float(theColour2.green) ,0)
      end if
      if theColour2.blue = 0 then
        theNewColour.blue = 0
      else
        theNewColour.blue = max(255 - power(255 - theColour1.blue,2) / float(theColour2.blue) ,0)
      end if
 
      theImage.setPixel(point(x, y), theNewColour)
 
    end repeat
  end repeat
  return theImage
end