Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
PDF Publishing in Multimedia Projects
Show Time
Live Video
Set DirectToStage Property of a Flash Sprite
convert to upper or to lowercase
Text Search Engine
Check for activeX component
DirectTransition3D Xtra, Set III
Create Install
XML TextRender v1.3
 

 

 

Behavior Image Magnify

Added on 8/21/2000

 

Compatibilities:
behavior D8 Mac PC Shockwave

Rating:

Author: BarrySwan (website)

Magnifies an image

Download PC Source    Download Mac Source
-- Image Magnification Behaviour

-- by Barry Swan (gerbil@theburrow.co.uk)
--  & Ben Pitt   (ben@robotduck.com)

-- August 2000

property plGrid
property pGridSize
property pSize
property pLoc
property pFishEye
property pZoom
property pMovement
property pFirstSN

property pSampleAreaSize

property facetsize,stage_snapshot,my

on beginSprite me
  
  -- Set up grid points
  
  tHalfGrid = pGridSize / 2.0
  tMaxScalar = mDistance(tHalfGrid, tHalfGrid)  
  
  plGrid = []
  repeat with x = 0 to pGridSize
    tX = x - tHalfGrid
    
    tlRow = []
    repeat with y = 0 to pGridSize
      tY = y - tHalfGrid
      
      tAngle = me.mAngle(tX, tY)
      tDistance = me.mDistance(tX, tY)
      
      tScalar = tDistance / tMaxScalar
      repeat with a = 1 to pFishEye
        tScalar = sin(tScalar)
      end repeat
      
      tlRow.add([sin(tAngle / 180.0 * pi()) * tScalar, cos(tAngle / 180.0 * pi()) * tScalar])
    end repeat    
    
    plGrid.add(tlRow.duplicate())
  end repeat
  
  -- Scale grid points
  
  tSizeScalar = me.mDistance(plGrid[1][pGridSize / 2 + 1][1], plGrid[1][pGridSize / 2 + 1][2])
  
  repeat with y = 1 to pGridSize + 1
    repeat with x = 1 to pGridSize + 1
      plGrid[x][y] = plGrid[x][y] / tSizeScalar
    end repeat
  end repeat
  
  my = sprite(me.spriteNum)
  
  stage_snapshot = the stage.image.duplicate()
  facetsize = pSampleAreaSize/pGridSize
  
end

on prepareFrame me
  
  
  -- Control movement
  
  if pMovement = #fixedtocursor then my.loc = the mouseLoc
  
  -- Draw magnifying area
  
  s = psampleareasize
  area_under_lens = image(s,s,stage_snapshot.depth)
  srcrect = rect(my.Loc - point(s/2, s/2), my.Loc + point(s/2, s/2))
  destrect = rect(0,0,s,s)
  area_under_lens.copyPixels(stage_snapshot, destRect, srcrect,[])
  
  s = abs(psize)*2
  lens = image(s,s,stage_snapshot.depth)
  srcrect = rect(my.Loc - point(s/2, s/2), my.Loc + point(s/2,s/2))
  destrect = rect(0,0,s,s)
  lens.copyPixels(stage_snapshot, destRect, srcrect,[])
  
  
  repeat with y = 1 to pGridSize
    repeat with x = 1 to pGridSize
      
      tX1 = integer((plGrid[x][y][1]*pSize)-psize)
      tY1 = integer((plGrid[x][y][2]*pSize)-psize)
      tX2 = integer((plGrid[x + 1][y][1] * pSize)-psize)
      tY2 = integer((plGrid[x + 1][y][2] * pSize)-psize)
      tX3 = integer((plGrid[x + 1][y + 1][1] * pSize)-psize)
      tY3 = integer((plGrid[x + 1][y + 1][2] * pSize)-psize)
      tX4 = integer((plGrid[x][y + 1][1] * pSize)-psize)
      tY4 = integer((plGrid[x][y + 1][2] * pSize)-psize)
      
      srcrect = rect((x-1)*facetsize,(y-1)*facetsize,x*facetsize,y*facetsize)
      destquad = [point(tX1, tY1), point(tX2, tY2), point(tX3, tY3), point(tX4, tY4)]
      
      lens.copypixels(area_under_lens,destquad,srcrect,[])
      
    end repeat
  end repeat
  
  my.member.image = lens
  
end

on mAngle me, tDX, tDY
  
  -- Calculate angle
  
  if tDY = 0 then
    if tDX > 0 then tAngle = 0
    else tAngle = 180
  else if tDX = 0 then
    if tDY > 0 then tAngle = 90
    else tAngle = 270
  else
    tAngle = integer(atan(tDY / tDX) / pi() * 180.0)
    if tDX * tDY < 0 then tAngle = tAngle + 180
    if tDY < 0 then tAngle = tAngle + 180
  end if
  
  -- Orientate angle and clip within range 0 -> 360
  
  tAngle = (630 - tAngle) mod 360
  
  -- Return the angle
  
  return tAngle
  
end

on mDistance me, tDX, tDY
  
  -- Calculate distance
  
  return sqrt(tDX * tDX + tDY * tDY)
  
end

on getPropertyDescriptionList me
  
  tlData = [:]
  
  tlData[#pZoom] = [#format: #float, #default: 2.0, #comment: "How much to zoom (is a scalar dependant on fisheye effect):"]
  tlData[#pFishEye] = [#format: #integer, #default: 20, #range: [#min: 0, #max: 100], #comment: "Fisheye effect strength (0 = none, 100 = very strong):"]
  tlData[#pGridSize] = [#format: #integer, #default: 5, #range: [#min: 3, #max: 10], #comment: "Resolution of grid effect"]
  tlData[#pSize] = [#format: #integer, #default: -100, #comment: "RADIUS of bounding circle of magnifying area in pixels"]
  tlData[#pSampleAreaSize] = [#format: #integer, #default: 100, #comment: "size of sampling area (edge length of square in pixels)"]
  tlData[#pMovement] = [#format: #symbol, #default: #fixedtocursor, #range: [#fixedtocursor, #stationary], #comment: "Movement of magnifying section:"]  
  return tlData  
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail