-///+ Prefix linkto BasicCode1\r
-//// Lines for set up Psychlops environment\r
-using Psychlops;\r
+using Psychlops;\r
\r
-namespace PsychlopsSilverlight4test\r
+namespace PsychlopsSilverlightApp\r
{\r
\r
public class PsychlopsMain\r
- {///- Prefix linkto BasicCode1\r
+ {\r
\r
\r
- ///+ Main Routine\r
- //// Psychlops runs at the first line of this function psychlops_main().\r
- public void psychlops_main()\r
- {\r
- ///+ 0 linkto BasicCode3_1a\r
- ////Prepare global parameters\r
- int maxrectnum = 200;\r
- int rectnum = 100;\r
- double rectsize = 5.0;\r
- Rectangle[] rect = StaticFunctions.NewArray<Rectangle>(maxrectnum);\r
- double[] rectcolorR = new double[maxrectnum];\r
- double[] rectcolorG = new double[maxrectnum];\r
- double[] rectcolorB = new double[maxrectnum];\r
- ///- 0 linkto BasicCode3_1a\r
-\r
- Canvas window = new Canvas(Canvas.window);\r
-\r
- ///+ 1 linkto BasicCode3_1a\r
- ////Initialize\r
- for (int i = 0; i < rectnum; i++)\r
- {\r
- ///+ 1.1 set1\r
- ////set positions and sizes\r
- rect[i].set(rectsize, rectsize); //Set a size of rectangles.\r
- rect[i].centering();\r
- rect[i].shift((i - 0.5 * rectnum) * rectsize * 1.5,\r
- (i - 0.5 * rectnum) * rectsize * 1.5); //Move Rectangles to initial positions\r
- ///- 1.1 set1\r
- ///+ 1.2 set2\r
- ////set colors\r
- rectcolorR[i] = Math.random(1.0) * 0.5; //Set R values. Note that "i" is converted to double-type.\r
- rectcolorG[i] = Math.random(1.0) * 0.5; //Set G values. Note that "i" is converted to double-type.\r
- rectcolorB[i] = Math.random(1.0) * 0.5; //Set B values. Note that "i" is converted to double-type.\r
- ///- 1.2 set2\r
- }\r
- ///- 1 linkto BasicCode3_1a\r
+ public void psychlops_main() {\r
\r
- ///+ 2 drawing\r
- ////drawing objects\r
- ///+ 2.1 linkto BasicCode3_2a\r
- ////Prepare variables for movie control;\r
- int frame = 0;\r
- int motion_dir = 1;\r
- double Horizontal_shift, Vertical_shift;\r
- ///- 2.1 linkto BasicCode3_2a\r
+ Canvas display = new Canvas(768,768);\r
\r
- while (!Keyboard.esc.pushed())\r
- {\r
- window.clear(Color.black);\r
- for (int i = 0; i < rectnum; i++)\r
- {\r
- ///+ 2.2 loopset1\r
- ////set positions and sizes\r
-\r
- Horizontal_shift = Math.sin(2 * Math.PI * ((double)frame / 30.0)) * motion_dir * 100.0; //Calculate horizontal displacement from the center.\r
- Vertical_shift = Math.sin(2 * Math.PI * ((double)frame / 30.0)) * motion_dir * 0.0;//Calculate vertical displacement from the center.\r
- rect[i].resize(rectsize, rectsize); //Resize rectangles.\r
- rect[i].centering(); //Rectangles are moved to the center...\r
- rect[i].shift(Horizontal_shift + (i - 0.5 * rectnum) * rectsize * 1.5,\r
- Vertical_shift + (i - 0.5 * rectnum) * rectsize * 1.5); //and then move to designated positions\r
- ///- 2.2 loopset1\r
-\r
- ///+ 2.3 linkto BasicCode3_2a\r
- ////set colors \r
- rectcolorR[i] = Math.random(1.0) * 0.5; //Set R values. Note that "i" is converted to double-type.\r
- rectcolorG[i] = Math.random(1.0) * 0.5; //Set G values. Note that "i" is converted to double-type.\r
- rectcolorB[i] = Math.random(1.0) * 0.5; //Set B values. Note that "i" is converted to double-type.\r
- ///- 2.3 linkto BasicCode3_2a\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
- }\r
- ///+ 2.4 linkto BasicCode3_1a\r
- for (int i = 0; i < rectnum; i++)\r
- {\r
- rect[i].draw(new Color(rectcolorR[i], rectcolorG[i], rectcolorB[i])); //draw objects by designated colors.\r
- }\r
- window.flip();\r
- ///- 2.4 linkto BasicCode3_1a\r
- frame++;\r
- }\r
- ///- 2 drawing\r
+ SF[0]=4.0;\r
+ SF[1]=4.0;\r
\r
- }\r
- ///- Main Routine\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
- }\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
-}\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
-using Psychlops;\r
\r
-namespace PsychlopsSilverlight4test\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
- public class PsychlopsMain\r
- {\r
- void RectLuminance()\r
- {\r
- Canvas display = new Canvas(Canvas.window);\r
- Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);\r
- Letters le = new Letters("Reload to restart");\r
- le.fill = Color.black;\r
- le.align = Letters.HorizontalAlign.center;\r
-\r
- while (!Keyboard.esc.pushed())\r
- {\r
- Display.clear(Color.white);\r
- le.centering().shift(-200,-10).draw();\r
- Display.flip();\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
\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
- public void psychlops_main()\r
- {\r
- RectLuminance();\r
- }\r
\r
\r
- }\r
+ envelope.set(size, size);\r
+ envelope.clear(bglum);\r
\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
\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.var(Mouse.x, 300, 300);\r
+ Display.var(Mouse.y, 300, 320);\r
\r
-/*\r
- using Psychlops;\r
+ Display.flip();\r
\r
-namespace PsychlopsSilverlight4test\r
-{\r
\r
- public class PsychlopsMain\r
- {\r
+ }\r
\r
- Psychlops.Canvas cnvs;\r
- int i;\r
- double x, y, z, t, p, temp, xx, yy;\r
+}\r
\r
- //Set Target Initial Value\r
- double TargetEcce = 100.0, TargetSize = 5.0, TargetNumber = 5, Rotate = 0.0;\r
\r
- //Set Background Initial Value\r
- double Axis = 0.0, BGRadii = 150, BGSize = 5.0;\r
- Psychlops.Widgets.Slider thetaSpeed, DotNumber;\r
- Image img;\r
\r
+ }\r
\r
+}\r
+/*\r
\r
- public void psychlops_main()\r
- {\r
- cnvs = new Canvas(500, 500);\r
+using Psychlops;\r
+//Position Bias Program\r
+namespace PsychlopsSilverlightApp\r
+{\r
\r
- Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);\r
+ public class PsychlopsMain\r
+ {\r
+ Canvas cnvs;\r
+ Image img, img2, img3;\r
+ int isize = 40;\r
+ int frames;\r
+ Psychlops.Widgets.Slider tfreq;\r
+ Psychlops.Widgets.Slider contrast;\r
+ Psychlops.Widgets.Slider lambda;\r
\r
\r
- img = new Image("Resources/logo.png");\r
\r
+ public void psychlops_main()\r
+ {\r
+ cnvs = new Canvas(300, 600);\r
Interval rng = new Interval();\r
- thetaSpeed = new Psychlops.Widgets.Slider("Label", -10 <= rng <= 10, 3.0);\r
- DotNumber = new Psychlops.Widgets.Slider("DotNum", 0 <= rng <= 100, 50.0);\r
-\r
- //Declare background dots and target\r
- Rectangle[] BGDot = new Rectangle[2048];\r
- for(int i=0; i<2048; i++){\r
- BGDot[i]=new Rectangle();\r
- }\r
- Rectangle[] Target= new Rectangle[10];\r
- for(int i=0; i<10; i++){\r
- Target[i]=new Rectangle();\r
- }\r
+ tfreq = new Psychlops.Widgets.Slider("Temporal Frequency(Hz)", -5 <= rng <= 5, 3.0);\r
+ contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.25);\r
+ lambda = new Psychlops.Widgets.Slider("Wave Length", 10.0 <= rng <= 120.0, 30);\r
\r
+ img = new Image(isize * 2, isize * 2);\r
+ img2 = new Image(isize * 2, isize * 2);\r
+ img3 = new Image(isize * 2, isize * 2);\r
\r
- //Declare Matrix to keep back ground dots' coordinate value\r
- double[] DotX=new double[2048];\r
- double[] DotY = new double[2048];\r
+ var gabor1 = StaticFunctions.NewArray<Figures.ShaderGabor>(100);\r
+ foreach (var g in gabor1)\r
+ {\r
+ g.setSigma(isize/8).centering().shift(Math.random(300) - 150, Math.random(600) - 300);\r
+ //g.setSize(isize).centering().shift(Math.random(300) - 150, Math.random(600) - 300);\r
+ g.orientation = Math.random(2 * Math.PI);\r
+ //g.orientation2 = Math.random(2 * Math.PI);\r
+ }\r
\r
+ while (true)\r
+ {\r
+ cnvs.clear(new Color(0.5));\r
\r
- //Set Independent variables to manipulate\r
+ Figures.drawGabor(ref img, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);\r
+ Figures.drawGabor(ref img2, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * -tfreq / 60);\r
+ Figures.drawGabor(ref img3, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);\r
\r
\r
- //Initialize positions of background dots\r
- for(int i=0; i<2048; i++){\r
- t=2.0*Math.PI*Math.random(1.0);\r
- p=2.0*Math.PI*Math.random(1.0);\r
- DotX[i]=t;\r
- DotY[i]=p;\r
+ //img.centering().shift(0, -isize * 1.5).draw();\r
+ //img2.centering().draw();\r
+ //img3.centering().shift(0, isize * 1.5).draw();\r
\r
- x=BGRadii*Math.cos(t)*Math.cos(p);\r
- y=BGRadii*Math.sin(t)*Math.cos(p);\r
- BGDot[i].set(BGSize, BGSize);\r
- BGDot[i].centering().shift(x,y);\r
- }\r
\r
- //Initialize positions of targets\r
- for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize);\r
-\r
- double COS, SIN;\r
- //DotNumber = 200;\r
- //Main stimulus loop\r
- while(true){\r
- //Clear the main window\r
- cnvs.clear();\r
-\r
-\r
- temp=Axis/360*2*Math.PI;\r
- COS=Math.cos(temp);\r
- SIN=Math.sin(temp);\r
-\r
- //Calculate positions of background dots and set them\r
- for(int i=0; i<DotNumber; i++){\r
- //Calculate in polar coordinate\r
- t=DotX[i]+2.0*Math.PI*thetaSpeed/360.0;\r
- p=DotY[i];\r
-\r
- //Save current position\r
- DotX[i]=t;\r
-\r
- //Convert to Decartes coordinate\r
- x=BGRadii*Math.cos(t)*Math.cos(p);\r
- y=BGRadii*Math.sin(t)*Math.cos(p);\r
- z=BGRadii*Math.sin(p);\r
- xx=x;\r
- yy=SIN*y+COS*z;\r
-\r
- //Set Dotsize and Draw them\r
- BGDot[i].set(BGSize, BGSize);\r
- BGDot[i].centering().shift(xx,yy);\r
- BGDot[i].draw( Color.blue );\r
- }\r
-\r
- //Calculate positions of targets and set them\r
- temp=Rotate*2*Math.PI/360.0;\r
- for (int i = 0; i < 5; i++)\r
+ //foreach (var g in gabor1)\r
+ for (int i = 0; i < gabor1.Length; i++)\r
{\r
- t = 2.0 * Math.PI/TargetNumber;\r
- x = TargetEcce*Math.cos(i*t+temp);\r
- y = TargetEcce*Math.sin(i*t+temp);\r
- Target[i].centering().shift(x,y);\r
- Target[i].fill = Color.yellow;\r
- Target[i].draw();\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
+ gabor1[i].draw();\r
}\r
\r
- img.centering(Mouse.position).draw();\r
-\r
- cnvs.var(Mouse.position.x, 100, 100);\r
- cnvs.var(Mouse.position.y, 100, 140);\r
+ if (!Mouse.left.pressed()) frames++;\r
\r
- //Reflect drawing at the next frame;\r
cnvs.flip();\r
}\r
}\r
}\r
-\r
}\r
-*/\r
\r
\r
-/*using Psychlops;\r
+/*\r
+///+ Prefix linkto BasicCode1\r
+//// Lines for set up Psychlops environment\r
+using Psychlops;\r
\r
-namespace PsychlopsSilverlight4test\r
+namespace PsychlopsSilverlightApp\r
{\r
+\r
public class PsychlopsMain\r
{\r
+ ///- Prefix linkto BasicCode1\r
+\r
+\r
+ ///+ Main Routine\r
+ //// Psychlops runs at the first line of this function psychlops_main().\r
public void psychlops_main()\r
{\r
- var figure_type = Psychlops.Widgets.Browser.Element.byID("FIGURE");\r
- var size_x = Psychlops.Widgets.Browser.Element.byID("SIZE_X");\r
- var size_y = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");\r
- var shift_x = Psychlops.Widgets.Browser.Element.byID("SHIFT_X");\r
- var shift_y = Psychlops.Widgets.Browser.Element.byID("SHIFT_Y");\r
- var color_r = Psychlops.Widgets.Browser.Element.byID("COLOR_R");\r
- var color_g = Psychlops.Widgets.Browser.Element.byID("COLOR_G");\r
- var color_b = Psychlops.Widgets.Browser.Element.byID("COLOR_B");\r
-\r
- Canvas window = new Canvas(300, 300);\r
-\r
- var figure_r = new Rectangle();\r
- var figure_e = new Ellipse();\r
- Shape figure = figure_r;\r
+\r
+ ///+ 0 SetGlobal\r
+ ////Prepare global parameters\r
+ Rectangle p1 = new Rectangle(1,1);\r
+ Color col1 = new Color();\r
+ double width=50;\r
+ double height=10;\r
+ double lambda=60;\r
+ double lmean=0.25, contrast = 0.5;\r
+ double x0 = 0;\r
+ double y0 = 0;\r
+ double pitch = 1;\r
+ Canvas disp = new Canvas(Canvas.window, Display.secondary);\r
\r
- while (!Keyboard.esc.pushed())\r
+ var fieldW_ = Psychlops.Widgets.Browser.Element.byID("fieldW");\r
+ var fieldH_ = Psychlops.Widgets.Browser.Element.byID("fieldH");\r
+ var wL_ = Psychlops.Widgets.Browser.Element.byID("wL");\r
+ var Cont_ = Psychlops.Widgets.Browser.Element.byID("Cont");\r
+ var ix_ = Psychlops.Widgets.Browser.Element.byID("ix");\r
+ var iy_ = Psychlops.Widgets.Browser.Element.byID("iy");\r
+ var gap_ = Psychlops.Widgets.Browser.Element.byID("gap");\r
+ ///- 0 SetGlobal\r
+\r
+ ///+ 1 Initialize\r
+ ////initialize\r
+ p1.centering().shift(-width*0.5 + x0, -height*0.5 + y0); //Move a point to the initial position.\r
+ ///- 1 Initialize\r
+\r
+ ///+ 2 Drawing\r
+ ////drawing objects\r
+ for(int i=0; i < width; i++)\r
{\r
- if (System.String.Compare(figure_type, "Rectangle") == 0)\r
- {\r
- figure_r.set(size_x, size_y);\r
- figure = figure_r;\r
- }\r
- else\r
+ col1.set(lmean*((contrast*Math.sin((2*Math.PI*i/lambda)))+1)); //Set a color.\r
+\r
+ ///+ 2.1 Drawing a column\r
+ ////drawing a column\r
+ for(int j=0;j < height; j++)\r
{\r
- figure_e.set(size_x, size_y);\r
- figure = figure_e;\r
+ p1.draw(col1);\r
+ p1.shift(0, pitch);\r
}\r
- figure.fill = new Color(color_r, color_g, color_b);\r
+ ///- 2.1 Drawing a column\r
\r
- window.clear(Color.black);\r
- figure.centering().shift(shift_x, shift_y).draw();\r
- window.flip();\r
+ p1.shift(1, -height * pitch); //back to vertical intitial point after drawing one column.\r
}\r
+ disp.flip();\r
+ ///- 2 Drawing\r
+\r
+ while (!Keyboard.spc.pushed()) { }; //Wait until space key is pressed.\r
}\r
- }\r
\r
-}\r
\r
+ }\r
\r
+}\r
+ * */\r
\r
\r
/*\r
+///+ Prefix\r
+//// Lines for set up Psychlops environment\r
using Psychlops;\r
\r
-namespace Psychlops\r
+namespace PsychlopsSilverlightApp\r
{\r
\r
- public class RandomDots\r
- {\r
- Rectangle dot;\r
- public Point[] cood;\r
- public RandomDots()\r
- {\r
- cood = new Point[250];\r
- dot = new Rectangle(5, 5);\r
- }\r
- public void draw()\r
+ public class PsychlopsMain\r
+ {///- Prefix\r
+\r
+\r
+\r
+ ///+ Main Routine\r
+ //// Psychlops runs at the first line of this function psychlops_main().\r
+ public void psychlops_main()\r
{\r
- dot.fill = Color.white;\r
- foreach (Point p in cood)\r
- {\r
- dot.centering(p).draw();\r
+ Canvas window = new Canvas(300, 300); //Create a window. Here, window variables are preset mode.\r
+\r
+ var FIGURE = Psychlops.Widgets.Browser.Element.byID("FIGURE");\r
+ var SIZE_X_ = Psychlops.Widgets.Browser.Element.byID("SIZE_X");\r
+ var SIZE_Y_ = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");\r
+ var COLOR_R = Psychlops.Widgets.Browser.Element.byID("COLOR_R");\r
+ var COLOR_G = Psychlops.Widgets.Browser.Element.byID("COLOR_G");\r
+ var COLOR_B = Psychlops.Widgets.Browser.Element.byID("COLOR_B");\r
+ var COLOR_BG = Psychlops.Widgets.Browser.Element.byID("COLOR_BG");\r
+ var Period_Size = Psychlops.Widgets.Browser.Element.byID("Period_Size");\r
+ var Period_Position = Psychlops.Widgets.Browser.Element.byID("Period_Position");\r
+ var Speed_HSize_ = Psychlops.Widgets.Browser.Element.byID("Speed_HSize");\r
+ var Speed_VSize = Psychlops.Widgets.Browser.Element.byID("Speed_VSize");\r
+ var Speed_VMotion = Psychlops.Widgets.Browser.Element.byID("Speed_VMotion");\r
+ double SIZE_X = SIZE_X_, SIZE_Y = SIZE_Y_;\r
+\r
+ ///+ 2\r
+ //// Set a figure size, position and color.\r
+ Rectangle figure = new Rectangle();\r
+ Ellipse figure2 = new Ellipse();\r
+ figure.set(SIZE_X_, SIZE_Y_); // Set the size of figure.\r
+ figure2.set(SIZE_X_, SIZE_Y_); // Set the size of figure.\r
+ figure.centering().shift(0, 0); // Move the figure to the starting point.\r
+ figure2.centering().shift(0, 0); // Move the figure to the starting point.\r
+ ///- 2\r
+\r
+ int frame = 0;\r
+ int looming_direction = 1, motion_dir = 1;\r
+ double direction = 1.0;\r
+ //looming_direction is a variable for size change.\r
+ //motion_dir is a variable for motion direction.\r
+ ///+ 3 Drawing loop\r
+ //// Draw each frames in a "while loop".\r
+ while (!Keyboard.esc.pushed())\r
+ { //exit a program when the escape key is pressed down.\r
+ window.clear(COLOR_BG); // Clear the window with a designated gray-scale level.\r
+\r
+ ///+ 3.1\r
+ //// Calculate object's position and size for each frame.\r
+\r
+ if (frame % Period_Size == 0)\r
+ { // a direction of size change will reverse at designated frames.\r
+ looming_direction = looming_direction * -1;\r
+ }\r
+\r
+ if (frame % Period_Position == 0)\r
+ { // motion direction will reverse at designated frames.\r
+ motion_dir *= -1;\r
+ }\r
+\r
+ ///- 3.1\r
+\r
+ ///+ 3.2 \r
+ //// Settting figure's properties\r
+ figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".\r
+ figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".\r
+ figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". \r
+ figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".\r
+ figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".\r
+ figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". \r
+ /*\r
+ figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".\r
+ figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".\r
+ figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". \r
+ figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".\r
+ figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".\r
+ figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". \r
+ * * /\r
+ ///- 3.2\r
+\r
+ ///+ 3.3 \r
+ ////Drawing\r
+ if ("Rectangle".Equals(FIGURE))\r
+ {\r
+ figure.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.\r
+ }\r
+ else\r
+ {\r
+ figure2.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.\r
+ }\r
+ window.flip(); // Reflect the drawing for the display by flipping frame buffers.\r
+ ///- 3.3\r
+\r
+ ///+ 3.4\r
+ ////make a step for next frames \r
+ frame++;\r
+ ///- 3.4\r
}\r
+ ///- 3 Drawing loop\r
+\r
}\r
+ ///- Main Routine\r
+\r
+\r
}\r
\r
}\r
\r
\r
\r
-namespace PsychlopsSilverlight4test\r
+/*\r
+//The reversed-phi motion.\r
+//Anstis (1970)\r
+//Phi movement as a subtraction process. Vision Res 10:1411?1430\r
+\r
+///+ Prefix\r
+//// Include Psychlops Package\r
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlightApp\r
{\r
\r
public class PsychlopsMain\r
{\r
- Canvas cnvs;\r
- Image img;\r
- Ellipse fixation;\r
- Shape shape;\r
- Color col;\r
- int isize = 100;\r
- double tfreq = 1;\r
- int frames;\r
- RandomDots dots;\r
- Group g;\r
\r
- public void psychlops_main()\r
+ ///- Prefix\r
+\r
+ ///+ Stimulus drawing function\r
+ //// A function for stimulus drawing (main body)\r
+ void RectLuminance()\r
{\r
- cnvs = new Canvas(500, 500);\r
- g = new Group();\r
- img = new Image(isize * 2, isize * 2);\r
- Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);\r
- g.append(img);\r
- g.rotation = 50;\r
- fixation = new Ellipse(10, 10);\r
- fixation.fill = Color.red;\r
- //var poly = new Rectangle(100, 100);\r
- var poly = new Letters("日本語");\r
- //var poly = new Polygon(); poly.append(0, 100); poly.append(-100, 0); poly.append(0, -100); poly.append(100, 0);\r
- //var poly = new Ellipse(100, 100);\r
- //var poly = new Line(0,0,100, 0);\r
- poly.fill = Color.red;\r
- poly.stroke = new Stroke { color = Color.yellow, thick = 1 };\r
- shape = poly;\r
-\r
- var rng = new Interval();\r
- var slider = new Psychlops.Widgets.Slider("tesrt", -100 <= rng <= 100);\r
-\r
- dots = new RandomDots();\r
\r
+ ///+ Preperation\r
+ //// Declare and initialize local variables\r
+ double rect_size = 20;\r
\r
- while (true)\r
- {\r
- frames++;\r
+ double bg_lum = 0.5;\r
+ double radii = 200;\r
+ double rect_lum;\r
+ int element_number = 25;\r
+ int radial_row = 5;\r
\r
+ double rotation_tf = 0.2;\r
+ double polarity = 1;\r
+ double rotation;\r
\r
- cnvs.clear(new Color(Mouse.left.pressed() ? 0.75 : 0.5));\r
- col.set(Math.random(1.0));\r
+ double contrastflag = 1;\r
+ int period = 3;\r
+ double refresh;\r
\r
- /*if (frames % 2 == 0)\r
- {\r
- fixation.centering().shift(100, 100);\r
- fixation.draw(new Stroke(Color.blue, 3));\r
- }* /\r
+ Canvas display = new Canvas(Canvas.window); //Prepare drawing window\r
+ refresh = Display.getRefreshRate();\r
\r
- fixation.centering().shift(slider, 0);\r
- fixation.draw(Color.red);\r
+ Ellipse rect = new Ellipse();\r
+ rect.set(rect_size, rect_size);\r
\r
- //Figures.drawGabor(ref img, 20, 100, 1, 0, frames * 2.0 * Math.PI / tfreq / 60);\r
- //Figures.drawGaussian(ref img, 20, 1);\r
- //Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);\r
- //img.centering(Mouse.position);\r
- //img.draw();\r
- g.centering(Mouse.position).draw();\r
- g.rotation += 1;\r
+ Ellipse fixation = new Ellipse(5, 5);\r
+ fixation.centering();\r
\r
- shape.centering(Mouse.position).shift(100, 0);\r
- shape.draw();\r
- if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100);\r
+ Letters let1 = new Letters("Press Space key to change stimulus type");\r
+ let1.centering().shift(-180, 220);\r
+ Letters let2 = new Letters("Phi");\r
+ let2.centering().shift(-10, 200);\r
+ Letters let3 = new Letters("Reversed-Phi");\r
+ let3.centering().shift(-60, 200);\r
\r
- cnvs.var(frames, 0, 20);\r
- //slider.value = frames / 100.0;\r
+ rotation = Math.random(2 * Math.PI);\r
\r
- /*if (frames % 2 != 0)\r
- {\r
- fixation.shift(100, 100);\r
- fixation.draw(new Stroke(Color.green, 3));\r
- }* /\r
+ ///+ user interface\r
+ ////register variables to demo circumstances\r
+ Interval rng = new Interval();\r
+\r
+ Psychlops.Widgets.Slider rect_contrast;\r
+ rect_contrast = new Psychlops.Widgets.Slider("Contrast", 0.1 <= rng <= 1.0, 0.1);\r
+ rect_contrast.value = 0.5;\r
+ ///- user interface\r
+ ///- Preperation\r
+\r
+ ///+ Main loop\r
+ ////Main loop\r
+ int frame = 0;\r
+ //AppState::setThreadPriority(AppState::HIGH);\r
+ while (true)\r
+ {\r
+ frame++;\r
+ if (Keyboard.spc.pushed()) contrastflag = -contrastflag;\r
+ if (contrastflag < 0) polarity = -polarity;\r
+ rotation = 2 * Math.PI * rotation_tf * frame * period / refresh;\r
\r
- for (int i = 0; i < dots.cood.Length; i++)\r
+ for (int frame_now = 0; frame_now < period; frame_now++)\r
{\r
- dots.cood[i].set(Math.random(500), Math.random(500));\r
+ Display.clear(new Color(bg_lum));\r
+ for (int j = 0; j < radial_row; j++)\r
+ {\r
+ rect.resize(rect_size * (j + radial_row) / 10.0, rect_size * (j + radial_row) / 10.0);\r
+ for (double i = 0; i < element_number; i++)\r
+ {\r
+ rect_lum = bg_lum * (1.0 + polarity * rect_contrast);\r
+ rect.centering().shift(radii * (j + radial_row) / 10.0 * Math.cos(rotation + i * 2 * Math.PI / element_number), radii * (j + radial_row) / 10.0 * Math.sin(rotation + i * 2 * Math.PI / element_number));\r
+ rect.draw(rect_lum);\r
+ }\r
+ }\r
+ fixation.draw(Color.red);\r
+ let1.draw();\r
+ if (contrastflag > 0) let2.draw();\r
+ else let3.draw();\r
+ Display.flip();\r
}\r
- cnvs.var((double)slider, 200, 200);\r
- dots.draw();\r
-\r
- cnvs.flip();\r
}\r
+ ///- Main loop\r
+ //AppState::setThreadPriority(AppState::NORMAL);\r
+ }\r
+ ///- Stimulus drawing function\r
+\r
+ ///+ Main function for demo circumstances\r
+ //// Psychlops Main function\r
+ public void psychlops_main()\r
+ {\r
+ ///+ Demo circumstances\r
+ //// Spells for run demonstration circumstances\r
+ Procedure p = new Procedure();\r
+ //p.setDesign(Procedure::DEMO); //Designate that this is a demo.\r
+ p.setProcedure(RectLuminance); //The argument name is a name of drawing function.\r
+ p.run();\r
+ ///- Demo circumstances\r
}\r
+ ///- Main function for demo circumstances\r
+\r
}\r
+\r
}\r
\r
-**/\r
\r
\r
/*\r
+//Two types of plaid motion\r
+//E. H. Adelson and J. A. Movshon (1982).\r
+//Phenomenal coherence of moving visual patterns. Nature 300, 523-525\r
\r
+///+ Prefix\r
+//// Include Psychlops Package\r
using Psychlops;\r
-namespace PsychlopsSilverlight4test\r
-{\r
\r
- public class PsychlopsMain\r
+ namespace PsychlopsSilverlightApp\r
{\r
- Canvas cnvs;\r
- Rectangle[] rect;\r
- int n;\r
\r
- public void psychlops_main()\r
+ public class PsychlopsMain\r
{\r
- n = 1;\r
- cnvs = new Canvas(500, 500);\r
- rect = new Rectangle[n];\r
- for (int i = 0; i < n; i++)\r
+ ///- Prefix\r
+\r
+ ///+ Global\r
+ // Struct for component paremeters\r
+ struct component\r
{\r
- rect[i] = new Rectangle(10, 10);\r
- rect[i].fill = Color.red;\r
+ public double contrast;\r
+ public double orientation;\r
+ public double lambda;\r
+ public double tf;\r
}\r
- Interval rng = new Interval();\r
- var slider = new Psychlops.Widgets.Slider("Label", -100 <= rng <= 100);\r
+ ///- Global\r
\r
- while (true)\r
+ ///+ Stimulus drawing function\r
+ //// A function for stimulus drawing (main body)\r
+ void drawgratingmovie(Image[] img, component c1, component c2, double contrast, int start, int maxframe, double bg_lum, double alpha)\r
{\r
- cnvs.clear();\r
- for (int i = 0; i < n; i++)\r
+ double _xp, _xp2, col1, col2;\r
+ double contrast1, contrast2;\r
+ double imageheight, imagewidth;\r
+\r
+ contrast1 = contrast*c1.contrast/(c1.contrast+c2.contrast);\r
+ contrast2 = contrast*c2.contrast/(c1.contrast+c2.contrast);\r
+\r
+ imageheight = img[0].getHeight();\r
+ imagewidth = img[0].getWidth();\r
+\r
+ for(int frame=start; frame<start+maxframe+1; frame++){\r
+ //Display.progressbar(frame, maxframe+1);\r
+ //img[frame].convert(Image::RGBA);\r
+ for(int i=0; i<imagewidth; i++){\r
+ for(int j=0; j<imageheight; j++){\r
+ _xp = Math.sin(c1.orientation)*(i-imagewidth*0.5) + Math.cos(c1.orientation) * (j-imageheight *0.5);\r
+ _xp2 = Math.sin(c2.orientation)*(i-imagewidth*0.5) + Math.cos(c2.orientation) * (j-imageheight *0.5);\r
+ col1 = bg_lum*contrast1*Math.sin(2*Math.PI*_xp/c1.lambda + 2*Math.PI*c1.tf*frame/(double)refresh);\r
+ col2 = bg_lum*contrast2*Math.sin(2*Math.PI*_xp2/c2.lambda + 2*Math.PI*c2.tf*frame/(double)refresh);\r
+ img[frame].pix(i,j,new Color(col1+col2+bg_lum));\r
+ img[frame].alpha(i,j,alpha);\r
+ }\r
+ }\r
+ //img[frame].cache();\r
+ }\r
+ }\r
+\r
+ ///+ Stimulus drawing function\r
+ //// A function for stimulus drawing (main body)\r
+ void drawplaid() {\r
+ Canvas display = new Canvas(Canvas.window);\r
+ ///+ Preperation\r
+ //// Declare and initialize local variables\r
+ int rect_size = 150;\r
+ double rect_lum = 0.5;\r
+ double bg_lum = 0.2;\r
+ double duration = 400;\r
+\r
+ double[] lambda = new double[2], contrast = new double[2], tf = new double[2];\r
+ double center_orientation = 0.0;\r
+ Image[,] movie = StaticFunctions.NewArray<Image>(2, 120);\r
+ Image[,] component_movie = StaticFunctions.NewArray<Image>(4, 120);\r
+ Image envelope = new Image(), envelope_small = new Image();\r
+\r
+ for(int i=0; i<120; i++)\r
{\r
- rect[i].centering().shift(slider * i*3, i*3).draw();\r
+ movie[0, i].set(rect_size, rect_size);\r
+ movie[1, i].set(rect_size, rect_size);\r
+ component_movie[0, i].set(rect_size/2, rect_size/2);\r
+ component_movie[1, i].set(rect_size/2, rect_size/2);\r
+ component_movie[2, i].set(rect_size/2, rect_size/2);\r
+ component_movie[3, i].set(rect_size/2, rect_size/2);\r
}\r
- cnvs.flip();\r
+ envelope.set(rect_size, rect_size);\r
+ envelope_small.set(rect_size/2, rect_size/2);\r
+\r
+ Letters let1 = new Letters(), let2 = new Letters(), let3 = new Letters();\r
+ let1.str = "Component1";\r
+ let2.str = "Component2";\r
+ let3.str = "Superposition";\r
+ let1.centering().shift(-rect_size*1.25, -rect_size);\r
+ //let1.cache();\r
+ let2.centering().shift(rect_size*1.25, -rect_size);\r
+ //let2.cache();\r
+ let3.centering().shift(0.0, rect_size*0.75);\r
+ //let3.cache();\r
+\r
+ component c1, c2, c0;\r
+ c0 = new component{ 0.0,0.0,1.0,1.0 }; //dummy for component movie\r
+ ///+ type-I\r
+ // Prepare Type-I plaid movie\r
+ center_orientation = 0.0;\r
+ orientation_offset = Math.PI/6;\r
+ contrast[0] = 1.0, contrast[1] = 1.0;\r
+ lambda[0] = 30.0, lambda[1] = 30.0;\r
+ tf[0] = 1.0; tf[1] = 1.0;\r
+\r
+ c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};\r
+ c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};\r
+\r
+ drawgratingmovie(movie[0],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+ drawgratingmovie(component_movie[0],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+ drawgratingmovie(component_movie[1],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+ ///- type-I\r
+\r
+ ///+ type-II\r
+ // Prepare Type-II plaid movie\r
+ center_orientation = -0.0, orientation_offset = Math.PI/12;\r
+ contrast[0] = 1.0, contrast[1] = 1.0;\r
+ lambda[0] = 30.0, lambda[1] = 30.0;\r
+ tf[0] = 1.0; tf[1] = 4.0;\r
+\r
+ c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};\r
+ c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};\r
+\r
+ drawgratingmovie(movie[1],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+ drawgratingmovie(component_movie[2],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+ drawgratingmovie(component_movie[3],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+ ///- type-II\r
+\r
+ ///+ gaussian\r
+ //draw Gaussian envelopes\r
+ envelope.clear(new Color(bg_lum)); //clear offscreen image\r
+ double _x, _y;\r
+ for(int i=0; i<rect_size; i++){\r
+ _x=i-0.5*rect_size;\r
+ for(int j=0; j<rect_size; j++){\r
+ _y=j-0.5*rect_size;\r
+ envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/6.0, 2.0) ))));\r
+ }\r
+ }\r
+\r
+ envelope_small.clear(new Color(bg_lum)); //clear offscreen image\r
+ for(int i=0; i<rect_size*0.5; i++){\r
+ _x=i-0.25*rect_size;\r
+ for(int j=0; j<rect_size*0.5; j++){\r
+ _y=j-0.25*rect_size;\r
+ envelope_small.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/12.0, 2.0) ))));\r
}\r
+ }\r
+ envelope.cache(); //send offscreen image from main memory to GPU\r
+ envelope_small.cache(); //send offscreen image from main memory to GPU\r
+ ///- gaussian\r
+\r
+ ///+ user interface\r
+ // Draw user interface\r
+ Widgets::SelectBox stimulus_type;\r
+ stimulus_type.area.set(120, 20);\r
+ stimulus_type.append(L"TypeI");\r
+ stimulus_type.append(L"TypeII");\r
+ stimulus_type.centering().shift(-120.0,250.0);\r
+\r
+ Psychlops::Widgets::SelectBox stimulus_type2;\r
+ stimulus_type2.area.set(120, 20);\r
+ stimulus_type2.append(L"Continuous");\r
+ stimulus_type2.append(L"Periodic");\r
+ stimulus_type2.centering().shift(120.0,250.0);\r
+\r
+ Psychlops::Widgets::Slider duration_slider;\r
+ duration_slider.area.set(100,20);\r
+ duration_slider.centering().shift(120,280.0);\r
+ Interval rng = new Interval();\r
+ duration_slider.link(duration, 50<=rng<=950, 50.0, 50.0);\r
+ ///- user interface\r
+ ///- Preperation\r
+\r
+ ///+ Main loop\r
+ int frame = 0;\r
+ int period = refresh_int;\r
+ int movienum;\r
+ while(!Keyboard.esc.pushed()) {\r
+ Display.clear(new Color(bg_lum));\r
+ movienum = stimulus_type.getSelected(); //if "Type-I" is selected, 0, else frame refresh per sec\r
+\r
+ in;\r
+ else period = refresh_int;\r
+\r
+ if(frame>0){\r
+ movie[movienum, frame].centering().draw();\r
+ envelope.centering().draw();\r
+ component_movie[movienum*2, frame].centering().shift(-rect_size*0.5, -rect_size).draw();\r
+ envelope_small.centering().shift(-rect_size*0.5, -rect_size).draw();\r
+ component_movie[movienum*2+1, frame].centering().shift(rect_size*0.5, -rect_size).draw();\r
+ envelope_small.centering().shift(rect_size*0.5, -rect_size).draw();\r
+ }\r
+\r
+ ///+ draw user interface\r
+ let1.draw(0.75);\r
+ let2.draw(0.75);\r
+ let3.draw(0.75);\r
+ stimulus_type.draw();\r
+ stimulus_type2.draw();\r
+ if(stimulus_type2.getSelected())duration_slider.draw();\r
+ ///- draw user interface\r
+ Display.flip();\r
+ if(frame++ >= period) frame -= refresh_int;\r
+ }\r
+ ///- Main loop\r
+\r
+ }\r
+ ///- Stimulus drawing function\r
+\r
+ ///+ Main function for demo circumstances\r
+ public void psychlops_main() {\r
+ ///+ Demo circumstances\r
+ //// Spells for run demonstration circumstances\r
+ Procedure p = new Procedure();\r
+ //p.setDesign(Procedure::DEMO); //Designate that this is a demo.\r
+ p.setProcedure(drawplaid); //The argument name is a name of drawing function.\r
+ p.run();\r
+ ///- Demo circumstances\r
}\r
}\r
}\r
-\r
-*/
\ No newline at end of file
+*/\r