OSDN Git Service

first
[psychlops/cpp.git] / win32gl / test / shader / ShaderPlaidsBench.cpp
1 #include <psychlops.h>
2 using namespace Psychlops;
3
4 void psychlops_main() {
5         Canvas cnvs(1024,768,Canvas::window);
6         //Canvas cnvs(Canvas::fullscreen);
7         cnvs.watchFPS();
8         cnvs.showFPS();
9         Mouse::show();
10
11         const int N = 2500;
12         Figures::ShaderGaborAlpha *plaid;
13         plaid = new Figures::ShaderGaborAlpha[N];
14         for(int y=0; y<N; y++) {
15                 plaid[y].phase = random(2*PI);
16                 plaid[y].contrast = random(0.5);
17                 plaid[y].wavelength = 5+random(10.0);
18 //              plaid[y].phase2 = random(2*PI);
19 //              plaid[y].contrast2 = random(0.5);
20 //              plaid[y].wavelength2 = 10+random(20.0);
21         }
22
23         double sigma = 6.0;
24         int n = 100.0;
25         Widgets::Dial dial;
26         dial.link(sigma, 2).set(50).shift(100,100);
27         Widgets::Slider slider;
28         slider.link(n, Interval(0,2500), 4).set(200, 30).centering();
29
30         while(!Keyboard::esc.pushed()) {
31                 cnvs.clear(Color::gray);
32                 if(slider.changed()) for(int i=0; i<n; i++) plaid[i].centering(Psychlops::random(cnvs.getWidth()), Psychlops::random(cnvs.getHeight()));
33                 for(int i=0; i<n; i++) {
34                         plaid[i].resize(sigma*8, sigma*8);
35                         plaid[i].phase += PI/6;
36                         plaid[i].wavelength = plaid[i].wavelength + .5*sin(plaid[i].phase);
37                         plaid[i].orientation = -atan2(plaid[i].getCenter().x-cnvs.mouse().x, plaid[i].getCenter().y-cnvs.mouse().y);
38 //                      plaid[i].phase2 += PI/6;
39 //                      plaid[i].wavelength2 = plaid[i].wavelength2 + .5*sin(plaid[i].phase2);
40 //                      plaid[i].orientation2 = -PI/2-atan2(plaid[i].getCenter().x-cnvs.mouse().x, plaid[i].getCenter().y-cnvs.mouse().y);\r
41                         plaid[i].alpha = 0.5;
42                         plaid[i].draw();
43                 }
44                 dial.draw();
45                 slider.draw();
46                 cnvs.var(sigma*8, dial.getDatum().x, dial.getDatum().y);
47                 cnvs.var(n, slider.getDatum().x, slider.getDatum().y);
48                 cnvs.var(pow(floor(sigma), 2)*n, 200, 50, Color::green);
49                 cnvs.flip();
50         }
51         delete [] plaid;
52 }
53