A Data Science Central Community
This is a follow up to our article on Structuredness coefficient to find patterns and associations, featuring an image (animated gif) with rotating dots that simulate waves. I went one step further here, to create a new data video, where rotating points (by accident) simulate sensual waves, not unlike belly dancing. You'll understand what I mean when you see the video.
Here I provide the source code and methodology to create this video. Click here to view the video, including a link to the YouTube version.
1. Algorithm to create the data
The video features a rectangle with 20 x 20 moving points, initially evenly spaced, each point rotating around an invisible circle.
Here's the algorithm:
The parameter c governs the speed of the rotations, and r the radius of the underlying circles.
open(OUT,">movie.txt");
print OUT "iter\tx\ty\tz\n";
for ($iter=0; $iter<1000; $iter++) {
for ($k=0; $k<20; $k++) {
for ($l=0; $l<20; $l++) {
$r=0.50;
$c=(($k+$l)%81)/200;
$color=2.4*$c;
$pi=3.14159265358979323846264;
$x=$k+$r*sin($c*$pi*$iter);
$y=$l+$r*cos($c*$pi*$iter);
print OUT "$iter\t$x\t$y\t$color\n";
}
}
}
close(OUT);
2. Source code to produce the video
Here's the R source code. The input data is the file movie.txt produced in the previous step. Note that $iter represents the frame number in the video. Here I used 1,000 frames and the video lasts about 60 seconds.
vv<-read.table("c:/vincentg/movie.txt",header=TRUE);
iter<-vv$iter;
for (n in 0:999) {
x<-vv$x[iter == n];
y<-vv$y[iter == n];
z<-vv$z[iter == n];
plot(x,y,xlim=c(3,17),ylim=c(3,17),pch=20,cex=1,col=rgb(0,0,z),xlab="",ylab="",axes=TRUE);
Sys.sleep(0.01); # sleep 0.05 second between each iteration
}
3. Saving and exporting the video
I used a screen-cast software (Active Presenter, open source) to do the job. It's the same as as screen shot software or print screen, except that instead of saving a static image, it saves streaming data. Click here for details.
Related articles
Comment
© 2019 AnalyticBridge.com is a subsidiary and dedicated channel of Data Science Central LLC Powered by
Badges | Report an Issue | Privacy Policy | Terms of Service
You need to be a member of AnalyticBridge to add comments!
Join AnalyticBridge