From: HOSOKAWA Kenchi Date: Mon, 23 May 2011 20:44:09 +0000 (+0900) Subject: Merge remote branch 'remotes/psychlopssilverlight/master' X-Git-Url: http://git.osdn.jp/view?a=commitdiff_plain;h=e816f42793839d5dc3eb9cf933bbcb8e104d9fdb;hp=0518057c18438b6b749a3845c8eeeb5402ee893b;p=psychlops%2Fsilverlight.git Merge remote branch 'remotes/psychlopssilverlight/master' Conflicts: dev4/Shader/GaborAlpha.ps test4/PsychlopsMain.cs --- diff --git a/dev4/Shader/Gabor.fx b/dev4/Shader/Gabor.fx new file mode 100644 index 0000000..095d01f --- /dev/null +++ b/dev4/Shader/Gabor.fx @@ -0,0 +1,60 @@ +/// Amplitude of Grating +/// 0 +/// 1 +/// 1 +float contrast : register(C1); + +/// Phase of Grating +/// 0 +/// 100 +/// 100 +float frequency: register(C2); + +/// Phase of Grating +/// 0 +/// 6.283184 +/// 0 +float phase: register(C3); + +/// Orientation of Grating +/// 0 +/// 6.283184 +/// 0 +float orientation: register(C4); + +/// Half bandwidth of envelope +/// 2 +/// 8 +/// 4 +float sigma : register(C5); + +/// Transparency of Figure +/// 0 +/// 1 +/// 1 +float alpha : register(C6); + + +float rp(float2 uv) +{ + const float2 Center = float2(0.5,0.5); + float2 dir = uv - Center; // vector from center to pixel + float dist = length(dir); + //dir /= dist; + return dist; +} + +float4 main(float2 uv : TEXCOORD) : COLOR +//float4 main(float2 uv : VPOS ) : COLOR +{ + //float _r = rp(uv)*sigma*4.0; + //float env = exp( -(_r*_r) / 2.0 ) * alpha; + float _r = rp(uv)*8; + float env = exp( -(_r*_r) / (2.0) ) * alpha; + + float _x = sin(orientation)*uv[0]-cos(orientation)*uv[1]; + float l = 0.5+env*contrast*0.5*cos(frequency*_x + phase); + + float4 color = float4(l,l,l,1.0); + return color; +} diff --git a/dev4/Shader/GaborAlpha.ps b/dev4/Shader/GaborAlpha.ps index 1d39b76..cdc54db 100644 Binary files a/dev4/Shader/GaborAlpha.ps and b/dev4/Shader/GaborAlpha.ps differ diff --git a/dev4/Shader/Grating.fx b/dev4/Shader/Grating.fx new file mode 100644 index 0000000..88d73b8 --- /dev/null +++ b/dev4/Shader/Grating.fx @@ -0,0 +1,43 @@ +/// Amplitude of Grating +/// 0 +/// 1 +/// 1 +float contrast : register(C1); + +/// Phase of Grating +/// 0 +/// 100 +/// 100 +float frequency: register(C2); + +/// Phase of Grating +/// 0 +/// 6.283184 +/// 0 +float phase: register(C3); + +/// Orientation of Grating +/// 0 +/// 6.283184 +/// 0 +float orientation: register(C4); + + +float rp(float2 uv) +{ + const float2 Center = float2(0.5,0.5); + float2 dir = uv - Center; // vector from center to pixel + float dist = length(dir); + //dir /= dist; + return dist; +} + +float4 main(float2 uv : TEXCOORD) : COLOR +{ + float _x = sin(orientation)*uv[0]-cos(orientation)*uv[1]; + float l = 0.5 + + contrast*0.5*cos(frequency*_x + phase); + + float4 color = float4(l,l,l,1.0); + return color; +} diff --git a/dev4/Shader/Grating.ps b/dev4/Shader/Grating.ps new file mode 100644 index 0000000..1d39b76 Binary files /dev/null and b/dev4/Shader/Grating.ps differ diff --git a/dev4/Shader/Plaid.fx b/dev4/Shader/Plaid.fx new file mode 100644 index 0000000..e8635d1 --- /dev/null +++ b/dev4/Shader/Plaid.fx @@ -0,0 +1,69 @@ +/// Amplitude of Grating +/// 0 +/// 1 +/// 0.5 +float contrast : register(C1); + +/// Phase of Grating +/// 0 +/// 100 +/// 100 +float frequency: register(C2); + +/// Phase of Grating +/// 0 +/// 6.283184 +/// 0 +float phase: register(C3); + +/// Orientation of Grating +/// 0 +/// 6.283184 +/// 0 +float orientation: register(C4); + +/// Amplitude of Grating2 +/// 0 +/// 1 +/// 0.5 +float contrast2 : register(C5); + +/// Phase of Grating2 +/// 0 +/// 100 +/// 100 +float frequency2: register(C6); + +/// Phase of Grating2 +/// 0 +/// 6.283184 +/// 0 +float phase2: register(C7); + +/// Orientation of Grating2 +/// 0 +/// 6.283184 +/// 0.785398 +float orientation2: register(C8); + + +float rp(float2 uv) +{ + const float2 Center = float2(0.5,0.5); + float2 dir = uv - Center; // vector from center to pixel + float dist = length(dir); + //dir /= dist; + return dist; +} + +float4 main(float2 uv : TEXCOORD) : COLOR +{ + float _x1 = sin(orientation)*uv[0]-cos(orientation)*uv[1]; + float _x2 = sin(orientation2)*uv[0]-cos(orientation2)*uv[1]; + float l = 0.5 + + contrast*0.5*cos(frequency*_x1 + phase) + + contrast2*0.5*cos(frequency2*_x2 + phase2); + + float4 color = float4(l,l,l,1.0); + return color; +} diff --git a/dev4/Shader/Plaid.ps b/dev4/Shader/Plaid.ps new file mode 100644 index 0000000..31eee86 Binary files /dev/null and b/dev4/Shader/Plaid.ps differ diff --git a/test4/PsychlopsMain.cs b/test4/PsychlopsMain.cs index 4cfe448..7a79979 100644 --- a/test4/PsychlopsMain.cs +++ b/test4/PsychlopsMain.cs @@ -1,4 +1,319 @@ - +/* +///+ Prefix linkto BasicCode1 +//// Lines for set up Psychlops environment +using Psychlops; + +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 SetGlobal + ////Prepare global parameters + Rectangle p1 = new Rectangle(1,1); + Color col1 = new Color(); + double width=50; + double height=10; + double lambda=60; + double lmean=0.25, contrast = 0.5; + double x0 = 0; + double y0 = 0; + double pitch = 1; + Canvas disp = new Canvas(Canvas.window, Display.secondary); + + var fieldW_ = Psychlops.Widgets.Browser.Element.byID("fieldW"); + var fieldH_ = Psychlops.Widgets.Browser.Element.byID("fieldH"); + var wL_ = Psychlops.Widgets.Browser.Element.byID("wL"); + var Cont_ = Psychlops.Widgets.Browser.Element.byID("Cont"); + var ix_ = Psychlops.Widgets.Browser.Element.byID("ix"); + var iy_ = Psychlops.Widgets.Browser.Element.byID("iy"); + var gap_ = Psychlops.Widgets.Browser.Element.byID("gap"); + ///- 0 SetGlobal + + ///+ 1 Initialize + ////initialize + p1.centering().shift(-width*0.5 + x0, -height*0.5 + y0); //Move a point to the initial position. + ///- 1 Initialize + + ///+ 2 Drawing + ////drawing objects + for(int i=0; i < width; i++) + { + col1.set(lmean*((contrast*Math.sin((2*Math.PI*i/lambda)))+1)); //Set a color. + + ///+ 2.1 Drawing a column + ////drawing a column + for(int j=0;j < height; j++) + { + p1.draw(col1); + p1.shift(0, pitch); + } + ///- 2.1 Drawing a column + + p1.shift(1, -height * pitch); //back to vertical intitial point after drawing one column. + } + disp.flip(); + ///- 2 Drawing + + while (!Keyboard.spc.pushed()) { }; //Wait until space key is pressed. + } + + + } + +} + * */ + + +/* +///+ Prefix +//// Lines for set up Psychlops environment +using Psychlops; + +namespace PsychlopsSilverlightApp +{ + + public class PsychlopsMain + {///- Prefix + + + + ///+ Main Routine + //// Psychlops runs at the first line of this function psychlops_main(). + public void psychlops_main() + { + Canvas window = new Canvas(300, 300); //Create a window. Here, window variables are preset mode. + + var FIGURE = Psychlops.Widgets.Browser.Element.byID("FIGURE"); + var SIZE_X_ = Psychlops.Widgets.Browser.Element.byID("SIZE_X"); + var SIZE_Y_ = Psychlops.Widgets.Browser.Element.byID("SIZE_Y"); + var COLOR_R = Psychlops.Widgets.Browser.Element.byID("COLOR_R"); + var COLOR_G = Psychlops.Widgets.Browser.Element.byID("COLOR_G"); + var COLOR_B = Psychlops.Widgets.Browser.Element.byID("COLOR_B"); + var COLOR_BG = Psychlops.Widgets.Browser.Element.byID("COLOR_BG"); + var Period_Size = Psychlops.Widgets.Browser.Element.byID("Period_Size"); + var Period_Position = Psychlops.Widgets.Browser.Element.byID("Period_Position"); + var Speed_HSize_ = Psychlops.Widgets.Browser.Element.byID("Speed_HSize"); + var Speed_VSize = Psychlops.Widgets.Browser.Element.byID("Speed_VSize"); + var Speed_VMotion = Psychlops.Widgets.Browser.Element.byID("Speed_VMotion"); + double SIZE_X = SIZE_X_, SIZE_Y = SIZE_Y_; + + ///+ 2 + //// Set a figure size, position and color. + Rectangle figure = new Rectangle(); + Ellipse figure2 = new Ellipse(); + figure.set(SIZE_X_, SIZE_Y_); // Set the size of figure. + figure2.set(SIZE_X_, SIZE_Y_); // Set the size of figure. + figure.centering().shift(0, 0); // Move the figure to the starting point. + figure2.centering().shift(0, 0); // Move the figure to the starting point. + ///- 2 + + int frame = 0; + int looming_direction = 1, motion_dir = 1; + double direction = 1.0; + //looming_direction is a variable for size change. + //motion_dir is a variable for motion direction. + ///+ 3 Drawing loop + //// Draw each frames in a "while loop". + while (!Keyboard.esc.pushed()) + { //exit a program when the escape key is pressed down. + window.clear(COLOR_BG); // Clear the window with a designated gray-scale level. + + ///+ 3.1 + //// Calculate object's position and size for each frame. + + if (frame % Period_Size == 0) + { // a direction of size change will reverse at designated frames. + looming_direction = looming_direction * -1; + } + + if (frame % Period_Position == 0) + { // motion direction will reverse at designated frames. + motion_dir *= -1; + } + + ///- 3.1 + + ///+ 3.2 + //// Settting figure's properties + figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction". + figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction". + figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". + figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction". + figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction". + figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". + /* + figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction". + figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction". + figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". + figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction". + figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction". + figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". + * * / + ///- 3.2 + + ///+ 3.3 + ////Drawing + if ("Rectangle".Equals(FIGURE)) + { + figure.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position. + } + else + { + figure2.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position. + } + window.flip(); // Reflect the drawing for the display by flipping frame buffers. + ///- 3.3 + + ///+ 3.4 + ////make a step for next frames + frame++; + ///- 3.4 + } + ///- 3 Drawing loop + + } + ///- Main Routine + + + } + +} + + + +/* +//The reversed-phi motion. +//Anstis (1970) +//Phi movement as a subtraction process. Vision Res 10:1411?1430 + +///+ Prefix +//// Include Psychlops Package +using Psychlops; + +namespace PsychlopsSilverlightApp +{ + + public class PsychlopsMain + { + + ///- Prefix + + ///+ Stimulus drawing function + //// A function for stimulus drawing (main body) + void RectLuminance() + { + + ///+ Preperation + //// Declare and initialize local variables + double rect_size = 20; + + double bg_lum = 0.5; + double radii = 200; + double rect_lum; + int element_number = 25; + int radial_row = 5; + + double rotation_tf = 0.2; + double polarity = 1; + double rotation; + + double contrastflag = 1; + int period = 3; + double refresh; + + Canvas display = new Canvas(Canvas.window); //Prepare drawing window + refresh = Display.getRefreshRate(); + + Ellipse rect = new Ellipse(); + rect.set(rect_size, rect_size); + + Ellipse fixation = new Ellipse(5, 5); + fixation.centering(); + + Letters let1 = new Letters("Press Space key to change stimulus type"); + let1.centering().shift(-180, 220); + Letters let2 = new Letters("Phi"); + let2.centering().shift(-10, 200); + Letters let3 = new Letters("Reversed-Phi"); + let3.centering().shift(-60, 200); + + rotation = Math.random(2 * Math.PI); + + ///+ user interface + ////register variables to demo circumstances + Interval rng = new Interval(); + + Psychlops.Widgets.Slider rect_contrast; + rect_contrast = new Psychlops.Widgets.Slider("Contrast", 0.1 <= rng <= 1.0, 0.1); + rect_contrast.value = 0.5; + ///- user interface + ///- Preperation + + ///+ Main loop + ////Main loop + int frame = 0; + //AppState::setThreadPriority(AppState::HIGH); + while (true) + { + frame++; + if (Keyboard.spc.pushed()) contrastflag = -contrastflag; + if (contrastflag < 0) polarity = -polarity; + rotation = 2 * Math.PI * rotation_tf * frame * period / refresh; + + for (int frame_now = 0; frame_now < period; frame_now++) + { + Display.clear(new Color(bg_lum)); + for (int j = 0; j < radial_row; j++) + { + rect.resize(rect_size * (j + radial_row) / 10.0, rect_size * (j + radial_row) / 10.0); + for (double i = 0; i < element_number; i++) + { + rect_lum = bg_lum * (1.0 + polarity * rect_contrast); + 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)); + rect.draw(rect_lum); + } + } + fixation.draw(Color.red); + let1.draw(); + if (contrastflag > 0) let2.draw(); + else let3.draw(); + Display.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). @@ -257,7 +572,11 @@ namespace PsychlopsSilverlightApp img2 = new Image(isize * 2, isize * 2); img3 = new Image(isize * 2, isize * 2); +<<<<<<< HEAD + var gabor1 = StaticFunctions.NewArray(100); +======= var gabor1 = StaticFunctions.NewArray(100); +>>>>>>> remotes/psychlopssilverlight/master foreach(var g in gabor1) { g.setSigma(isize / 8).centering().shift(Math.random(300) - 150, Math.random(600) - 300);