From 995fc1b91f005c8ca430dd8f2bcca0d676907f06 Mon Sep 17 00:00:00 2001 From: HOSOKAWA Kenchi Date: Wed, 4 Apr 2012 00:22:53 +0900 Subject: [PATCH] 12 --- dev5/psychlops/core/math/matrix.cs | 15 ++++ test5/PsychlopsMain.cs | 143 ++++++++++++++++++++++++++++++++++++- 2 files changed, 157 insertions(+), 1 deletion(-) diff --git a/dev5/psychlops/core/math/matrix.cs b/dev5/psychlops/core/math/matrix.cs index de4a836..4d011e5 100644 --- a/dev5/psychlops/core/math/matrix.cs +++ b/dev5/psychlops/core/math/matrix.cs @@ -6,6 +6,11 @@ namespace Psychlops public abstract class Matrix { + public static Matrix gen(int row, int col) + { + return new Internal.MatrixImplementation(row, col); + } + public abstract double this[int row, int col] { get; @@ -26,6 +31,16 @@ namespace Psychlops return new Internal.MatrixExpression(); } */ + public void each(Func f) + { + for (int i = 1; i <= getRows(); i++) + { + for (int j = 1; j <= getCols(); j++) + { + this[i, j] = f(this[i, j]); + } + } + } public abstract int rows { get; } public abstract int cols { get; } diff --git a/test5/PsychlopsMain.cs b/test5/PsychlopsMain.cs index f1d7bb8..4242429 100644 --- a/test5/PsychlopsMain.cs +++ b/test5/PsychlopsMain.cs @@ -1,4 +1,143 @@ -//Psychlops Code Template +// Motion with glass patterns. +// Ross, J., Badcock, D. R., and Hayes, A. (2000) +// Coherent global motion in the absence of coherent velocity signals. +// Current Biology, 10, 679-682. +///+ Prefix +//// Include Psychlops Package +using Psychlops; + +namespace PsychlopsSilverlightApp +{ + + public class PsychlopsMain + { + Psychlops.Widgets.Slider distance, duration, stimulus_type; + ///- Prefix + + public void psychlops_main() + { + GlassPattern(); + } + + readonly int DOTNUM = 512; + + ///+ Stimulus drawing function + //// A function for stimulus drawing (main body) + void GlassPattern() { + + ///+ Preperation + //// Declare and initialize local variables + Canvas cnvs = new Canvas(400,400); //Prepare drawing window + double dotsize = 2; + double dot_lum = 0.5; + double bg_lum = 0.2; + double fieldsize = 300; + double[] orientation = new double[DOTNUM]; + Rectangle dots = new Rectangle(dotsize, dotsize); + ///+ prepare dots position + //// prepare dots position and paired orientation + Matrix positionmat = Matrix.gen(DOTNUM,2); + //Math.random(positionmat, -0.5*fieldsize, 0.5*fieldsize); + positionmat.each( (v) => Math.random(-0.5*fieldsize, 0.5*fieldsize) ); + + + for(int i=0; i duration) + { + //Math.random(positionmat, -0.5 * fieldsize, 0.5 * fieldsize); + positionmat.each((v) => Math.random(-0.5 * fieldsize, 0.5 * fieldsize)); + for (int i = 0; i < DOTNUM; i++) { orientation[i] = Math.atan2(positionmat[i + 1, 2], positionmat[i + 1, 1]); } + frame = 0; + } + ///- position change + Display.clear(new Color(bg_lum)); //Clear window + + //// Draw DOTNUM pairs of dots + for(int i=0; i