OSDN Git Service

first
[psychlops/cpp.git] / osx / test / Shader / ShaderPlaidsBench.cpp
1 #include <psychlops.h>
2 using namespace Psychlops;
3
4 void psychlops_main() {
5         //      Canvas cnvs(800,600,Canvas::window);
6         Canvas cnvs(Canvas::fullscreen, Display::secondary);
7         cnvs.watchFPS();
8         cnvs.showFPS();
9 //      Mouse::show();
10
11         const int N = 2500;
12         Figures::ShaderPlaid *plaid;
13         plaid = new Figures::ShaderPlaid[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 = 300.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         Rectangle mouse_cur(10,10);
30
31         while(!Keyboard::esc.pushed()) {
32                 cnvs.clear(Color::gray);
33                 //dial.draw();
34                 slider.draw();
35                 if(slider.changed()) for(int i=0; i<n; i++) plaid[i].centering(Psychlops::random(cnvs.getWidth()), Psychlops::random(cnvs.getHeight()));
36                 for(int i=0; i<n; i++) {
37                         plaid[i].resize(sigma*8, sigma*8);
38                         plaid[i].phase += PI/6;
39                         plaid[i].wavelength = plaid[i].wavelength + .5*sin(plaid[i].phase);
40                         plaid[i].orientation = -atan2(plaid[i].getCenter().x-cnvs.mouse().x, plaid[i].getCenter().y-cnvs.mouse().y);
41                         plaid[i].phase2 += PI/6;
42                         plaid[i].wavelength2 = plaid[i].wavelength2 + .5*sin(plaid[i].phase2);
43                         plaid[i].orientation2 = PI/2-atan2(plaid[i].getCenter().x-cnvs.mouse().x, plaid[i].getCenter().y-cnvs.mouse().y);
44                         plaid[i].draw();
45                 }
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*8), 2)*n, 200, 50, Color::green);
49                 mouse_cur.centering(cnvs.mouse()).draw(Color::red);
50                 cnvs.flip();
51         }
52         delete [] plaid;
53 }
54