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
Import SWA (Shockwave Audio)
The Director Podcast
Simatrix Lingo Font
Expire date
DM Transitions Pack 2
Wind-Xtra
OnStage DVD for Director
Lingo and Shockwave Sourcebook
free MD5 hashing Xtra
Simple Radio Button Group
 

 

 

Behavior Change bitmap brightness and contrast behaviour

Added on 4/4/2001

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

Rating:

Author: BarrySwan (website)

Changes bitmap brightness and contrast

---------------------------> Information about this behaviour
-- [S] Change bitmap brightness and contrast behaviour
-- Behaviour written by Barry Swan
-- E-mail: gerbil@theburrow.co.uk
-- WWW:    http://www.theburrow.co.uk

---------------------------> Property definitions for the behaviour
property pSN, pS
property pOldInk, pOldBGColor, pOldColor

property pBrightness
property pContrast

property pOldBrightness
property pOldContrast

---------------------------> Initialise the sprite and properties
on beginSprite me
  
  -- Set up sprite properties
  pSN = me.spriteNum
  pS = sprite(pSN)
  pOldInk = pS.ink
  pOldBGColor = pS.bgcolor
  pOldColor = pS.color
  
  -- Set to use darken ink
  pS.ink = 41
  
  -- Set up behaviour properties (to guarantee a refresh on the first prepareFrame)
  pOldBrightness = -1
  pOldContrast = -1
  
end

---------------------------> Check for values being changed - if so update sprite
on prepareFrame me
  
  -- Change sprite if brightness or contrast has changed
  if pBrightness <> pOldBrightness OR pContrast <> pOldContrast then
    me.UpdateBrightnessAndContrast()
    
    -- Store current values
    pOldBrightness = pBrightness
    pOldContrast = pContrast
  end if
  
end

---------------------------> The actual handler to change the sprite values
on UpdateBrightnessAndContrast me
  
  -- Apply brightness
  tBGBrightness = min(pBrightness * 256 / 100, 256)
  tFGBrightness = max(((pBrightness - 100) * 256 / 100), 0)
  
  -- Apply contrast  
  tBGBrightness = tBGBrightness * pContrast / 100
  tFGBrightness = tFGBrightness + (127 - tFGBrightness) * (100 - pContrast) / 100
  
  -- Set sprite values
  pS.bgcolor = rgb(tBGBrightness, tBGBrightness, tBGBrightness)
  pS.color = rgb(tFGBrightness, tFGBrightness, tFGBrightness)
  
end

---------------------------> Reset the sprite when finished
on endSprite me
  
  -- Restore the old ink
  pS.ink = pOldInk
  pS.bgcolor = pOldBGColor
  pS.color = pOldColor
  
end

---------------------------> Input the initial property values
on getPropertyDescriptionList me
  
  -- Set up list
  tlData = [:]
  
  -- Options for brightness
  tlData[#pBrightness] = [
      #format: #integer,
      #default: 100,
      #range: [#min: 0, #max: 200],
      #comment: "Brightness (measured in percentage with 100% being no change):"
  ]
  
  -- Options for contrast
  tlData[#pContrast] = [
      #format: #integer,
      #default: 100,
      #range: [#min: 0, #max: 100],
      #comment: "Contrast (measured in percentage with 100% being no change):"
  ]
  
  -- Return list
  return tlData
  
end

---------------------------> Description of the behaviour in the behaviour inspector
on getBehaviorDescription me
  
  -- Create description string
  tInfo = "[S] Change bitmap brightness and contrast behaviour" & RETURN & RETURN
  
  tInfo = tInfo & "Behaviour by Barry Swan" & RETURN
  tInfo = tInfo & "E-mail: gerbil@theburrow.co.uk" & RETURN
  tInfo = tInfo & "www:    www.theburrow.co.uk" & RETURN & RETURN
  
  tInfo = tInfo & "Drop this behaviour onto a bitmap sprite to alter it's brightness and contrast without altering the graphic itself." & RETURN
  tInfo = tInfo & "Note that it uses the DARKEN ink. Therefore it will override the ink setting for the sprite in the score." & RETURN
  tInfo = tInfo & "The DARKEN ink has transparency identical to MATTE ink." & RETURN & RETURN
  
  tInfo = tInfo & "Parameters are:" & RETURN & RETURN
  
  tInfo = tInfo & "Brightness - measured as a percentage with 100% being normal. 0% is darkest, 200% is lightest." & RETURN
  tInfo = tInfo & "Contrast - measured as a percentage with 100% being normal. 0% is no contrast." & RETURN & RETURN
  
  tInfo = tInfo & "You can change the properties and the behaviour will automatically update the graphic to represent the new values." & RETURN
  tInfo = tInfo & "To alter brightness change the 'pBrightness' property of the behaviour." & RETURN
  tInfo = tInfo & "To alter contrast change the 'pContrast' property of the behaviour."
  
  -- Return string
  return tInfo
  
end

 


Contact

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

Send e-mail