Guest

How can I make this Shoes code from bogging down the computer

By: a guest on Jan 28th, 2012  |  syntax: None  |  size: 3.63 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. Shoes.app ( :title => 'Circles', :width => 500, :height => 500, :resizable => false ) do
  2.                 i = 0
  3. # Animation loop
  4.     animate ( 24 ) do |i|
  5. # Variables For Randomized Colours
  6.                 randomCol = rgb( ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand )
  7.                 randomCol2 = rgb( ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand )
  8.                 randomCol3 = rgb( ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand )
  9.                 randomCol4 = rgb( ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand )
  10.                 background randomCol..randomCol2
  11.                 fill    randomCol3
  12.                 stroke  randomCol4
  13.                 strokewidth             ( 0..5 ).rand
  14. # Generate 10 circles per loop cycle
  15.                 10.times{
  16.                 i += 1
  17.                 oval :left => ( -5..self.width ).rand,
  18.                 :top => ( -5..self.height ).rand,
  19.                 :radius => ( 1..100 ).rand
  20.                 } end
  21.         end
  22.        
  23. Shoes.app ( :title => 'Circles', :width => 500, :height => 500, :resizable => false ) do
  24.  
  25.   # Animation loop
  26.   animate ( 24 ) do |i|
  27.     app.clear
  28.  
  29.     # Variables For Randomized Colours
  30.     randomCol = rgb( ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand )
  31.     randomCol2 = rgb( ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand )
  32.     randomCol3 = rgb( ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand )
  33.     randomCol4 = rgb( ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand )
  34.  
  35.     background randomCol..randomCol2
  36.     fill    randomCol3
  37.     stroke  randomCol4
  38.     strokewidth ( 0..5 ).rand
  39.  
  40.     # Generate 10 circles per loop cycle
  41.     10.times do |i|
  42.       i += 1
  43.       oval :left => ( -5..self.width ).rand,
  44.         :top => ( -5..self.height ).rand,
  45.         :radius => ( 1..100 ).rand
  46.     end
  47.   end
  48. end
  49.        
  50. Shoes.app ( :title => 'Circles', :width => 500, :height => 500, :resizable => false ) do
  51.  
  52.   # Animation loop
  53.   animate ( 24 ) do |i|
  54.     app.clear if (i % 6 == 0)
  55.  
  56.     # Variables For Randomized Colours
  57.     randomCol = rgb( ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand )
  58.     randomCol2 = rgb( ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand )
  59.     randomCol3 = rgb( ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand )
  60.     randomCol4 = rgb( ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand )
  61.  
  62.     background randomCol..randomCol2
  63.     fill    randomCol3
  64.     stroke  randomCol4
  65.     strokewidth ( 0..5 ).rand
  66.  
  67.     # Generate 10 circles per loop cycle
  68.     10.times do |i|
  69.       i += 1
  70.       oval :left => ( -5..self.width ).rand,
  71.         :top => ( -5..self.height ).rand,
  72.         :radius => ( 1..100 ).rand
  73.     end
  74.   end
  75. end
  76.        
  77. Shoes.app ( :title => 'Circles', :width => 500, :height => 500, :resizable => false ) do
  78.   n = 6
  79.   @layers = []
  80.   n.times { @layers << [] }
  81.   # Animation loop
  82.   animate ( 24 ) do |i|
  83.     oldest = i % n
  84.     # Clear out oldest frame
  85.     @layers[oldest].each {|x| x.remove}
  86.     @layers[oldest] = []
  87.  
  88.     # Variables For Randomized Colours
  89.     randomCol = rgb( ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand )
  90.     randomCol2 = rgb( ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand )
  91.     randomCol3 = rgb( ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand )
  92.     randomCol4 = rgb( ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand, ( 0..255 ).rand )
  93.  
  94.     @layers[oldest] << background(randomCol..randomCol2)
  95.     fill    randomCol3
  96.     stroke  randomCol4
  97.     strokewidth ( 0..5 ).rand
  98.  
  99.     # Generate 10 circles per loop cycle
  100.     10.times do |i|
  101.       @layers[oldest] << oval (:left => ( -5..self.width ).rand,
  102.         :top => ( -5..self.height ).rand,
  103.         :radius => ( 1..100 ).rand)
  104.       end
  105.   end
  106. end