property pStageW -- the width of the stage
property pStageH -- the height of the stage
property pLineSize -- the thickness of the lines drawn
property pRandom -- should lines be drawn with random thickness
property pFilled -- are the rounded rectangles filled, or not?
property pMinSize -- the minimum size of each rounded rectangle
property pMaxSize -- the maximum size of each rounded rectangle

on prepareFrame me
  -- determine the width and height of the stage
  pStageW = getStageWidth(me)
  pStageH = getStageHeight(me)
end

--
-- This behavior draws randomly sized, randomly colored rounded rectangles
-- all over the stage using imaging Lingo. Place this in a
-- frame script. No other sprites are needed for it to work.
-- Ken Loge - http://diginoodles.com
--

on getPropertyDescriptionList me
  list = [:]
  addProp list, #pLineSize, [#comment: "Line thickness:", #format: #integer, #default: 0, #range: [#min: 0, #max: 30]]
  addProp list, #pRandom, [#comment: "Randomize line thickness:", #format: #boolean, #default: FALSE]
  addProp list, #pFilled, [#comment: "Rounded rectangles are filled:", #format: #boolean, #default: TRUE]
  addProp list, #pMinSize, [#comment: "Minimum size of each rounded rectangle:", #format: #integer, #default: 5, #range: [#min: 0, #max: 30]]
  addProp list, #pMaxSize, [#comment: "Maximum size of each rounded rectangle:", #format: #integer, #default: 150, #range: [#min: 10, #max: 300]]
  return list
end

on exitFrame me
  -- get an image of the stage
  myImage = _movie.stage.image
  
  -- handle line thickness
  if pRandom = TRUE then
    strokeSize = random(pLineSize)
  else
    strokeSize = pLineSize
  end if
  
  -- get random rectangle size
  roundRectSizeWidth = random(pMaxSize) + pMinSize
  roundRectSizeHeight = random(pMaxSize) + pMinSize
  
  -- get random rectangle origin
  roundRectOrigin = point(random(getStageWidth(me) - pMinSize), random(getStageHeight(me) - pMinSize))
  
  -- set width limits for rectangle
  if roundRectOrigin.locH > getStageWidth(me) - roundRectSizeWidth then
    roundRectOrigin.locH = getStageWidth(me) - roundRectSizeWidth * 2
  end if
  
  -- set height limits for rectangle
  if roundRectOrigin.locV > getStageHeight(me) - roundRectSizeHeight then
    roundRectOrigin.locV = getStageHeight(me) - roundRectSizeHeight * 2
  end if
  
  -- set width and height of rectangle
  roundRectWidth = roundRectOrigin.locH + roundRectSizeWidth
  roundRectHeight = roundRectOrigin.locV + roundRectSizeHeight
  
  -- handle filled or hollow shapes
  if pFilled then
    -- filled
    myImage.fill(point(roundRectOrigin.locH, roundRectOrigin.locV), point(roundRectWidth, roundRectHeight), [#shapeType: #roundRect, #lineSize: strokeSize, #color: rgb(random(255), random(255), random(255))])
  else
    -- hollow
    myImage.draw(point(roundRectOrigin.locH, roundRectOrigin.locV), point(roundRectWidth, roundRectHeight), [#shapeType: #roundRect, #lineSize: strokeSize, #color: rgb(random(255), random(255), random(255))])
  end if
  
  _movie.go(_movie.frame)
end

-- get the width of the stage
on getStageWidth me
  return _movie.stage.rect[3] - _movie.stage.rect[1]
end

-- get the height of the stage
on getStageHeight me
  return _movie.stage.rect[4] - _movie.stage.rect[2]
end