OSDN Git Service

first
[psychlops/cpp.git] / win32gl / test / newfuncfirm.cpp
1 #include <psychlops.h>
2 using namespace Psychlops;      // Initially developed with Psychlops Win32 1.0.2 / 20080414
3
4 /*
5 class Palette {
6         Color elem[256];
7         Image LUT;
8         Palette() {
9                 LUT.set(523, 1);
10                 const int HEADER[12*3] = {
11                         36,106,133,63,136,163,8,19,138,211,25,46,3,115,164,112,68,9,56,41,49,34,159,208,
12                         0,0,0,0,0,0,0,0,0,0,0,0
13                 };
14                 for(int i=0; i<12; i++) {
15                         LUT.pix(i,0,Color(HEADER[i*3]/255.0, HEADER[i*3+1]/255.0, HEADER[i*3+2]/255.0));
16                 }
17         }
18 };
19
20 */
21
22 const double LOG2E = 1.44269504088896340736;
23 const double SIXSD = 1.15/2;
24 double bind(double x) { return Math::normalDistibution(log(x)*LOG2E, 3, 1); }
25 double bind2(double x) {        return Math::cumulativeNormalDistibution(log(x)*LOG2E, 4, SIXSD); }
26 double bind3(double x) {        return 1-Math::cumulativeNormalDistibution(log(x)*LOG2E, 3, SIXSD); }
27
28 double hoge;
29 AnalogInput *analog;
30 void watcher() {
31         while(true) {
32                 hoge = analog->get();
33                 Prototype::Thread::sleep(1000000);
34         }
35 }
36
37 class RectLuminance : public ExperimentalMethods::Demo {
38     Canvas display;
39     double tf, tmp;
40     int numstim;
41     int orientation;
42
43     Image base;
44     Group gp;
45
46     Letters let;
47     Figures::FunctionalPlot c;
48     Prototype::Thread thread;
49
50     void initialize() {
51         display.set(Canvas::window);
52         c.set(500,500).shift(0,300).centering();
53         c.append(&bind);
54         c.append(&bind2);
55         c.append(&bind3);
56         c.x_max = 50;
57         c.x_min = 0.01;
58         c.y_max = 1;
59         c.y_min = -0.5;
60
61         Interval itv;
62         Independent << tf          | "Temporal Frequency"   | -1.0<=itv<=3.0 |  1 | 0.5 , 1.0;
63         Independent << orientation | "Stimulus Orientation" |  0.0<=itv<=3   |  1 | 1 , 0,1,2,3;
64         Independent << numstim     | "Stimulus Alignment"   |  0.0<=itv<=2   |  1 | 1 , 0;
65
66         Color col;
67
68         base.set(100,100);
69         for(int x=-50; x<50; x++) for(int y=-50; y<50; y++) base.pix(x+50,y+50,col.set(x*x+y*y>50*50? 0.5 : (y+50)/100.0));
70         base.quicken();
71         base.join(gp).centering(gp);
72         gp.centering();
73
74
75                 AnalogOutput *analogout = new Devices::AnalogOutput_NIDAQmxBase();
76                 analogout->put(5);
77                 delete analogout;
78                 analog = new Devices::AnalogInput_NIDAQmxBase();
79                 thread.create(&watcher);
80      }
81
82     void trial() {
83
84         Psychlops::Rectangle mask(102,102);
85         double phase = 0;
86         Color col;
87         while(!Input::get(Keyboard::esc)) {
88             phase = Math::mod(phase+2*PI*pow(2,tf)/display.getRefreshRate(), 2*PI);
89
90             display.clear(Color::gray);
91
92             if(numstim>0) {
93                 for(int x=-1; x<=1; x++ ) {
94                     for(int y=-1; y<=1; y++ ) {
95                         gp.rotation = orientation*90 +180*(cos(phase)<0 ? 1 : 0);
96                         gp.centering().shift(x*102, y*102).draw();
97                         mask.centering(gp);
98                         mask.draw(col.set(.5,.5,.5,sin(phase)*(sin(phase)<0 ? -1 : 1)));
99                     }
100                 }
101             }
102
103             gp.rotation = orientation*90 +180*(cos(phase)<0 ? 1 : 0) + 180*(numstim==2 ? 1 : 0);
104             gp.centering().draw();
105
106             mask.centering(gp);
107             mask.draw(col.set(.5,.5,.5,sin(phase)*(sin(phase)<0 ? -1 : 1)));
108             Display::var(Mouse::x, 300,300);
109             Display::var(Mouse::y, 300,320);
110
111
112                         display.var(Mouse::getWheelDelta().y, 100, 100);
113                         display.var(Mouse::left.pressed(), 100, 120);
114                         display.var(hoge, 100, 140);
115             c.draw();
116             let.centering().draw(Color::red);
117             display.flip();
118         }
119     }
120
121 };
122
123 void psychlops_main() {
124     RectLuminance * exp = new RectLuminance;
125     exp->run();
126     delete exp;
127 }
128
129
130 /*
131 void YamaGraph(const Psychlops::Rectangle &area, const Interval &itvl, double (*func)(double) ) {
132         double xbegin = itvl.begin.value, xend = itvl.end.value, xdiff = xend-xbegin;
133         double x, y, lasty = 0;
134         for(int i=0; i<area.getWidth(); i++) {
135                 x = xbegin + xdiff*i/area.getWidth();
136                 y = 10*func(x);
137                 Display::line(area.getLeft()+i, area.getTop(), area.getLeft()+i, area.getTop()+y, Color::red);
138         }
139 }
140
141 void psychlops_main() {
142         Canvas c(Canvas::window);
143
144         Psychlops::Rectangle area(100,100);
145         area.centering();
146
147         Interval itvl = Interval(0,2*PI);
148         while(!Keyboard::esc.pushed()) {
149                 c.clear();
150                 YamaGraph(area, itvl, &sin);
151                 c.flip();
152         }
153 }
154 */
155
156
157 /*
158 class MotionOfHybridImage : public ExperimentalMethods::Demo {
159         Canvas canvas;
160         double x, y;
161         double a;
162
163         void initialize() {
164                 canvas.set(800,600, Canvas::window, Display::secondary);
165
166                 Interval rng;
167                 Independent << x    | "x"     |  -500<=rng<= 600.0 |  10    |  .0625   , 0;
168                 Independent << y    | "y"     |  -500<=rng<= 600.0 |  10    |  .0625   , 0;
169                 Independent << a    | "a"     |     0<=rng<=   1.0 |  .125  |  .0625  , 0.5;
170
171                 canvas.showFPS();
172                 canvas.watchFPS();
173                 Mouse::show();
174         }
175
176         void trial() {
177                 Psychlops::Rectangle rect(100,100), dot(1,1);
178                 Image img(102,102), full(300,200);
179                 for(int x=0;x<102;x++) { img.pix(x,0,Color::yellow); img.pix(x,101,Color::yellow); }
180                 for(int y=0;y<102;y++) { img.pix(0,y,Color::yellow); img.pix(101,y,Color::yellow); }
181                 //img.quicken();
182                 full.clear();//.shift(2,1).quicken();
183                 dot.shift(0,0);
184
185                 Color gridc(0,.2,0);
186
187                 while(!Keyboard::esc.pushed()) {
188                         canvas.clear(Color::black);
189                         for(int xx=0; xx<canvas.getWidth()/2; xx++)  canvas.line(xx*2, 0,xx*2, canvas.getHeight()-1, gridc);
190                         for(int yy=0; yy<canvas.getHeight()/2; yy++) canvas.line(0, yy*2, canvas.getWidth()-1, yy*2, gridc);
191                         full.draw();
192                         dot.draw(Color::red);
193                         canvas.pix(canvas.getWidth()-1,canvas.getHeight()-1,Color::red);
194
195 //                      rect.centering().shift(x-100,y).draw(Color::red);
196                         img.centering().shift(x-100,y).draw(a);
197
198                         img.centering().shift(x+100,y).draw();
199                         rect.centering().shift(x+100,y).draw(Color::red);
200                         canvas.flip();
201                         //y+=0.001;
202                 }
203         }
204
205 };
206
207
208 void psychlops_main() {
209
210         MotionOfHybridImage *exp = new MotionOfHybridImage;
211         exp->run();
212         delete exp;
213
214 }
215 */
216
217 /*
218
219 #include <psychlops.h>
220 using namespace Psychlops;
221
222
223
224 class GaussianEnvelope : public Image {
225 public:
226         GaussianEnvelope(double sigma) {
227                 Color col;
228
229                 int size = Math::round(sigma*6), halfsize = size/2;
230                 int particle = (halfsize*2 == size) ? 0 : 1;
231                 Image::set(size, size, Image::RGBA);
232
233                 for(int y=-halfsize; y<halfsize+particle; y++) {
234                         for(int x=-halfsize; x<halfsize+particle; x++) {
235                                 alpha(x+halfsize, y+halfsize, gaussian(sigma,x) * gaussian(sigma,y));
236                         }
237                 }
238                 quicken();
239         }
240         double gaussian(double sigma, double x) const {
241                 double factor = ( sigma * sqrt(2*PI) ) / 1.0;
242                 return factor * ( ( 1.0 / ( sigma * ::sqrt(2.0*PI) ) ) * exp( -(x*x) / (2.0*sigma*sigma) ) );
243         }
244 };
245
246
247 void psychlops_main() {
248         Canvas canvas(800,600, Display::list()[1]);
249
250         Image grating(100,100);
251         for(int y=0; y<100; y++) for(int x=0; x<100; x++) grating.pix(x,y,Color(.5+.5*sin(x/10.0)));
252         grating.centering(0,0);
253
254         GaussianEnvelope filter(20);
255         filter.centering();
256         Group group;
257         group.clip(&filter).add(grating).centering();
258
259         while(!Keyboard::esc.pushed()) {
260                 canvas.clear(Color::gray);
261                 group.draw();
262                 canvas.flip();
263         }
264 }
265
266 */