library(tcltk) n<-50 set.seed(101) x<-rnorm(n) x[15]<- -x[14] y<-0.4*x + 0.1*rnorm(n,0,2) y[14]<-0.4*x[14] y[15]<--y[14] x[1]<-max(x) grafica<-function(...){theta=as.numeric(tclvalue(SliderValue)); plot(x,y,ylim=c(-3,3),xlim=c(-3,3),pch=19); #points(cos(theta)*x +sin(theta)*y,rep(-1,n),pch=19,col="red"); points(0,0,pch=19) abline(a=0,b=tan(theta),col="red",lwd=2) points(cos(theta)*x +sin(theta)*y,rep(-3,n),pch=19,col="red",) points(x[1],y[1],col="blue",pch=19,cex=1.5) points(x[15],y[15],col="green",pch=19) points(x[14],y[14],col="green",pch=19) xp1<-cos(theta)*(cos(theta)*x[1] +sin(theta)*y[1]); yp1<-sin(theta)*(cos(theta)*x[1] +sin(theta)*y[1]) lines(c(x[1],xp1),c(y[1],yp1),col="green") points(xp1,yp1,pch=19,col="red",cex=1.5); points(cos(theta)*x[1] +sin(theta)*y[1],-3,pch=19,col="blue",cex=1.5) points(cos(theta)*x[15] +sin(theta)*y[15],-3,pch=19,col="green") points(cos(theta)*x[14] +sin(theta)*y[14],-3,pch=19,col="green") } sliderinicio=-0.999; slidermin=-1; slidermax=1.95; sliderstep=0.01 tt <- tktoplevel() SliderValue <- tclVar(sliderinicio) SliderValueLabel <- tklabel(tt,text=as.character(tclvalue(SliderValue))) tkgrid(tklabel(tt,text="Slider Value : "),SliderValueLabel,tklabel(tt,text="angulo")) tkconfigure(SliderValueLabel,textvariable=SliderValue) slider <- tkscale(tt, from=slidermin, to=slidermax, showvalue=F, variable=SliderValue, resolution=sliderstep, command=grafica) tkgrid(slider) tkfocus(tt)