回复 第9楼 的 谢益辉:
看看我1000秒内鼠标停留在屏幕的位置~
C++ code(Windows only; VS), 以后再写个wx版本的。
<br />
// Curse.cpp : Defines the entry point for the console application.<br />
// 自行加上<><br />
// Win32 application</p>
<p>#include "stdafx.h"<br />
#include windows.h<br />
#include Winuser.h<br />
#include iostream<br />
#include fstream<br />
#include string<br />
using namespace std;</p>
<p>void wait(long seconds)<br />
{<br />
seconds = seconds * 100;<br />
Sleep(seconds);<br />
}</p>
<p>int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
POINT pt; // cursor location<br />
int x;<br />
char tmp;<br />
string ifile;<br />
cout<<"输出文件名(例如 D:/loglog.csv):\t";<br />
cin>>ifile;<br />
warn1: cout<<"监视时间(s):\t";<br />
cin>>x;</p>
<p>if (x>3600) {<br />
cout<<"超过一个小时, 是否继续?(y/N)"<<endl;<br />
cin>>tmp;<br />
if (tmp=='N')<br />
goto warn1;<br />
}<br />
if (x<10) {<br />
cout<<"小于10秒, 是否继续?(y/N)"<<endl;<br />
cin>>tmp;<br />
if (tmp=='N')<br />
goto warn1;<br />
}</p>
<p>ofstream oy(ifile.c_str());<br />
oy<<"\"x\",\"y\"\n";<br />
for (int i=0;i<=10*x;i++){<br />
GetCursorPos(&pt);<br />
oy<<pt.x<<','<<pt.y<<"\n";<br />
wait(1);<br />
}<br />
oy.close();<br />
MessageBoxA(NULL,"文件写入完毕", "Information", MB_OK);<br />
system("pause");<br />
return 0;<br />
}</p>
<p>
</p>
R来画图:
<br />
#这个是rgl的demo(hist3d), 写得挺好的~<br />
library(rgl)<br />
binplot.3d<-function(x,y,z,alpha=1,topcol="#ff0000",sidecol="#aaaaaa")<br />
{<br />
save <- par3d(skipRedraw=TRUE)<br />
on.exit(par3d(save))</p>
<p> x1<-c(rep(c(x[1],x[2],x[2],x[1]),3),rep(x[1],4),rep(x[2],4))<br />
z1<-c(rep(0,4),rep(c(0,0,z,z),4))<br />
y1<-c(y[1],y[1],y[2],y[2],rep(y[1],4),rep(y[2],4),rep(c(y[1],y[2],y[2],y[1]),2))<br />
x2<-c(rep(c(x[1],x[1],x[2],x[2]),2),rep(c(x[1],x[2],rep(x[1],3),rep(x[2],3)),2))<br />
z2<-c(rep(c(0,z),4),rep(0,8),rep(z,8) )<br />
y2<-c(rep(y[1],4),rep(y[2],4),rep(c(rep(y[1],3),rep(y[2],3),y[1],y[2]),2) )<br />
rgl.quads(x1,z1,y1,col=rep(sidecol,each=4),alpha=alpha)<br />
rgl.quads(c(x[1],x[2],x[2],x[1]),rep(z,4),c(y[1],y[1],y[2],y[2]),<br />
col=rep(topcol,each=4),alpha=1)<br />
rgl.lines(x2,z2,y2,col="#000000")<br />
}</p>
<p>hist3d<-function(x,y=NULL,nclass="auto",alpha=1,col="#ff0000",scale=10)<br />
{<br />
save <- par3d(skipRedraw=TRUE)<br />
on.exit(par3d(save))<br />
xy <- xy.coords(x,y)<br />
x <- xy$x<br />
y <- xy$y<br />
n<-length(x)<br />
if (nclass == "auto") { nclass<-ceiling(sqrt(nclass.Sturges(x))) }<br />
breaks.x <- seq(min(x),max(x),length=(nclass+1))<br />
breaks.y <- seq(min(y),max(y),length=(nclass+1))<br />
z<-matrix(0,(nclass),(nclass))<br />
for (i in 1:nclass)<br />
{<br />
for (j in 1:nclass)<br />
{<br />
z[i, j] <- (1/n)*sum(x < breaks.x[i+1] & y < breaks.y[j+1] &<br />
x >= breaks.x[i] & y >= breaks.y[j])<br />
binplot.3d(c(breaks.x[i],breaks.x[i+1]),c(breaks.y[j],breaks.y[j+1]),<br />
scale*z[i,j],alpha=alpha,topcol=col)<br />
}<br />
}<br />
}</p>
<p>################################################################################</p>
<p> rgl.open()</p>
<p> rgl.bg(color="gray")</p>
<p> rgl.light()<br />
mat<-read.csv('D:/loglog.csv',header=T)<br />
hist3d(mat$x,mat$y,alpha=0.4,nclass=6,scale=1000)<br />
</p>
[attachment=218123,1051]