1 module app; 2 3 import dlangui; 4 import plot2d; 5 6 mixin APP_ENTRY_POINT; 7 8 auto ct() 9 { 10 import std.datetime : Clock; 11 return Clock.currStdTime / 1e7; 12 } 13 14 class PlotWidget : CanvasWidget 15 { 16 Plot plot; 17 DlangUICtx ctx; 18 19 this() 20 { 21 plot = new Plot; 22 plot.settings.minGridStep.x = 80; 23 plot.settings.minGridStep.y = 80; 24 ctx = new DlangUICtx; 25 26 auto mf(float i) { return sin(i*sin(i+ct()*0.5)*PI*2); } 27 auto tre = iota(-2, 2.02, 0.02) 28 .map!(i=>TreStat(i, mf(i) + 0.4 + sin(i*PI*2+ct*3) * 0.3, 29 mf(i), mf(i) - 0.4 - sin(i*PI*2+ct*5) * 0.3)); 30 31 plot.add(new TreChart( 32 PColor(0,0.5,0,0.8), 33 34 PColor(1,1,0,.3), 35 PColor(1,1,0,.2), 36 37 PColor(0,1,1,.3), 38 PColor(0,1,1,.2), 39 (ref Appender!(TreStat[]) buf) { buf.put(tre.save); } 40 )); 41 42 plot.settings.viewport = Viewport(DimSeg(-2,2), DimSeg(-1, 2)); 43 plot.settings.autoFit = false; 44 plot.settings.padding = Border(0); 45 } 46 47 override void doDraw(DrawBuf buf, Rect rc) 48 { 49 buf.fillRect(rc, 0xaaaaaa); 50 auto _ = ctx.set(buf); 51 plot.updateCharts(); 52 plot.draw(ctx, PPoint(this.width, this.height)); 53 } 54 } 55 56 extern (C) int UIAppMain(string[] args) 57 { 58 Window window = Platform.instance.createWindow( 59 "example", null, WindowFlag.Resizable, 1000, 600); 60 61 window.mainWidget = new PlotWidget(); 62 63 window.show(); 64 65 return Platform.instance.enterMessageLoop(); 66 }