home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Resource / Random Iconator < prev    next >
Encoding:
Text File  |  1999-03-04  |  5.8 KB  |  175 lines  |  [TEXT/ToyS]

  1. property kasGenTitle : "Generating Icon"
  2.  
  3.  
  4. on run
  5.     ShowAlert("Drop items on this Applet to give them random icons.")
  6. end run
  7.  
  8.  
  9. on open fsObjs
  10.     -- Get our icon
  11.     set myIcon to (the icon for (path to me))
  12.     
  13.     repeat with fsObj in fsObjs
  14.         set inf to basic info for fsObj
  15.         if (catalog kind of inf) is a folder then
  16.             if (folder ref of inf is 2) then -- root directory?
  17.                 set ic to GenerateVolumeIcon()
  18.             else
  19.                 set ic to GenerateFolderIcon()
  20.             end if
  21.         else
  22.             set ic to GenerateItemIcon()
  23.         end if
  24.         -- Is it a server item?
  25.         if (vol kind of (the volume info of fsObj) is AFP volume) then
  26.             set choice to (display dialog ¬
  27.                 ("The item " & (catalog name of (basic info for fsObj)) & " is on a server volume." & ¬
  28.                     return & return & ¬
  29.                     "Do you want to set compatible icons?") buttons {"< 8.5", "> 8.1", "Both"} default button 3)
  30.             set the icon of fsObj to ic compatibility (button returned of choice is "Both")
  31.         else
  32.             set the icon of fsObj to ic
  33.         end if
  34.     end repeat
  35. end open
  36.  
  37.  
  38. -- All in 128 x 128 with pen 4x4
  39. property kasVolPolyT : {{108, 12}, {0, 12}, {16, 0}, {124, 0}, {108, 12}}
  40. property kasVolPolyR : {{108, 12}, {108, 124}, {124, 108}, {124, 0}, {108, 12}}
  41. property kasVolPoly : {{108, 12}, {0, 12}, {0, 124}, {108, 124}, {108, 12}}
  42.  
  43. property kasColMin : 22222
  44. property kasColMax : 61116
  45. property kasColStepMin : 11
  46. property kasColStepMax : 111
  47. property kasCentMin : 8
  48. property kasCentMax : 100
  49.  
  50.  
  51. on GenerateVolumeIcon()
  52.     set icWin to ¬
  53.         display drawing titled kasGenTitle ¬
  54.             with dimensions {128, 128}
  55.     
  56.     -- Draw solids
  57.     draw a polygon into icWin ¬
  58.         using data kasVolPolyT ¬
  59.         using state {fg color:"CCCCCC"} ¬
  60.         filling it with the pen
  61.     draw a polygon into icWin ¬
  62.         using data kasVolPolyR ¬
  63.         using state {fg color:"BBBBBB"} ¬
  64.         filling it with the pen
  65.     draw a polygon into icWin ¬
  66.         using data kasVolPoly ¬
  67.         using state {fg color:"EEEEEE"} ¬
  68.         filling it with the pen
  69.     
  70.     -- Draw Face
  71.     set cx to random number from kasCentMin to kasCentMax
  72.     set cy to 16 + (random number from kasCentMin to kasCentMax)
  73.     set cr to random number from kasColMin to kasColMax
  74.     set cg to random number from kasColMin to kasColMax
  75.     set cb to random number from kasColMin to kasColMax
  76.     set sr to random number from kasColStepMin to kasColStepMax
  77.     set sg to random number from kasColStepMin to kasColStepMax
  78.     set sb to random number from kasColStepMin to kasColStepMax
  79.     
  80.     -- Top Roll
  81.     repeat with x from 4 to 108
  82.         draw a line into icWin ¬
  83.             inside of {x, 16, cx, cy} ¬
  84.             using state {fg col64:{cr, cg, cb}, pen size:{1, 1}}
  85.         
  86.         set cr to cr + sr
  87.         set cg to cg + sg
  88.         set cb to cb + sb
  89.         
  90.         if (cr > kasColMax) then set sr to -(random number from kasColStepMin to kasColStepMax)
  91.         if (cr < kasColMin) then set sr to (random number from kasColStepMin to kasColStepMax)
  92.         if (cg > kasColMax) then set sg to -(random number from kasColStepMin to kasColStepMax)
  93.         if (cg < kasColMin) then set sg to (random number from kasColStepMin to kasColStepMax)
  94.         if (cb > kasColMax) then set sb to -(random number from kasColStepMin to kasColStepMax)
  95.         if (cb < kasColMin) then set sb to (random number from kasColStepMin to kasColStepMax)
  96.     end repeat
  97.     
  98.     -- Right Roll
  99.     repeat with y from 16 to 124
  100.         draw a line into icWin ¬
  101.             inside of {107, y, cx, cy} ¬
  102.             using state {fg col64:{cr, cg, cb}, pen size:{1, 1}}
  103.         
  104.         set cr to cr + sr
  105.         set cg to cg + sg
  106.         set cb to cb + sb
  107.         
  108.         if (cr > kasColMax) then set sr to -(random number from kasColStepMin to kasColStepMax)
  109.         if (cr < kasColMin) then set sr to (random number from kasColStepMin to kasColStepMax)
  110.         if (cg > kasColMax) then set sg to -(random number from kasColStepMin to kasColStepMax)
  111.         if (cg < kasColMin) then set sg to (random number from kasColStepMin to kasColStepMax)
  112.         if (cb > kasColMax) then set sb to -(random number from kasColStepMin to kasColStepMax)
  113.         if (cb < kasColMin) then set sb to (random number from kasColStepMin to kasColStepMax)
  114.     end repeat
  115.     
  116.     -- Bottom Roll
  117.     repeat with x from 108 to 4 by -1
  118.         draw a line into icWin ¬
  119.             inside of {x, 123, cx, cy} ¬
  120.             using state {fg col64:{cr, cg, cb}, pen size:{1, 1}}
  121.         
  122.         set cr to cr + sr
  123.         set cg to cg + sg
  124.         set cb to cb + sb
  125.         
  126.         if (cr > kasColMax) then set sr to -(random number from kasColStepMin to kasColStepMax)
  127.         if (cr < kasColMin) then set sr to (random number from kasColStepMin to kasColStepMax)
  128.         if (cg > kasColMax) then set sg to -(random number from kasColStepMin to kasColStepMax)
  129.         if (cg < kasColMin) then set sg to (random number from kasColStepMin to kasColStepMax)
  130.         if (cb > kasColMax) then set sb to -(random number from kasColStepMin to kasColStepMax)
  131.         if (cb < kasColMin) then set sb to (random number from kasColStepMin to kasColStepMax)
  132.     end repeat
  133.     
  134.     -- Left Roll
  135.     repeat with y from 124 to 16 by -1
  136.         draw a line into icWin ¬
  137.             inside of {4, y, cx, cy} ¬
  138.             using state {fg col64:{cr, cg, cb}, pen size:{1, 1}}
  139.         
  140.         set cr to cr + sr
  141.         set cg to cg + sg
  142.         set cb to cb + sb
  143.         
  144.         if (cr > kasColMax) then set sr to -(random number from kasColStepMin to kasColStepMax)
  145.         if (cr < kasColMin) then set sr to (random number from kasColStepMin to kasColStepMax)
  146.         if (cg > kasColMax) then set sg to -(random number from kasColStepMin to kasColStepMax)
  147.         if (cg < kasColMin) then set sg to (random number from kasColStepMin to kasColStepMax)
  148.         if (cb > kasColMax) then set sb to -(random number from kasColStepMin to kasColStepMax)
  149.         if (cb < kasColMin) then set sb to (random number from kasColStepMin to kasColStepMax)
  150.     end repeat
  151.     
  152.     -- Draw frame
  153.     draw a polygon into icWin ¬
  154.         using data (kasVolPoly & kasVolPolyT & kasVolPolyR) ¬
  155.         using state {fg color:"111111", pen size:{4, 4}}
  156.     
  157.     set ic to ¬
  158.         capture picture from icWin ¬
  159.             using depth 32 ¬
  160.             with pixel conversion
  161.     display drawing icWin with disposal
  162.     
  163.     return ic
  164. end GenerateVolumeIcon
  165.  
  166.  
  167. on GenerateItemIcon()
  168.     return GenerateVolumeIcon()
  169. end GenerateItemIcon
  170.  
  171.  
  172. on GenerateFolderIcon()
  173.     return GenerateVolumeIcon()
  174. end GenerateFolderIcon
  175.