OSDN Git Service

first
[psychlops/cpp.git] / win32gl / test / bugfix.cpp
1 #include <psychlops.h>
2 using namespace Psychlops;      // Initially developed with Psychlops Win32 1.0.2 / 20080414
3 /*
4 void drawGaussianFilter(Image &img, double sigma, double factor)
5 {
6         img.release();
7         img.set(sigma*8, sigma*8, Image::RGBA);
8         const int width = img.getWidth(), height = img.getHeight();
9         double xp, yp, r, r2;
10         for(int y=0; y<height; y++) {
11                 yp = y-height/2.0;
12                 for(int x=0; x<width; x++) {
13                         xp = x-width/2.0;
14                         r = sqrt(xp*xp+yp*yp);
15                         r2 = -(r*r) / (2.0*sigma*sigma);
16                         img.alpha(x,y,factor*(exp(r2)));
17                 }
18         }
19 }
20
21 void psychlops_main() {
22         Canvas cnvs(1024,768,Canvas::window);
23
24         Group gr;
25
26         // Attach filter to Group
27         Image filter;
28         drawGaussianFilter( filter, 100, 1 );
29         filter.centering(0,0);
30         gr.clip(&filter);
31
32         // Append 'filtered' Figures
33         Psychlops::Rectangle dot[100];
34         for(int i=0; i<100; i++) {
35                 dot[i].fill = Color::white;
36                 dot[i].set(5,5).centering(random(-300,300),random(-300,300)).join(gr);
37         }
38
39         cnvs.clear();
40         gr.centering().draw();
41         cnvs.flip();
42
43         while(!Keyboard::esc.pushed()) {}
44
45 }
46 */
47
48 const double E = 2.718281828459045;
49 const double LOG2E = 1.44269504088896340736;
50 double sigmoid(double x, double d, double a) { return 1 / ( 1 + pow(E, -(a*(x-d))) ); }
51 double log2NormalDistibution(double log_x, double octave_mu, double octave_sigma) { return Math::normalDistibution(log(log_x)*LOG2E, octave_mu, octave_sigma); }
52 double cumulativeLog2NormalDistibution(double log_x, double octave_mu, double octave_sigma) { return Math::cumulativeNormalDistibution(log(log_x)*LOG2E, octave_mu, octave_sigma); }
53
54
55 double bind(double x) {
56         return cumulativeLog2NormalDistibution(x, 2, 1.15/2);
57 }
58 double bind2(double x) {
59         return 1-cumulativeLog2NormalDistibution(x, 1, 1.15/2);
60 }
61
62 void psychlops_main() {
63         Canvas cnvs(1024,768,Canvas::window);
64
65         Figures::FunctionalPlot plot(256,256);
66         //plot.append(&bind);
67         //plot.append(&bind2);
68         //plot.x_max=20; plot.x_min=0.0000001; plot.y_max=1.1; plot.y_min=-0.1;
69         plot.append(&sin);
70         plot.x_max=10; plot.x_min=-10; plot.y_max=1.1; plot.y_min=-1.1;
71         plot.draw();
72         cnvs.flip();
73
74         while(!Keyboard::esc.pushed()) {}
75 }
76
77
78 /*
79 void psychlops_main() {
80         Canvas sampleA(Canvas::fullscreen);
81
82         Image img(200,200);
83         img.clear(Color::blue);
84         img.rect(Psychlops::Rectangle(50,0,150,100),Color::green); // Draw rect to upper side
85         img.centering().draw();
86
87
88         Psychlops::Rectangle rect(500,500);
89         Image target;
90
91         sampleA.to(target, rect.centering());
92         rect.draw(Color(1,0,0,0.2));    // show source area of Canvas::to
93
94
95         sampleA.flip(); // If Canvas::flip has been done bofore Canvas::to, Canvas::to won't work as you intended.
96         while(!Input::get(Keyboard::esc));
97
98         // writing outline of the image
99         target.line(0, 0, 0, target.getHeight(), Color::red);
100         target.line(0, 0, target.getWidth(), 0, Color::red);
101         target.line(0, 0, target.getWidth(), target.getHeight(), Color::red);
102
103         sampleA.clear();
104         target.draw();
105         sampleA.flip();
106         while(!Input::get(Keyboard::esc));
107 }
108 */
109
110 /*
111 Psychlops::Rectangle rect1(1279,1023); Psychlops::Rectangle rect2;
112 Psychlops::Image Stimulus1(rect1); Psychlops::Image Stimulus2(rect1);
113 Psychlops::Color col(0.8);
114
115 void psychlops_main() {
116         Canvas sampleA(Canvas::fullscreen);
117         for(int y=0; y<10; y++) {
118                 rect2.set(0, y*100+25, 1279, y*100+20+25);
119                 Stimulus1.rect(rect2, col);
120         }
121         Stimulus1.draw();
122         sampleA.flip();
123         while(!Input::get(Keyboard::esc));
124
125         sampleA.flip();
126
127         rect2.set(0,0,500,500);//x座標が指定できていない
128         //rect2.set(0,0,1680,500);//上下反転?
129         //rect2.set(0,500,1680,1000);//OK
130
131         sampleA.to(Stimulus2, rect2);
132         Stimulus2.draw();
133         sampleA.flip();
134         while(!Input::get(Keyboard::esc));
135 }
136
137 */