Jeder dieser Ovale und Hintergründe, die Sie zeichnen, ist ein separater Gegenstand im Speicher, was bedeutet, dass er nach einer Weile abstürzt. Wenn Sie nur das letzte Bild zeigen, wollen Sie gezeichnet, dann müssen Sie die App jedes Mal löschen:
Shoes.app (:title => 'Circles', :width => 500, :height => 500, :resizable => false) do
# Animation loop
animate (24) do |i|
app.clear
# Variables For Randomized Colours
randomCol = rgb((0..255).rand, (0..255).rand, (0..255).rand, (0..255).rand)
randomCol2 = rgb((0..255).rand, (0..255).rand, (0..255).rand, (0..255).rand)
randomCol3 = rgb((0..255).rand, (0..255).rand, (0..255).rand, (0..255).rand)
randomCol4 = rgb((0..255).rand, (0..255).rand, (0..255).rand, (0..255).rand)
background randomCol..randomCol2
fill randomCol3
stroke randomCol4
strokewidth (0..5).rand
# Generate 10 circles per loop cycle
10.times do |i|
i += 1
oval :left => (-5..self.width).rand,
:top => (-5..self.height).rand,
:radius => (1..100).rand
end
end
end
, die als Ihr Original (außer der Tatsache, dass sie auf unbestimmte Zeit laufen werden) nicht so cool ist, weil Sie den Schichtungseffekt nicht mehr haben. In diesem Fall können wir es einige Male durchlaufen lassen, bevor wir es löschen.
Shoes.app (:title => 'Circles', :width => 500, :height => 500, :resizable => false) do
# Animation loop
animate (24) do |i|
app.clear if (i % 6 == 0)
# Variables For Randomized Colours
randomCol = rgb((0..255).rand, (0..255).rand, (0..255).rand, (0..255).rand)
randomCol2 = rgb((0..255).rand, (0..255).rand, (0..255).rand, (0..255).rand)
randomCol3 = rgb((0..255).rand, (0..255).rand, (0..255).rand, (0..255).rand)
randomCol4 = rgb((0..255).rand, (0..255).rand, (0..255).rand, (0..255).rand)
background randomCol..randomCol2
fill randomCol3
stroke randomCol4
strokewidth (0..5).rand
# Generate 10 circles per loop cycle
10.times do |i|
i += 1
oval :left => (-5..self.width).rand,
:top => (-5..self.height).rand,
:radius => (1..100).rand
end
end
end
nun eine noch interessante Strategie der letzten n
Pässe zu halten wäre und die älteste zu räumen, so dass wir immer haben, sagen sie, 6 Schichten: In diesem Beispiel wird es jedes sechstes Mal durch löschen auf dem Bildschirm (können variieren finde ich 6 ein guter Cutoff-Punkt zu sein, aber Ihre Meinung (und Leistung des Computers)!):
Shoes.app (:title => 'Circles', :width => 500, :height => 500, :resizable => false) do
n = 6
@layers = []
n.times { @layers << [] }
# Animation loop
animate (24) do |i|
oldest = i % n
# Clear out oldest frame
@layers[oldest].each {|x| x.remove}
@layers[oldest] = []
# Variables For Randomized Colours
randomCol = rgb((0..255).rand, (0..255).rand, (0..255).rand, (0..255).rand)
randomCol2 = rgb((0..255).rand, (0..255).rand, (0..255).rand, (0..255).rand)
randomCol3 = rgb((0..255).rand, (0..255).rand, (0..255).rand, (0..255).rand)
randomCol4 = rgb((0..255).rand, (0..255).rand, (0..255).rand, (0..255).rand)
@layers[oldest] << background(randomCol..randomCol2)
fill randomCol3
stroke randomCol4
strokewidth (0..5).rand
# Generate 10 circles per loop cycle
10.times do |i|
@layers[oldest] << oval (:left => (-5..self.width).rand,
:top => (-5..self.height).rand,
:radius => (1..100).rand)
end
end
end
Wenn Sie die Erzeugung der Kreise steuern mögen, eine Variable hinzu zu zählen, wie Viele wurden produziert und hören dann auf, sie zu produzieren, wenn zu viele erzeugt wurden. –