Unix:像Mathematica一样让鼠标坐在X上?

hhh*_*hhh 2 python language-agnostic x11 wolfram-mathematica r

数学

DynamicModule[{list = {}}, 
 EventHandler[
  Dynamic[Framed@
    Graphics[{BSplineCurve[list], Red, Line[list], Point[list]}, 
     PlotRange -> 2]], {{"MouseClicked", 
     1} :> {AppendTo[list, 
      MousePosition["Graphics"]]}}, {"MouseClicked", 2} :> 
   Print[list]]]
Run Code Online (Sandbox Code Playgroud)

我想在家里做上面没有Mathematica.使用你想要的任何工具,我喜欢使用Python和R,但对任何候选解决方案都很满意.我想到的第一件事是RStudio和这个问题,但我不确定是否有更好的方法来做到这一点.

如何通过X进行交互式GUI创新?

Mathematica -snippet的程序概述

1. you click points

2. you will see BSplineCurve formating between the points and points are red

3. points are saved to an array

4. when finished, you click `right-mouse-button` so array to stdout
Run Code Online (Sandbox Code Playgroud)

Gre*_*now 5

这是一个R函数,可以执行您所描述的内容:

dynmodfunc <- function() {
    plot(0:1,0:1,ann=FALSE,type='n')
    mypoints <- matrix(ncol=2, nrow=0)
    while( length(p <- locator(1, type='p', col='red')) ) {
        mypoints <- rbind(mypoints, unlist(p))
        plot(mypoints, col='red', ann=FALSE, xlim=0:1, ylim=0:1)
        if(nrow(mypoints)>1) {
            xspline(mypoints, shape=-1)
        }
    }
    mypoints
}

(out <- dynmodfunc())
Run Code Online (Sandbox Code Playgroud)

您可以更改shape参数以xspline更改样条曲线的样式.此版本返回带有x和y值的2列矩阵,但如果愿意,可以将其更改为其他结构.还有很多其他东西也可以自定义.

添加了将输出粘贴到Mathematica中的函数:

matrix2mathematica <- function(x) {
    paste0( '{', 
        paste0( '{', x[,1], ', ', x[,2], '}', collapse=', '),
    '}')
}

cat( matrix2mathematica(out))
Run Code Online (Sandbox Code Playgroud)