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
7 IN: ui.gadgets.charts.demos
9 CONSTANT: -pi $[ pi neg ]
11 : sine-wave ( steps -- seq )
13 pi 2 * swap / [ * pi - dup sin 2array ] curry map
14 ${ pi $[ pi sin ] } suffix ;
16 : cosine-wave ( steps -- seq )
18 pi 2 * swap / [ * pi - dup cos 2array ] curry map
19 ${ pi $[ pi cos ] } suffix ;
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
33 : chart-demo ( -- ) 40 (chart-demo) ;
37 ! chart new line new COLOR: blue >>color { { 0 100 } { 100 0 } { 100 50 } { 150 50 } { 200 100 } } >>data add-gadget "Chart" open-window