]> gitweb.factorcode.org Git - factor.git/blob - extra/ui/gadgets/charts/demos/demos.factor
core: Rename iota to <iota> so we can have TUPLE: iota ... ; instead of TUPLE: iota...
[factor.git] / extra / ui / gadgets / charts / demos / demos.factor
1 ! Copyright (C) 2017 Alexander Ilin.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays colors.constants kernel literals locals
4 math math.constants math.functions sequences ui ui.gadgets
5 ui.gadgets.charts ui.gadgets.charts.axes ui.gadgets.charts.lines
6 ;
7 IN: ui.gadgets.charts.demos
8
9 CONSTANT: -pi $[ pi neg ]
10
11 : sine-wave ( steps -- seq )
12     [ <iota> ] keep
13     pi 2 * swap / [ * pi - dup sin 2array ] curry map
14     ${ pi $[ pi sin ] } suffix ;
15
16 : cosine-wave ( steps -- seq )
17     [ <iota> ] keep
18     pi 2 * swap / [ * pi - dup cos 2array ] curry map
19     ${ pi $[ pi cos ] } suffix ;
20
21 <PRIVATE
22
23 :: (chart-demo) ( n -- )
24     chart new ${ ${ -pi pi } { -1 1 } } >>axes
25     line new COLOR: blue >>color n sine-wave >>data add-gadget
26     line new COLOR: red >>color n cosine-wave >>data add-gadget
27     vertical-axis new add-gadget
28     horizontal-axis new add-gadget
29     "Chart" open-window ;
30
31 PRIVATE>
32
33 : chart-demo ( -- ) 40 (chart-demo) ;
34
35 MAIN: chart-demo
36
37 ! chart new line new COLOR: blue >>color { { 0 100 } { 100 0 } { 100 50 } { 150 50 } { 200 100 } } >>data add-gadget "Chart" open-window