OSDN Git Service

cache
[psychlops/cpp.git] / test / main.cpp
1 #include <psychlops.h>
2 using namespace Psychlops;
3
4 void psychlops_main() {
5         Canvas cnvs(Canvas::window);\r
6 \r
7         Font font(L"MS P Gothic", 32);\r
8         Letters let(L"hoge", font);\r
9         let._zoom_cache = true;\r
10 \r
11         Clock after, before;\r
12         after.update();\r
13 \r
14         while(!Keyboard::esc.pushed()) {\r
15         before = after;\r
16         after.update();\r
17 \r
18         cnvs.clear();\r
19 \r
20         font.size = random(100);\r
21         //let.setFont(font);\r
22         let.font = font;\r
23         let.centering().draw(Color::white);\r
24 \r
25         cnvs.var((after-before).at_msec(), 100,100, Color::green);\r
26 \r
27         cnvs.flip();\r
28         }
29 }
30 \r
31 /*
32 #include <psychlops.h>
33 using namespace Psychlops;
34
35
36 class RectLuminance : public ExperimentalMethods::Demo {
37         Canvas display;
38         double bg_lum, x;
39 //      Widgets::SequentialScreenshot sc;
40         Gabor *gabor;
41         Psychlops::Rectangle rect;
42         FigureGroupe g;
43         Figures::Cross xr;
44         Figures::Arrow arr;
45
46         void initialize() {
47                 display.set(Canvas::window);
48                 gabor = new QuickGabor(10.0, 10.0, 1.0);
49                 g.add(rect);
50                 rect.set(100, 100).centering(0,0);
51                 xr.set(100,100).shift(200,200);
52                 xr.brush = Stroke(Color::red, 2, Stroke::SOLID);
53                 g.shift(100,0);
54                 g.rotation = -5;
55                 arr.centering();
56                 arr.vec = Psychlops::Point(100,50);
57
58                 Interval itv;
59                 Independent << bg_lum    | "BG Luminance"   | 0.0<=itv<=4095 |  128 | 1 , 1;
60                 Independent << x         | "X"              | 0.0<=itv<=4095 |  128 | 1 , 1;
61         }
62
63         void trial() {
64                 Letters let(L"hoge");
65                 while(!Input::get(Keyboard::esc)) {
66                         display.clear(Color(bg_lum/4095));
67                         (*gabor).centering().draw();
68                         let.centering();
69                         let.draw(Color::red);
70                         g.draw(Color::red);
71                         arr.vec.x -= 1;
72                         arr.draw(Color::white);
73                         if(Mouse::left.pressed()) display.var(Mouse::x, 100,100);
74
75                         display.flip();
76                 }
77         }
78
79 };
80
81
82 void psychlops_main() {
83         RectLuminance * exp = new RectLuminance;
84         exp->run();
85         delete exp;
86 }
87 */
88
89
90
91 /*
92 #include <psychlops.h>
93 using namespace Psychlops;
94
95
96 const int DIVISION_MODES = 5;
97 const int MIN_DIVISION_MODES = 5;
98 const double SIGMA_MAGN = 6.0;
99
100 void GaborChart() {
101
102         Canvas display(Canvas::window);
103         int div = 5, divarr;
104
105         double size_whole= 400.0, wl = 30.0;
106         double contrast = 0.5, ori = 0.0, velocity = 15.0;
107         int velmode = 1;
108
109         Range rng;
110         Independent << div      | "Division"      |      5<=rng<=9     |  1   | 1   ;
111         Independent << wl       | "Wavelength"    |   30.0<=rng<=60.0  |  5.0 | 1.0 ;
112         Independent << contrast | "Contrast"      |      0<=rng<=1.0   |  0.1 | 0.01;
113         Independent << velocity | "Velocity"      |  -90.0<=rng<=90.0  | 15.0 | 1.0 ;
114         Independent << velmode  | "Velocity Mode" |      0<=rng<=1     |  1   | 1   ;
115         Independent << ori      | "Orientation"   | -360.0<=rng<=720.0 | 30.0 | 15.0;
116         double each_size;
117
118         //Formatting and (re)locating Gabors
119         QuickGabor gabor[DIVISION_MODES][DIVISION_MODES+MIN_DIVISION_MODES][DIVISION_MODES+MIN_DIVISION_MODES];
120         for(int divs=0, divs_really=0; divs<DIVISION_MODES; divs++) {
121                 divs_really = MIN_DIVISION_MODES+divs;
122                 for(int x=0; x<DIVISION_MODES+MIN_DIVISION_MODES; x++) {
123                         for(int y=0; y<DIVISION_MODES+MIN_DIVISION_MODES; y++) {
124                                 each_size = size_whole/divs_really;
125                                 gabor[divs][x][y].set((wl/(divs_really-y+1)), each_size/SIGMA_MAGN).centering().shift(each_size*((x+0.5)-(divs_really/2.0)), each_size*(divs_really/2.0-(y+0.5)));
126                                 gabor[divs][x][y].phase = Psychlops::random(360);
127                         }
128                 }
129         }
130
131         //Run Movie
132         display.showFPS();
133         display.watchFPS();
134         while(!Input::get(Keyboard::esc)) {
135                 Display::clear(Color::gray);
136                 divarr = div-MIN_DIVISION_MODES;
137
138                 for(int x=0; x<div; x++) {
139                         for(int y=0; y<div; y++) {
140                                 if(ori>360.0) ori -=360.0; if(ori<0.0) ori+=360.0;
141
142                                 //Set Gabor parameters
143                                 gabor[divarr][x][y].wavelength  = wl / pow(4.0/3.0, y);
144                                 gabor[divarr][x][y].contrast    = contrast;
145                                 gabor[divarr][x][y].orientation = ori;
146                                 if(velmode) {
147                                         gabor[divarr][x][y].phase += velocity * (1.0*x/div);
148                                 } else {
149                                         gabor[divarr][x][y].phase += velocity / gabor[divarr][x][y].wavelength * (1.0*x/div) * 20;
150                                 }
151
152                                 //Drawing Gabors
153                                 gabor[divarr][x][y].draw();
154                         }
155                 }
156
157                 Display::flip();
158         }
159
160 }
161
162 void psychlops_main()
163 {
164         Procedure p;
165         p.setDesign(Procedure::DEMO);
166         p.setProcedure(&GaborChart);
167         p.run();
168 }
169 */
170
171 /*
172 #include <psychlops.h>
173 using namespace Psychlops;      // Initially developed with Psychlops Win32 1.0.2 / 20080414
174
175
176
177 void RectLuminance() {
178         Canvas display(1024, 768, Canvas::window, Display::secondary);
179         display.showFPS();
180         display.watchFPS();
181
182         double rect_size = 100;
183         double rect_lum  = 0.5;
184         double bg_lum    = 0.2;
185
186         Psychlops::Rectangle rect(rect_size,rect_size);
187         rect.centering();
188
189         Range rng;
190         Independent << rect_size | "Rect Size"      |   1< rng< 500 | 10.0 | 2.0 ;
191         Independent << rect_lum  | "Rect Luminance" | 0.0<=rng<=1.0 |  0.1 | 0.05;
192         Independent << bg_lum    | "BG Luminance"   | 0.0<=rng<=1.0 |  0.1 | 0.05;
193         Psychlops::Rectangle drawee(100,100);
194
195         Clock before, after;
196         while(!Input::get(Keyboard::esc)) {
197                 Display::clear(bg_lum);
198                 rect.resize(rect_size,rect_size).draw(rect_lum);
199                 after.update();
200                 display.var((after-before).at_msec(), 100,100, Color::green);
201                 if(Independent[&rect_lum].changed()) display.var((after-before).at_msec(), 100,200, Color::green);
202                 drawee.centering().shift(Psychlops::random(100),0).draw(Color::black);
203                 Display::flip();
204         }
205
206 }
207
208
209 void psychlops_main() {
210         Procedure p;
211         p.setDesign(Procedure::DEMO);
212         p.setProcedure(RectLuminance);
213         p.run();
214
215 }
216 */