]> gitweb.factorcode.org Git - factor.git/commitdiff
charts.demo: add a red cosine wave to the demo chart
authorAlexander Iljin <ajsoft@yandex.ru>
Sun, 22 Jan 2017 19:30:56 +0000 (22:30 +0300)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 17 Apr 2017 20:54:51 +0000 (13:54 -0700)
demos/demos.factor

index 24ba490f5a73cb604860365a9d80db3f88bd4cd9..7555891ddadaf3be54679f56f976b7ab3d194051 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2017 Alexander Ilin.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays charts charts.lines colors.constants
-kernel literals math math.constants math.functions sequences ui
-ui.gadgets ;
+kernel literals locals math math.constants math.functions
+sequences ui ui.gadgets ;
 IN: charts.demos
 
 CONSTANT: -pi $[ pi neg ]
@@ -12,10 +12,22 @@ CONSTANT: -pi $[ pi neg ]
     pi 2 * swap / [ * pi - dup sin 2array ] curry map
     ${ pi $[ pi sin ] } suffix ;
 
-: chart-demo ( -- )
+: cosine-wave ( steps -- seq )
+    [ iota ] keep
+    pi 2 * swap / [ * pi - dup cos 2array ] curry map
+    ${ pi $[ pi cos ] } suffix ;
+
+<PRIVATE
+
+:: (chart-demo) ( n -- )
     chart new ${ ${ -pi pi } { -1 1 } } >>axes
-    line new COLOR: blue >>color 40 sine-wave >>data
-    add-gadget "Chart" open-window ;
+    line new COLOR: blue >>color n sine-wave >>data add-gadget
+    line new COLOR: red >>color n cosine-wave >>data add-gadget
+    "Chart" open-window ;
+
+PRIVATE>
+
+: chart-demo ( -- ) 40 (chart-demo) ;
 
 MAIN: chart-demo