2 using namespace Psychlops; // Initially developed with Psychlops Win32 1.0.2 / 20080414
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
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));
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); }
33 Prototype::Thread::sleep(1000000);
37 class RectLuminance : public ExperimentalMethods::Demo {
47 Figures::FunctionalPlot c;
48 Prototype::Thread thread;
51 display.set(Canvas::window);
52 c.set(500,500).shift(0,300).centering();
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;
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));
71 base.join(gp).centering(gp);
75 AnalogOutput *analogout = new Devices::AnalogOutput_NIDAQmxBase();
78 analog = new Devices::AnalogInput_NIDAQmxBase();
79 thread.create(&watcher);
84 Psychlops::Rectangle mask(102,102);
87 while(!Input::get(Keyboard::esc)) {
88 phase = Math::mod(phase+2*PI*pow(2,tf)/display.getRefreshRate(), 2*PI);
90 display.clear(Color::gray);
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();
98 mask.draw(col.set(.5,.5,.5,sin(phase)*(sin(phase)<0 ? -1 : 1)));
103 gp.rotation = orientation*90 +180*(cos(phase)<0 ? 1 : 0) + 180*(numstim==2 ? 1 : 0);
104 gp.centering().draw();
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);
112 display.var(Mouse::getWheelDelta().y, 100, 100);
113 display.var(Mouse::left.pressed(), 100, 120);
114 display.var(hoge, 100, 140);
116 let.centering().draw(Color::red);
123 void psychlops_main() {
124 RectLuminance * exp = new RectLuminance;
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();
137 Display::line(area.getLeft()+i, area.getTop(), area.getLeft()+i, area.getTop()+y, Color::red);
141 void psychlops_main() {
142 Canvas c(Canvas::window);
144 Psychlops::Rectangle area(100,100);
147 Interval itvl = Interval(0,2*PI);
148 while(!Keyboard::esc.pushed()) {
150 YamaGraph(area, itvl, &sin);
158 class MotionOfHybridImage : public ExperimentalMethods::Demo {
164 canvas.set(800,600, Canvas::window, Display::secondary);
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;
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); }
182 full.clear();//.shift(2,1).quicken();
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);
192 dot.draw(Color::red);
193 canvas.pix(canvas.getWidth()-1,canvas.getHeight()-1,Color::red);
195 // rect.centering().shift(x-100,y).draw(Color::red);
196 img.centering().shift(x-100,y).draw(a);
198 img.centering().shift(x+100,y).draw();
199 rect.centering().shift(x+100,y).draw(Color::red);
208 void psychlops_main() {
210 MotionOfHybridImage *exp = new MotionOfHybridImage;
219 #include <psychlops.h>
220 using namespace Psychlops;
224 class GaussianEnvelope : public Image {
226 GaussianEnvelope(double sigma) {
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);
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));
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) ) );
247 void psychlops_main() {
248 Canvas canvas(800,600, Display::list()[1]);
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);
254 GaussianEnvelope filter(20);
257 group.clip(&filter).add(grating).centering();
259 while(!Keyboard::esc.pushed()) {
260 canvas.clear(Color::gray);