Hi Arthur...

> I have tried and tried to make this work and I cannot. Do you have a
small director file that does this that you can send me so that I can
study it.



Luckily, I caught your email to me, as it got filtered into Lingo-L!
The entire behavior is below, and it gets attached to a 1-bit 1x1 pixel
image on the stage, so there really isn't a file I can send you per se,
but I'm posting all my code, for the benefit of others as well.  I'll
try to explain, line by line, what I'm doing, with lots of comments.  If
you have any questions, let me know.

First, make a movie with two images in it, one a 1x1 pixel black image,
and put it on the stage.  Next, have some photo in your cast that you
want to extract the luminosity out of, but don't put it on the stage.
The following lingo is taken out of the whole behavior.  Alternately,
you could make a behavior and use a getPropertyDescritpionList dropdown
menu to choose the image you want as the source photo.

-- create a black and white buffer image with same dimensions as the
photo, not the 1x1 pixel on the stage.
theBW = image(120, 180, 8)
theBW.paletteRef = #grayscale -- make sure it's grayscale (because 8-bit
could still be 256 *color*)
-- the buffer image is grayscale so that you don't have to desaturate
any colors: you're just dealing with brightness.  In effect, when you
copy the color photo into the #grayscale image, you're converting it to
black and white.
-- SIDE NOTE --> This is NOT the best way to convert a color photo to
grayscale, but it's my Lingo way. 
-- The REAL way to do it is with HSL in Photoshop, going through each of
the channels!
-- copy a color image into the 8-bit #grayscale image forces it to
convert it to BW on the following line...
theBW.copypixels(member("photo").image,
member("photo").image.rect,member("photo").image.rect)
-- next, I colorize a "background" buffer image for the newly b&w photo
(like taking a red piece of construction paper, and running it through a
laser printer to print a photo).
-- create the color buffer image, same dimensions as BW buffer image
theColorized = image(120, 180, 32) 
-- here, I chose green as the "color of the construction paper," so to
speak.
theColorized.fill(theColorized.rect, rgb(0,0,255))
-- then apply the BW photo into the color photo
theColorized.copyPixels(theBW, theColorized.rect,
theColorized.rect,[#ink:39])
-- by adding [#ink:39], what I did was transfer the "darkness" info out
of the photo and onto the solid field of color.  If you think about it,
if the grayscale photo has values that go from black to white, only the
values darker than the substrate get copied over to the green.  And, any
white in the grayscale image will not overwrite the green pixels.

Hope this is clearer for you.
- Michael M.



-- the whole behavior, timeouts and all
==================================================================
-- This behavior creates an image on the stage that is a collage of two
rows of four colorized,smaller b&w images, picked randomly out of an
external cast, and fades them in, quite nicely, I might add.  :-)

property pSp
property pBackupImage
property pRecentPhotosPicked
property pColors
property pData
property pRectList -- list (master), and duplicate list (to pull from)
used to position copyPixel calls

on beginSprite(me) -- initialize image
  pSp = sprite(me.spriteNum)
  pColors = [rgb(114,39,80), rgb(101,87,135), rgb(159,27,41),
rgb(43,109,115), rgb(0,69,132),
rgb(211,88,0),rgb(151,148,44),rgb(110,99,88)] -- our corporate colors
  theRectSet = [[rect(0,0,120,180), VOID], [rect(120,0,240,180), VOID],
[rect(240,0,360,180), VOID], [rect(360,0,480,180), VOID],
[rect(0,180,120,360), VOID], [rect(120,180,240,360), VOID],
[rect(240,180,360,360), VOID], [rect(360,180,480,360), VOID]]
  pRectList = [theRectSet, duplicate(theRectSet), duplicate(theRectSet)]
-- [the rect, the associated image, the second backup used to go to the
next round]
  pData = [#pIncrement:0, #pCastNum:VOID, #pRect:VOID] -- shared data
between timeouts
  pBackupImage = pSp.member.image.duplicate()
  -- pick 8 initial "previously used" images to ensure no doubling from
the outset
  pRecentPhotosPicked = [] -- [castnumber, 8 positions] no double images
should show up 
  repeat while (TRUE)
    w = random(castLib("thumbs").member.count) -- I have a separate cast
filled just with my thumbnail images
    if (pRecentPhotosPicked.getOne(w) = 0) then -- ensures no double
occurances within this list
      pRecentPhotosPicked.add(w)
      pRectList[2][pRecentPhotosPicked.count][2] = w
    end if
    if pRecentPhotosPicked.count = 8 then
      exit repeat
    end if
  end repeat
  -- create initial image of the thumbs cast, 4 columns, 2 rows, all are
120 x 180
  initImg = image(480, 360, 32)
  imageIndex = 1
  theT = 0
  theB = 180
  repeat with r = 1 to 2
    theL = 0
    theR = 120
    repeat with c = 1 to 4
      -- colorized photo
      theThumbImage = pRectList[2][imageIndex][2]
      imageIndex = imageIndex + 1
      theBW = image(120, 180, 8)
      theBW.paletteRef = #grayscale
      theBW.copypixels(member(theThumbImage, "thumbs").image,
member(theThumbImage, "thumbs").image.rect, member(theThumbImage,
"thumbs").image.rect)
      theColorized = image(120, 180, 32)
      theColorized.fill(theColorized.rect,
pColors[random(pColors.count)]) -- fill with random FM Global color
      theColorized.copyPixels(theBW, theColorized.rect,
theColorized.rect, [#ink:39])
      initImg.copyPixels(theColorized, rect(theL, theT, theR, theB),
theColorized.rect)
      theL = theL + 120
      theR = theR + 120
    end repeat
    theT = theT + 180
    theB = theB + 180
  end repeat
  pSp.member.image = initImg
  pSp.member.regPoint = point(0,0)  
  chooseSaturationPosition =
timeout("chooseSaturationPosition").new(500, #chooseSaturationPosition,
me) -- start animation
end

on chooseSaturationPosition(me)
  timeout("chooseSaturationPosition").forget() -- end this part of the
animation (picking postion and colorizing image)
  -- pick position to copy to, create colorized initial image
  if (pRectList[2].count = 0) then
    -- init again!  8 colorized, then 8 colored!
    pRectList[2] = duplicate(pRectList[1]) -- then change all image
representatives from void to a member number!!!!
    -- make sure not to pick any of the images from the previous 8!
    theNewSet = []
    repeat while (TRUE)
      w = random(castLib("thumbs").member.count)
      if (pRecentPhotosPicked.getOne(w) = 0) and (theNewSet.getOne(w) =
0) then -- shouldn't be double from previous set, or already in new set
being built
        theNewSet.add(w)
        pRectList[2][theNewSet.count][2] = w -- was pRecentPhotosPicked
      end if
      if (theNewSet.count = 8) then
        pRecentPhotosPicked = theNewSet
        exit repeat
      end if
    end repeat
    pRectList[3] = duplicate(pRectList[2])
    recolorize = timeout("recolorize").new(100, #recolorize, me) --
phase 4 of the animation, build a new set of colorized thumbs
  else
    theItem = random(pRectList[2].count) -- the list to pick and delete
from  
    pData.pRect = pRectList[2][theItem][1]
    pData.pCastNum = pRectList[2][theItem][2]
    pRectList[2].deleteAt(theItem)   
    delaySaturate = timeout("delaySaturate").new(250, #delaySaturate,
me)-- begin phase 2 of animation: delay to launch colorized image
saturatation
  end if
end

on delaySaturate(me) -- just a small delay!
  timeout("delaySaturate").forget() -- end phase 2 of animation
  saturate = timeout("saturate").new(25,#saturate, me) -- begin phase 3
of animation: saturation process
end

on saturate(me)
  if pData.pIncrement < 72 then
    pSp.member.image.copyPixels(member(pData.pCastNum, "thumbs").image,
pData.pRect, member(pData.pCastNum, "thumbs").image.rect, [#blend:2])
    pData.pIncrement = pData.pIncrement + 1
  else
    timeout("saturate").forget() -- end phase 3
    pData.pIncrement = 0
    chooseSaturationPosition =
timeout("chooseSaturationPosition").new(250, #chooseSaturationPosition,
me) -- restart phase 1 of animation
  end if
end

on recolorize(me)
  if (pRectList[2].count > 0) then
    theTarget = random(pRectList[2].count)
    -- build the COLORIZED image, randomly place it
    theBW = image(120, 180, 8)
    theBW.paletteRef = #grayscale
    theBW.copypixels(member(pRectList[2][theTarget][2], "thumbs").image,
member(pRectList[2][theTarget][2], "thumbs").image.rect,
member(pRectList[2][theTarget][2], "thumbs").image.rect)
    theColorized = image(120, 180, 32)
    theColorized.fill(theColorized.rect, pColors[random(pColors.count)])
-- fill rectangle with random FM Global color
    theColorized.copyPixels(theBW, theColorized.rect, theColorized.rect,
[#ink:39]) -- apply B&W version of thumbnail to solid color #39=darkest
    pSp.member.image.copyPixels(theColorized,
pRectList[2][theTarget][1], theColorized.rect)
    pRectList[2].deleteAt(theTarget)
  else
    timeout("recolorize").forget()
    pRectList[2] = duplicate(pRectList[3])
    chooseSaturationPosition =
timeout("chooseSaturationPosition").new(500, #chooseSaturationPosition,
me) -- start animation
  end if
end

on endSprite(me)
  _movie.timeOutList = []
  pSp.member.image = pBackupImage
end


[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
lingo-l@penworks.com  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to