GIFReader.st
changeset 3283 e32b39c8647f
parent 3282 57d0f3cef4ef
child 3284 b2302e748434
--- a/GIFReader.st	Fri Feb 14 01:23:38 2014 +0100
+++ b/GIFReader.st	Fri Feb 14 01:27:40 2014 +0100
@@ -71,6 +71,80 @@
     [author:]
         Claus Gittinger
 "
+!
+
+examples
+"
+    saving an animated gif sequence:
+
+     a view showing rainfall:
+                                                                                [exBegin] 
+    |BG CLR N1 H W v drops gen gen1 buffer|
+
+    BG := Color black.
+    CLR := Color blue lightened.
+    H := 100.
+    W := 100.
+    N1 := 10.
+    WIND := 0.
+    drops := OrderedCollection new.
+
+    gen := [:n | ((1 to:n) collect:[:i | Random nextIntegerBetween:1 and:W] as:Set) collect:[:x | x@0]].
+    newDrops := [drops addAll:(gen value:N1)].
+    draw := [buffer fill:BG; paint:CLR. drops do:[:d | buffer displayPoint:d]].
+    remove := [drops := drops reject:[:d | d y > H]].
+    move := [:wind | drops := drops collect:[:d| (d x + wind)\\W @ (d y + 1)]].
+    v := View new openAndWait.
+    buffer := Form extent:(v extent) depth:24 onDevice:v device.
+
+    [
+        [v shown] whileTrue:[
+            draw value.
+            v displayForm:buffer.
+            move value:WIND.
+            remove value.
+            newDrops value.
+            WIND := (WIND+(Random nextBetween:-1 and:1)) clampBetween:-5 and:5.
+            Delay waitForSeconds:0.1.
+        ]
+    ] fork.
+                                                                                [exEnd]
+
+   saving those images:
+                                                                                [exBegin] 
+    |seq img BG CLR N1 H W v drops gen gen1 buffer|
+
+    BG := Color black.
+    CLR := Color blue lightened.
+    H := 100.
+    W := 100.
+    N1 := 10.
+    WIND := 0.
+    drops := OrderedCollection new.
+
+    gen := [:n | ((1 to:n) collect:[:i | Random nextIntegerBetween:1 and:W] as:Set) collect:[:x | x@0]].
+    newDrops := [drops addAll:(gen value:N1)].
+    draw := [buffer fill:BG; paint:CLR. drops do:[:d | buffer displayPoint:d]].
+    remove := [drops := drops reject:[:d | d y > H]].
+    move := [:wind | drops := drops collect:[:d| (d x + wind)\\W @ (d y + 1)]].
+    buffer := Form extent:W@H depth:8 onDevice:Display.
+
+    seq := OrderedCollection new.
+    500 timesRepeat:[
+        move value:WIND.
+        remove value.
+        newDrops value.
+        draw value.
+        seq add:(ImageFrame new delay:100; image:(Depth8Image fromForm:buffer)).
+        WIND := (WIND+(Random nextBetween:-1 and:1)) clampBetween:-5 and:5.
+    ].
+
+    img := seq first image.
+    img imageSequence:(seq copyFrom:2).
+    img imageSequence do:[:each | each image colorMap:img colorMap].
+    GIFReader save:img onFile:'/tmp/img.gif'
+                                                                                [exEnd]
+"
 ! !
 
 !GIFReader class methodsFor:'initialization'!
@@ -1010,11 +1084,11 @@
 !GIFReader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.102 2014-02-14 00:23:38 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.103 2014-02-14 00:27:40 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.102 2014-02-14 00:23:38 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.103 2014-02-14 00:27:40 cg Exp $'
 ! !