X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=test4%2FPsychlopsMain.cs;h=e69a680907e928b65a738b126b2ef198cfc5d847;hb=refs%2Fheads%2Fsilverlight4;hp=261c75dd7eb2060920269f0bb53cefdf2e929825;hpb=7a71cabcacaf39cef5cbfb1ab85e51cecdc91dc7;p=psychlops%2Fsilverlight.git diff --git a/test4/PsychlopsMain.cs b/test4/PsychlopsMain.cs index 261c75d..e69a680 100644 --- a/test4/PsychlopsMain.cs +++ b/test4/PsychlopsMain.cs @@ -1,513 +1,756 @@ -///+ Prefix linkto BasicCode1 -//// Lines for set up Psychlops environment -using Psychlops; +using Psychlops; -namespace PsychlopsSilverlight4test +namespace PsychlopsSilverlightApp { public class PsychlopsMain - {///- Prefix linkto BasicCode1 + { - ///+ Main Routine - //// Psychlops runs at the first line of this function psychlops_main(). public void psychlops_main() { - ///+ 0 linkto BasicCode3_1a - ////Prepare global parameters - const int maxrectnum = 200; - int rectnum = 100/*ID:rectnumber 25.0 200.0 25.0*/; - double rectsize = 5.0/*ID:dotsize 1.0 10.0 1.0*/; - Rectangle[] rect = new Rectangle[maxrectnum]; - for (int i = 0; i < maxrectnum; i++) { rect[i] = new Rectangle(); } - double[] rectcolorR = new double[maxrectnum]; - double[] rectcolorG = new double[maxrectnum]; - double[] rectcolorB = new double[maxrectnum]; - ///- 0 linkto BasicCode3_1a - - Canvas window = new Canvas(Canvas.window); - - ///+ 1 linkto BasicCode3_1a - ////Initialize - for(int i=0; i < rectnum; i++){ - ///+ 1.1 set1 - ////set positions and sizes - rect[i].set(rectsize, rectsize); //Set a size of rectangles. - rect[i].centering(); - rect[i].shift((i - 0.5 * rectnum) * rectsize* 1.5/*ID:RectHGap 1.0 3.0 0.5*/, - (i - 0.5*rectnum) * rectsize * 1.5/*ID:RectVGap 1.0 3.0 0.5*/); //Move Rectangles to initial positions - ///- 1.1 set1 - ///+ 1.2 set2 - ////set colors - rectcolorR[i]=Math.random(1.0) * 0.5/*ID: RGain 0.0 1.0 0.5*/; //Set R values. Note that "i" is converted to double-type. - rectcolorG[i]=Math.random(1.0) * 0.5/*ID: GGain 0.0 1.0 0.5*/; //Set G values. Note that "i" is converted to double-type. - rectcolorB[i]=Math.random(1.0) * 0.5/*ID: BGain 0.0 1.0 0.5*/; //Set B values. Note that "i" is converted to double-type. - ///- 1.2 set2 - } - ///- 1 linkto BasicCode3_1a - - ///+ 2 drawing - ////drawing objects - ///+ 2.1 setlocal - ////Prepare variables for movie control; - int frame = 0; - int motion_dir = 1; - double Horizontal_shift, Vertical_shift; - ///- 2.1 setlocal - - while(!Keyboard.esc.pushed()){ - window.clear(Color.black); - - if(frame % 30/*ID:Period_Position 30 240 30*/ ==0){ // motion direction will reverse at designated frames. - motion_dir *= -1; - } - - for(int i=0; i < rectnum; i++){ - ///+ 2.2 loopset1 - ////set positions and sizes - - Horizontal_shift=motion_dir * 1.0/*ID:HSpeed 0.0 5.0 1.0*/; - Vertical_shift=motion_dir * 0.0/*ID:VSpeed 0.0 5.0 1.0*/; - - rect[i].resize(rectsize, rectsize); //Resize rectangles. - rect[i].shift(Horizontal_shift, Vertical_shift); - ///- 2.2 loopset1 - - ///+ 2.3 loopset2 - ////set colors - rectcolorR[i]=Math.random(1.0)* 0.5/*ID:RGain 0.0 1.0 0.5*/; //Set R values. Note that "i" is converted to double-type. - rectcolorG[i]=Math.random(1.0)* 0.5/*ID:GGain 0.0 1.0 0.5*/; //Set G values. Note that "i" is converted to double-type. - rectcolorB[i]=Math.random(1.0)* 0.5/*ID:BGain 0.0 1.0 0.5*/; //Set B values. Note that "i" is converted to double-type. - ///- 2.3 loopset2 - - } - - ///+ 2.4 linkto BasicCode3_1a - for(int i=0; i < rectnum; i++){ - rect[i].draw(new Color(rectcolorR[i], rectcolorG[i], rectcolorB[i])); //draw objects by designated colors. - } - window.flip(); - ///- 2.4 linkto BasicCode3_1a - - frame++; - } - ///- 2 drawing -} - ///- Main Routine + Canvas display = new Canvas(768,768); + double rect_size = 100; + double rect_lum = 0.5; + double bg_lum = 0.5; + double size = 250.0; + double sigma; + sigma = size/6.0; + double lambda; + lambda = 6*sigma; + int envelopemode = 0; + double refresh = display.getRefreshRate(); + double[] SF=new double[2]; - } - -} + SF[0]=4.0; + SF[1]=4.0; + double phase=0; -/* -using Psychlops; + double[] initphase = new double[2]; + double _i, _j, _x, _y, _x2, _y2, col; + double amplitude = 1.0; -namespace PsychlopsSilverlight4test -{ + Rectangle fixation1 = new Rectangle(3,9); + Rectangle fixation2 = new Rectangle(9,3); + fixation1.centering(); + fixation2.centering(); + Rectangle contrastrect = new Rectangle(); + contrastrect.set(760,760); - public class PsychlopsMain - { + Image envelope = new Image(); + Psychlops.Color bglum= new Color(0.5,0.5,0.5); + Psychlops.Color masklum = new Color(0.5,0.5,0.5,0.5); - Psychlops.Widgets.Slider rect_size; - Psychlops.Widgets.Slider rect_lum; - Psychlops.Widgets.Slider bg_lum; + Interval rng = new Interval(); - void RectLuminance() - { - Canvas display = new Canvas(Canvas.window); - Interval rng = new Interval(); - rect_size = new Psychlops.Widgets.Slider("Rect Size", 1 < rng < 500, 10.0); - rect_lum = new Psychlops.Widgets.Slider("Rect Luminance", 0.0 <= rng <= 1.0, 0.1); - bg_lum = new Psychlops.Widgets.Slider("BG Luminance", 0.0 <= rng <= 1.0, 0.1); - Ellipse drawee = new Ellipse(100, 100); - display.showFPS(); - display.watchFPS(); + Psychlops.Widgets.Slider TF; + TF = new Psychlops.Widgets.Slider("TF", 0.25<=rng<=2.0 , 0.1); + TF.value=0.75; - Rectangle rect = new Rectangle(rect_size, rect_size); - rect.centering(); - Clock before = new Clock(), after = new Clock(); - while (!Keyboard.esc.pushed()) - { - Display.clear(bg_lum); - rect.resize(rect_size, rect_size).draw(rect_lum); - after.update(); - display.var((after - before).at_msec(), 100, 100, Color.green); - display.var((after - before).at_msec(), 100, 200, Color.green); - drawee.centering().shift(Math.random(100), 0); - drawee.draw(Color.black); - Display.flip(); - } + Psychlops.Widgets.Slider SFs; + SFs = new Psychlops.Widgets.Slider("SF", 4.0<=rng<=16.0 , 4.0); + SFs.value = 4.0; - } + Psychlops.Widgets.Slider contrast; + contrast= new Psychlops.Widgets.Slider("Contrast", 0.0<=rng<=1.0 , 0.1); + contrast.value = 0.1; - public void psychlops_main() - { - RectLuminance(); - } + var element = StaticFunctions.NewArray(2); + for (int i = 0; i < element.Length; i++){ + element[i].setSigma(sigma); // set a size of patch as a halfwidth of Gaussian + element[i].orientation = Math.PI/4.0+Math.PI/2.0*(1-i);//Math.PI/2*(rand()%2);// //set orientations + initphase[i]=0; + } - } -} -*/ + envelope.set(size, size); + envelope.clear(bglum); + for(int i=0; i0){ + envelope.centering().shift(size*0.6,-size*0.6).draw(); + envelope.centering().shift(-size*0.6,size*0.6).draw(); + } + masklum.set(bg_lum, bg_lum, bg_lum, 1-contrast); + contrastrect.centering(); + contrastrect.draw(masklum); + fixation1.centering().shift(size*2,0.0); + fixation1.draw(Color.red); + fixation2.centering().shift(size*2,0.0); + fixation2.draw(Color.red); + Display.var(Mouse.x, 300, 300); + Display.var(Mouse.y, 300, 320); -/* - using Psychlops; + Display.flip(); -namespace PsychlopsSilverlight4test -{ - public class PsychlopsMain - { + } - Psychlops.Canvas cnvs; - int i; - double x, y, z, t, p, temp, xx, yy; +} - //Set Target Initial Value - double TargetEcce = 100.0, TargetSize = 5.0, TargetNumber = 5, Rotate = 0.0; - //Set Background Initial Value - double Axis = 0.0, BGRadii = 150, BGSize = 5.0; - Psychlops.Widgets.Slider thetaSpeed, DotNumber; - Image img; + } +} +/* - public void psychlops_main() - { - cnvs = new Canvas(500, 500); +using Psychlops; +//Position Bias Program +namespace PsychlopsSilverlightApp +{ - Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution); + public class PsychlopsMain + { + Canvas cnvs; + Image img, img2, img3; + int isize = 40; + int frames; + Psychlops.Widgets.Slider tfreq; + Psychlops.Widgets.Slider contrast; + Psychlops.Widgets.Slider lambda; - img = new Image("Resources/logo.png"); + public void psychlops_main() + { + cnvs = new Canvas(300, 600); Interval rng = new Interval(); - thetaSpeed = new Psychlops.Widgets.Slider("Label", -10 <= rng <= 10, 3.0); - DotNumber = new Psychlops.Widgets.Slider("DotNum", 0 <= rng <= 100, 50.0); - - //Declare background dots and target - Rectangle[] BGDot = new Rectangle[2048]; - for(int i=0; i<2048; i++){ - BGDot[i]=new Rectangle(); - } - Rectangle[] Target= new Rectangle[10]; - for(int i=0; i<10; i++){ - Target[i]=new Rectangle(); - } - + tfreq = new Psychlops.Widgets.Slider("Temporal Frequency(Hz)", -5 <= rng <= 5, 3.0); + contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.25); + lambda = new Psychlops.Widgets.Slider("Wave Length", 10.0 <= rng <= 120.0, 30); - //Declare Matrix to keep back ground dots' coordinate value - double[] DotX=new double[2048]; - double[] DotY = new double[2048]; + img = new Image(isize * 2, isize * 2); + img2 = new Image(isize * 2, isize * 2); + img3 = new Image(isize * 2, isize * 2); + var gabor1 = StaticFunctions.NewArray(100); + foreach (var g in gabor1) + { + g.setSigma(isize/8).centering().shift(Math.random(300) - 150, Math.random(600) - 300); + //g.setSize(isize).centering().shift(Math.random(300) - 150, Math.random(600) - 300); + g.orientation = Math.random(2 * Math.PI); + //g.orientation2 = Math.random(2 * Math.PI); + } - //Set Independent variables to manipulate + while (true) + { + cnvs.clear(new Color(0.5)); + Figures.drawGabor(ref img, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60); + Figures.drawGabor(ref img2, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * -tfreq / 60); + Figures.drawGabor(ref img3, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60); - //Initialize positions of background dots - for(int i=0; i<2048; i++){ - t=2.0*Math.PI*Math.random(1.0); - p=2.0*Math.PI*Math.random(1.0); - DotX[i]=t; - DotY[i]=p; - x=BGRadii*Math.cos(t)*Math.cos(p); - y=BGRadii*Math.sin(t)*Math.cos(p); - BGDot[i].set(BGSize, BGSize); - BGDot[i].centering().shift(x,y); - } + //img.centering().shift(0, -isize * 1.5).draw(); + //img2.centering().draw(); + //img3.centering().shift(0, isize * 1.5).draw(); - //Initialize positions of targets - for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize); - - double COS, SIN; - //DotNumber = 200; - //Main stimulus loop - while(true){ - //Clear the main window - cnvs.clear(); - - - temp=Axis/360*2*Math.PI; - COS=Math.cos(temp); - SIN=Math.sin(temp); - - //Calculate positions of background dots and set them - for(int i=0; i 0) let2.draw(); + else let3.draw(); + Display.flip(); } - cnvs.var((double)slider, 200, 200); - dots.draw(); - - cnvs.flip(); } + ///- Main loop + //AppState::setThreadPriority(AppState::NORMAL); + } + ///- Stimulus drawing function + + ///+ Main function for demo circumstances + //// Psychlops Main function + public void psychlops_main() + { + ///+ Demo circumstances + //// Spells for run demonstration circumstances + Procedure p = new Procedure(); + //p.setDesign(Procedure::DEMO); //Designate that this is a demo. + p.setProcedure(RectLuminance); //The argument name is a name of drawing function. + p.run(); + ///- Demo circumstances } + ///- Main function for demo circumstances + } + } -**/ /* +//Two types of plaid motion +//E. H. Adelson and J. A. Movshon (1982). +//Phenomenal coherence of moving visual patterns. Nature 300, 523-525 +///+ Prefix +//// Include Psychlops Package using Psychlops; -namespace PsychlopsSilverlight4test -{ - public class PsychlopsMain + namespace PsychlopsSilverlightApp { - Canvas cnvs; - Rectangle[] rect; - int n; - public void psychlops_main() + public class PsychlopsMain { - n = 1; - cnvs = new Canvas(500, 500); - rect = new Rectangle[n]; - for (int i = 0; i < n; i++) + ///- Prefix + + ///+ Global + // Struct for component paremeters + struct component { - rect[i] = new Rectangle(10, 10); - rect[i].fill = Color.red; + public double contrast; + public double orientation; + public double lambda; + public double tf; } - Interval rng = new Interval(); - var slider = new Psychlops.Widgets.Slider("Label", -100 <= rng <= 100); + ///- Global - while (true) + ///+ Stimulus drawing function + //// A function for stimulus drawing (main body) + void drawgratingmovie(Image[] img, component c1, component c2, double contrast, int start, int maxframe, double bg_lum, double alpha) { - cnvs.clear(); - for (int i = 0; i < n; i++) + double _xp, _xp2, col1, col2; + double contrast1, contrast2; + double imageheight, imagewidth; + + contrast1 = contrast*c1.contrast/(c1.contrast+c2.contrast); + contrast2 = contrast*c2.contrast/(c1.contrast+c2.contrast); + + imageheight = img[0].getHeight(); + imagewidth = img[0].getWidth(); + + for(int frame=start; frame(2, 120); + Image[,] component_movie = StaticFunctions.NewArray(4, 120); + Image envelope = new Image(), envelope_small = new Image(); + + for(int i=0; i<120; i++) { - rect[i].centering().shift(slider * i*3, i*3).draw(); + movie[0, i].set(rect_size, rect_size); + movie[1, i].set(rect_size, rect_size); + component_movie[0, i].set(rect_size/2, rect_size/2); + component_movie[1, i].set(rect_size/2, rect_size/2); + component_movie[2, i].set(rect_size/2, rect_size/2); + component_movie[3, i].set(rect_size/2, rect_size/2); } - cnvs.flip(); + envelope.set(rect_size, rect_size); + envelope_small.set(rect_size/2, rect_size/2); + + Letters let1 = new Letters(), let2 = new Letters(), let3 = new Letters(); + let1.str = "Component1"; + let2.str = "Component2"; + let3.str = "Superposition"; + let1.centering().shift(-rect_size*1.25, -rect_size); + //let1.cache(); + let2.centering().shift(rect_size*1.25, -rect_size); + //let2.cache(); + let3.centering().shift(0.0, rect_size*0.75); + //let3.cache(); + + component c1, c2, c0; + c0 = new component{ 0.0,0.0,1.0,1.0 }; //dummy for component movie + ///+ type-I + // Prepare Type-I plaid movie + center_orientation = 0.0; + orientation_offset = Math.PI/6; + contrast[0] = 1.0, contrast[1] = 1.0; + lambda[0] = 30.0, lambda[1] = 30.0; + tf[0] = 1.0; tf[1] = 1.0; + + c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]}; + c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]}; + + drawgratingmovie(movie[0],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0); + drawgratingmovie(component_movie[0],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0); + drawgratingmovie(component_movie[1],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0); + ///- type-I + + ///+ type-II + // Prepare Type-II plaid movie + center_orientation = -0.0, orientation_offset = Math.PI/12; + contrast[0] = 1.0, contrast[1] = 1.0; + lambda[0] = 30.0, lambda[1] = 30.0; + tf[0] = 1.0; tf[1] = 4.0; + + c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]}; + c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]}; + + drawgratingmovie(movie[1],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0); + drawgratingmovie(component_movie[2],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0); + drawgratingmovie(component_movie[3],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0); + ///- type-II + + ///+ gaussian + //draw Gaussian envelopes + envelope.clear(new Color(bg_lum)); //clear offscreen image + double _x, _y; + for(int i=0; i0){ + movie[movienum, frame].centering().draw(); + envelope.centering().draw(); + component_movie[movienum*2, frame].centering().shift(-rect_size*0.5, -rect_size).draw(); + envelope_small.centering().shift(-rect_size*0.5, -rect_size).draw(); + component_movie[movienum*2+1, frame].centering().shift(rect_size*0.5, -rect_size).draw(); + envelope_small.centering().shift(rect_size*0.5, -rect_size).draw(); + } + + ///+ draw user interface + let1.draw(0.75); + let2.draw(0.75); + let3.draw(0.75); + stimulus_type.draw(); + stimulus_type2.draw(); + if(stimulus_type2.getSelected())duration_slider.draw(); + ///- draw user interface + Display.flip(); + if(frame++ >= period) frame -= refresh_int; + } + ///- Main loop + + } + ///- Stimulus drawing function + + ///+ Main function for demo circumstances + public void psychlops_main() { + ///+ Demo circumstances + //// Spells for run demonstration circumstances + Procedure p = new Procedure(); + //p.setDesign(Procedure::DEMO); //Designate that this is a demo. + p.setProcedure(drawplaid); //The argument name is a name of drawing function. + p.run(); + ///- Demo circumstances } } } - -*/ \ No newline at end of file +*/