【问题标题】:Racket Real Time Plot/Chart球拍实时图/图表
【发布时间】:2016-06-01 05:06:54
【问题描述】:
【问题讨论】:
标签:
plot
graph
charts
racket
real-time-updates
【解决方案1】:
在深入研究 Rackets OOP 和 gui 库后,我最终发现(并理解)了 plot/dc,文档声称可以将其用于此类应用程序:https://docs.racket-lang.org/plot/plotting.html?q=plot%2Fdc#%28def._%28%28lib._plot%2Fmain..rkt%29._plot%2Fdc%29%29
在渲染时它似乎比动画画布效果更好,但我仍然需要重新实现缩放和点击以及 snip%s 附带的所有东西,除非有人有更好的想法。
#lang racket
(require racket/gui plot racket/draw)
(define num 0)
(define f (new frame% [label "Test graph"]
[width 200]
[height 200]))
(define c (new canvas% [parent f]))
(send f show #t)
(define (loop)
(set! num (add1 num))
(plot/dc (function sin (- pi) num)
(send c get-dc)
0 0
(- (send f get-width) 40) ;; figure out how to get the actual size of the text outside the graphs boarder?
(- (send f get-height) 40)
#:title "Graph"
#:x-label "num"
#:y-label "sin"
)
(sleep/yield .2)
(loop))
(loop)