Tutorial 2 - Stage Snapshot Operations

The Director embed seen below uses the following code framents:

Initialization....Draw-loop code....Start/stop draw code....Color pick code....Brush choice code....The Embed

Initialization:

	on startMovie
	  global brush_sprite,constraint_sprite,clear_sprite
	  global indicator_sprite,first_brush_icon,last_brush_icon
	  global dragging
	  
	  dragging = false             -- initialize the dragging flag in the 'off' condition
	  brush_sprite = 7
	  constraint_sprite = 24
	  first_brush_icon = 13
	  last_brush_icon = 18
	  clear_sprite = 2
	  indicator_sprite = 25
	  
	  sprite(brush_sprite).constraint = sprite(constraint_sprite)
	  sprite(brush_sprite).puppet = 1
	  sprite(brush_sprite).trails = 1
	end

Draw-loop code:

on exitFrame
  global dragging
  global brush_sprite,constraint_sprite,clear_sprite
  global indicator_sprite,first_brush_icon,last_brush_icon
 
  if not dragging then             -- that's all
    go to the frame
  else                             -- position the brush
    sprite(brush_sprite).locH = the MouseH - sprite(brush_sprite).width/2
    sprite(brush_sprite).locV = the MouseV - sprite(brush_sprite).height/2
    go to the frame
  end if
  
end

Start/stop draw code:

on mouseDown   -- start draw
  global dragging
  global brush_sprite,constraint_sprite,clear_sprite
  global indicator_sprite,first_brush_icon,last_brush_icon
  
  sprite(brush_sprite).constraint = constraint_sprite    -- set the position costraint on the brush sprite
  sprite(brush_sprite).locH = the mouseH - sprite(brush_sprite).width/2
  sprite(brush_sprite).locV = the mouseV - sprite(brush_sprite).height/2
  dragging = true
end

on mouseUp   -- end draw
  global dragging
  global brush_sprite,constraint_sprite,clear_sprite
  global indicator_sprite,first_brush_icon,last_brush_icon
  
  sprite(brush_sprite).constraint = 0    -- drop the position constraint on the brush sprite
  sprite(brush_sprite).locH = 20000
  dragging = false
end

Color pick code:

on mouseUp
  global brush_sprite,constraint_sprite,clear_sprite
  global indicator_sprite,first_brush_icon,last_brush_icon
  
  hval = (the mouseH - sprite(the clickOn).left + 4)/8    -- get the box clicked
  vval = (the mouseV - sprite(the clickOn).top + 4)/8
  colno = (vval - 1) * 16 + (hval - 1)
  
  sprite(indicator_sprite).forecolor = colno     -- set the indicator to this color
  sprite(brush_sprite).forecolor = colno     -- set the brush to this color
end

Brush choice code:

on mouseUp
  global brush_sprite,constraint_sprite,clear_sprite
  global indicator_sprite,first_brush_icon,last_brush_icon
  
  sprite(brush_sprite).width = sprite(the clickOn).width
  sprite(brush_sprite).height = sprite(the clickOn).height
  
  repeat with j = first_brush_icon to last_brush_icon
    sprite(j).forecolor = 255
  end repeat
  
  sprite(the clickOn).forecolor = 250     -- darkish gray
  
end