2 using namespace Psychlops;
4 struct GaborVar : public Psychlops::Rectangle {
5 double contrast, wavelength, orientation, phase;
8 void psychlops_main() {
9 //Canvas cnvs(1024,768,Canvas::window);
10 Canvas cnvs(Canvas::fullscreen);
16 Figures::ShaderPlaid *plaid;
17 plaid = new Figures::ShaderPlaid[N];
18 for(int y=0; y<N; y++) {
19 plaid[y].phase = random(2*PI);
20 plaid[y].contrast = random(1.0);
21 plaid[y].wavelength = 5+random(10.0);
22 plaid[y].phase2 = random(2*PI);
23 plaid[y].contrast2 = random(1.0);
24 plaid[y].wavelength2 = 10+random(20.0);
28 GaborVar gaborVar[100];
29 for(int y=0; y<100; y++) {
30 gaborVar[y].contrast = 0.5+random(0.5);
31 gaborVar[y].phase = random(2*PI);
32 gaborVar[y].wavelength = 5+random(10.0);
38 Widgets::Slider slider1, slider2;
39 slider1.link(n1, Interval(-1,10), 1).set(200, 30).centering().shift(-cnvs.getHcenter()/2,0);
40 slider2.link(n2, Interval(-1,1000), 4).set(200, 30).centering().shift(cnvs.getHcenter()/2,0);
42 while(!Keyboard::esc.pushed()) {
43 cnvs.clear(Color::gray);
44 if(slider1.changed()) for(int i=0; i<n1; i++) gaborVar[i].centering(Psychlops::random(cnvs.getWidth()/2), Psychlops::random(cnvs.getHeight())).shift(0, 0);
45 if(slider2.changed()) for(int i=0; i<n2; i++) plaid[i].centering(Psychlops::random(cnvs.getWidth()/2), Psychlops::random(cnvs.getHeight())).shift( cnvs.getWidth()/2, 0);
46 for(int i=0; i<n1; i++) {
47 gaborVar[i].phase += PI/6;
48 gaborVar[i].wavelength = gaborVar[i].wavelength + .5*sin(gaborVar[i].phase);
49 gaborVar[i].orientation = -atan2(gaborVar[i].getCenter().x-cnvs.mouse().x, gaborVar[i].getCenter().y-cnvs.mouse().y);
50 Figures::drawGaborToImage(img, sigma, 1.0/gaborVar[i].wavelength, gaborVar[i].contrast, gaborVar[i].orientation, gaborVar[i].phase);
51 img.centering(gaborVar[i]).draw();
53 for(int i=0; i<n2; i++) {
54 plaid[i].resize(sigma*8, sigma*8);
55 plaid[i].phase += PI/6;
56 plaid[i].wavelength = plaid[i].wavelength + .5*sin(plaid[i].phase);
57 plaid[i].orientation = -atan2(plaid[i].getCenter().x-cnvs.mouse().x, plaid[i].getCenter().y-cnvs.mouse().y);
58 plaid[i].contrast2 = Keyboard::spc.pressed() ? .5 : 0;
59 plaid[i].phase2 += PI/6;
60 plaid[i].wavelength2 = plaid[i].wavelength2 + .5*sin(plaid[i].phase2);
61 plaid[i].orientation2 = -PI/2-atan2(plaid[i].getCenter().x-cnvs.mouse().x, plaid[i].getCenter().y-cnvs.mouse().y);