OSDN Git Service

sll
[psychlops/silverlight.git] / test4 / PsychlopsMain.cs
index 16acfd8..3969c0b 100644 (file)
@@ -1,5 +1,140 @@
-\r
+using Psychlops;\r
 \r
+namespace PsychlopsSilverlightApp\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+\r
+\r
+               public void psychlops_main() {\r
+\r
+       Canvas display = new Canvas(768,768);\r
+\r
+       double rect_size = 100;\r
+       double rect_lum  = 0.5;\r
+       double bg_lum    = 0.5;\r
+       double size = 250.0;\r
+   double sigma;\r
+   sigma = size/6.0;\r
+   double lambda;\r
+   lambda = 6*sigma;\r
+   int envelopemode = 0;\r
+   double refresh = display.getRefreshRate();\r
+   double[] SF=new double[2];\r
+\r
+   SF[0]=4.0;\r
+   SF[1]=4.0;\r
+\r
+   double phase=0;\r
+\r
+   double[] initphase = new double[2];\r
+   double _i, _j, _x, _y, _x2, _y2, col;\r
+   double amplitude = 1.0;\r
+\r
+       Rectangle fixation1 = new Rectangle(3,9);\r
+   Rectangle fixation2 = new Rectangle(9,3);\r
+       fixation1.centering();\r
+       fixation2.centering();\r
+   Rectangle contrastrect = new Rectangle();\r
+   contrastrect.set(760,760);\r
+\r
+   Image envelope = new Image();\r
+   Psychlops.Color bglum= new Color(0.5,0.5,0.5);\r
+   Psychlops.Color masklum = new Color(0.5,0.5,0.5,0.5);\r
+\r
+       Interval rng = new Interval();\r
+\r
+\r
+       Psychlops.Widgets.Slider TF;\r
+       TF = new Psychlops.Widgets.Slider("TF", 0.25<=rng<=2.0 , 0.1);\r
+   TF.value=0.75;\r
+\r
+\r
+\r
+       Psychlops.Widgets.Slider SFs;\r
+       SFs = new Psychlops.Widgets.Slider("SF", 4.0<=rng<=16.0 ,  4.0);\r
+       SFs.value = 4.0;\r
+\r
+   Psychlops.Widgets.Slider contrast;\r
+       contrast= new Psychlops.Widgets.Slider("Contrast", 0.0<=rng<=1.0 ,  0.1);\r
+       contrast.value = 0.1;\r
+\r
+\r
+       var element =  StaticFunctions.NewArray<Figures.ShaderGabor>(2);\r
+    for (int i = 0; i < element.Length; i++){\r
+           element[i].setSigma(sigma); // set a size of patch as a halfwidth of Gaussian\r
+           element[i].orientation = Math.PI/4.0+Math.PI/2.0*(1-i);//Math.PI/2*(rand()%2);// //set orientations\r
+           initphase[i]=0;\r
+  }\r
+\r
+\r
+\r
+      envelope.set(size, size);\r
+      envelope.clear(bglum);\r
+\r
+   for(int i=0; i<size; i++){\r
+       for(int j=0; j<size; j++){\r
+           _i=i-size*0.5;\r
+           _j=j-size*0.5;\r
+           _x=_i*Math.cos(-Math.PI/4.0)+_j*Math.sin(-Math.PI/4.0);\r
+           _y=-_i*Math.sin(-Math.PI/4.0)+_j*Math.cos(-Math.PI/4.0);\r
+           col=Math.exp(-(_x*_x)/(2*Math.pow(sigma*2/6.0,2.0))-(_y*_y)/(2*Math.pow(sigma*2,2.0)));\r
+           envelope.alpha(i,j,1.0-col);\r
+\r
+           }\r
+       }\r
+\r
+\r
+       while(!Keyboard.esc.pushed()) {\r
+           if(Keyboard.spc.pushed())envelopemode++; envelopemode%=2;\r
+       Display.clear(bglum);\r
+       phase ++;\r
+       //phase = fmod(phase,60);\r
+\r
+       for(int i=0; i<2; i++) {\r
+           element[i].phase =(SF[i]/SF[0])*amplitude*\r
+Math.PI*Math.sin(Math.PI/2*i+2*Math.PI*phase*TF/refresh);\r
+           element[i].wavelength = lambda/SF[i];\r
+           element[i].contrast = contrast;\r
+       }\r
+\r
+\r
+       element[0].centering().shift(-size * 0.6, -size * 0.6);\r
+       element[0].draw();\r
+       element[1].centering().shift(size*0.6,-size*0.6);\r
+       element[1].draw();\r
+               element[1].centering().shift(-size*0.6,size*0.6);\r
+       element[1].draw();\r
+               element[0].centering().shift(size*0.6,size*0.6);\r
+       element[0].draw();\r
+\r
+\r
+               if(envelopemode>0){\r
+                   envelope.centering().shift(size*0.6,-size*0.6).draw();\r
+                   envelope.centering().shift(-size*0.6,size*0.6).draw();\r
+                   }\r
+       masklum.set(bg_lum, bg_lum, bg_lum, 1-contrast);\r
+       contrastrect.centering();\r
+       contrastrect.draw(masklum);\r
+       fixation1.centering().shift(size*2,0.0);\r
+       fixation1.draw(Color.red);\r
+       fixation2.centering().shift(size*2,0.0);\r
+       fixation2.draw(Color.red);\r
+\r
+               Display.flip();\r
+\r
+\r
+       }\r
+\r
+}\r
+\r
+\r
+\r
+       }\r
+\r
+}\r
+/*\r
 \r
 using Psychlops;\r
 //Position Bias Program\r
@@ -53,15 +188,16 @@ namespace PsychlopsSilverlightApp
                                //img3.centering().shift(0, isize * 1.5).draw();\r
 \r
 \r
-                               foreach (var g in gabor1)\r
+                               //foreach (var g in gabor1)\r
+                               for (int i = 0; i < gabor1.Length; i++)\r
                                {\r
-                                       g.wavelength = lambda;\r
-                                       g.phase = (double)frames * 2.0 * Math.PI * tfreq / 60;\r
-                                       g.contrast = contrast;\r
+                                       gabor1[i].wavelength = lambda;\r
+                                       gabor1[i].phase = (double)frames * 2.0 * Math.PI * tfreq / 60;\r
+                                       gabor1[i].contrast = contrast;\r
                                        //g.wavelength2 = lambda * 2;\r
                                        //g.phase2 = (double)frames * 2.0 * Math.PI * tfreq / 60;\r
                                        //g.contrast2 = contrast / 2;\r
-                                       g.draw();\r
+                                       gabor1[i].draw();\r
                                }\r
 \r
                                if (!Mouse.left.pressed()) frames++;\r