OSDN Git Service

first
[psychlops/cpp.git] / osx / test / bugfix.cpp
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
6
7 ///+ 0 Setup Psychlops Circumstances
8 //// 0 Setup Psychlops Circumstances
9 #include <psychlops.h>
10 using namespace Psychlops;
11 // Psychlops Win32 1.5.5 / 20110927
12 ///- 0 Setup Psychlops Circumstances
13
14 void psychlops_main() {
15         
16         
17         ///+ 1 Declaration /////////////////////////////////////////////////////////////
18         //// 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);
24         
25         double CANVAS_FRAMENUM;
26         int CANVAS_REFRESHRATE;
27         int defaultdotnum = 1500;
28         int dotnum = defaultdotnum;
29         
30         double fieldW=400, fieldH=200;
31         double orientation = PI;
32         double d[128];
33         double maxlifetime = 100;
34         double dotsize = 2;
35         
36         Psychlops::Widgets::Slider wavelength;
37         Psychlops::Widgets::Slider speed;
38         Psychlops::Widgets::Slider angle;
39         Psychlops::Widgets::Slider tf;
40         
41         
42         Psychlops::Interval rng;
43         Psychlops::Matrix position(defaultdotnum,3);
44         
45         Psychlops::Color DEFAULT_BG_COLOR, dotcol;
46         Psychlops::Rectangle dot(dotsize, dotsize);
47         
48         
49         //declare local variables around here
50         
51         ///- 1 Declaration /////////////////////////////////////////////////////////////
52         
53         ///+ 2 Initialization //////////////////////////////////////////////////////////
54         //// 2 Initialization
55         // Set initial values for local variables
56         CANVAS_REFRESHRATE = cnvs.getRefreshRate();
57         CANVAS_FRAMENUM = 0;
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
59         
60         wavelength.set("Lambda", 100<=rng<=300, 10,50);
61 //      wavelength.shift(50,20);
62         wavelength = 150;
63         
64         speed.set("speed", 0<=rng<=2, 0.25,1);
65 //      speed.shift(50,40);
66         speed = 0.25;
67         
68         angle.set("direction", 0<=rng<=360, 30,15);
69 //      angle.shift(50,60);
70         angle = 90;
71         
72         tf.set("TF", 0<=rng<=5, 0.25,1.0);
73 //      tf.shift(50,80);
74         tf = 0.25;
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);
81         }
82         // Offline Movie calculation using Image array around here
83         
84         ///- 2 Initialization //////////////////////////////////////////////////////////
85         
86         ///+ 3 Drawing /////////////////////////////////////////////////////////////////
87         //// 3 Drawing
88         while(!Input::get(Keyboard::esc)) {
89                 cnvs.clear(DEFAULT_BG_COLOR);
90                 
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);
95                         
96                         if(cos(2.0*PI*d[3]/wavelength+2.0*PI*tf*2.0*CANVAS_FRAMENUM/CANVAS_REFRESHRATE)>0){
97                                 d[5] = speed;
98                         }
99                         else{
100                                 d[5] = -speed;
101                         }
102                         
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];
105                         
106                         if(position(dn,3)--<0){
107                                 position(dn,1)=random(fieldW);
108                                 position(dn,2)=random(fieldH);
109                                 position(dn,3)= random(maxlifetime);
110                                 
111                         }
112                         
113                         position(dn,1)=Math::mod(position(dn,1), fieldW);
114                         position(dn,2)=Math::mod(position(dn,2), fieldH);
115                         
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]);}
119                         dot.draw(dotcol);
120                 }
121                 //Write draw commands for realtime figure calculation and drawing around here
122                 
123                 
124                 //Write copy (Draw) commands for rendered movies in section 2 around here
125                 speed.draw();
126                 wavelength.draw();
127                 angle.draw();
128                 tf.draw();
129
130                 cnvs.flip(2);
131                 CANVAS_FRAMENUM++;
132         }
133         
134         ///- 3 Drawing /////////////////////////////////////////////////////////////////
135         
136 }