1 //Psychlops Code Template
2 // Please visit following web site to get sample codes.
3 // http://psychlops.sourceforge.jp/ja/?StartCode
4 // CodeDresser at following address is also available to view the code.
5 // http://visitope.org/Tools/codedresser.html
7 ///+ 0 Setup Psychlops Circumstances
8 //// 0 Setup Psychlops Circumstances
10 using namespace Psychlops;
11 // Psychlops Win32 1.5.5 / 20110927
12 ///- 0 Setup Psychlops Circumstances
14 void psychlops_main() {
17 ///+ 1 Declaration /////////////////////////////////////////////////////////////
19 // declare default window and variables for its parameters
20 //Psychlops::Rectangle cnvsrect(800,600);
21 //cnvsrect.centering(((Display)Display::secondary).getCenter());
22 //Canvas cnvs(cnvsrect);
23 Canvas cnvs(Canvas::window);
25 double CANVAS_FRAMENUM;
26 int CANVAS_REFRESHRATE;
27 int defaultdotnum = 1500;
28 int dotnum = defaultdotnum;
30 double fieldW=400, fieldH=200;
31 double orientation = PI;
33 double maxlifetime = 100;
36 Psychlops::Widgets::Slider wavelength;
37 Psychlops::Widgets::Slider speed;
38 Psychlops::Widgets::Slider angle;
39 Psychlops::Widgets::Slider tf;
42 Psychlops::Interval rng;
43 Psychlops::Matrix position(defaultdotnum,3);
45 Psychlops::Color DEFAULT_BG_COLOR, dotcol;
46 Psychlops::Rectangle dot(dotsize, dotsize);
49 //declare local variables around here
51 ///- 1 Declaration /////////////////////////////////////////////////////////////
53 ///+ 2 Initialization //////////////////////////////////////////////////////////
55 // Set initial values for local variables
56 CANVAS_REFRESHRATE = cnvs.getRefreshRate();
58 DEFAULT_BG_COLOR.set(127.0/255.0,127.0/255.0,127.0/255.0,1.0); // default background color is 127/255 mid-gray
60 wavelength.set("Lambda", 100<=rng<=300, 10,50);
61 // wavelength.shift(50,20);
64 speed.set("speed", 0<=rng<=2, 0.25,1);
65 // speed.shift(50,40);
68 angle.set("direction", 0<=rng<=360, 30,15);
69 // angle.shift(50,60);
72 tf.set("TF", 0<=rng<=5, 0.25,1.0);
75 // Draw Offline images around here
76 for(int i=0; i<dotnum; i++){
77 position(i,1)=random(fieldW);
78 position(i,2)=random(fieldH);
79 position(i,3)= random(maxlifetime);
80 position(i,4)= random(1.0);
82 // Offline Movie calculation using Image array around here
84 ///- 2 Initialization //////////////////////////////////////////////////////////
86 ///+ 3 Drawing /////////////////////////////////////////////////////////////////
88 while(!Input::get(Keyboard::esc)) {
89 cnvs.clear(DEFAULT_BG_COLOR);
91 for(int dn=0; dn<dotnum; dn++){
92 d[1] = position(dn,1);
93 d[2] = position(dn,2);
94 d[3] = d[1]*cos(orientation)-d[2]*sin(orientation);
96 if(cos(2.0*PI*d[3]/wavelength+2.0*PI*tf*2.0*CANVAS_FRAMENUM/CANVAS_REFRESHRATE)>0){
103 position(dn,1) = position(dn,1) + cos(angle*180.0/PI) * d[5];
104 position(dn,2) = position(dn,2) + sin(angle*180.0/PI) * d[5];
106 if(position(dn,3)--<0){
107 position(dn,1)=random(fieldW);
108 position(dn,2)=random(fieldH);
109 position(dn,3)= random(maxlifetime);
113 position(dn,1)=Math::mod(position(dn,1), fieldW);
114 position(dn,2)=Math::mod(position(dn,2), fieldH);
116 dot.centering().shift(-fieldW*0.5+position(dn,1), -fieldH*0.5 + position(dn,2));
117 if(Keyboard::up.pressed()){if(d[5]>0)dotcol.set(0.5,0.0,0.0); else dotcol.set(0.0,0.5,0.0);}
118 else {d[6]= 1.0; dotcol.set(d[6],d[6],d[6]);}
121 //Write draw commands for realtime figure calculation and drawing around here
124 //Write copy (Draw) commands for rendered movies in section 2 around here
134 ///- 3 Drawing /////////////////////////////////////////////////////////////////