• R/O
  • HTTP
  • SSH
  • HTTPS

silverlight: Commit

psychlops silverlight


Commit MetaInfo

Revision995fc1b91f005c8ca430dd8f2bcca0d676907f06 (tree)
Time2012-04-04 00:22:53
AuthorHOSOKAWA Kenchi <hskwk@user...>
CommiterHOSOKAWA Kenchi

Log Message

12

Change Summary

Incremental Difference

--- a/dev5/psychlops/core/math/matrix.cs
+++ b/dev5/psychlops/core/math/matrix.cs
@@ -6,6 +6,11 @@ namespace Psychlops
66
77 public abstract class Matrix
88 {
9+ public static Matrix gen(int row, int col)
10+ {
11+ return new Internal.MatrixImplementation(row, col);
12+ }
13+
914 public abstract double this[int row, int col]
1015 {
1116 get;
@@ -26,6 +31,16 @@ namespace Psychlops
2631 return new Internal.MatrixExpression();
2732 }
2833 */
34+ public void each(Func<double, double> f)
35+ {
36+ for (int i = 1; i <= getRows(); i++)
37+ {
38+ for (int j = 1; j <= getCols(); j++)
39+ {
40+ this[i, j] = f(this[i, j]);
41+ }
42+ }
43+ }
2944
3045 public abstract int rows { get; }
3146 public abstract int cols { get; }
--- a/test5/PsychlopsMain.cs
+++ b/test5/PsychlopsMain.cs
@@ -1,4 +1,143 @@
1-//Psychlops Code Template
1+// Motion with glass patterns.
2+// Ross, J., Badcock, D. R., and Hayes, A. (2000)
3+// Coherent global motion in the absence of coherent velocity signals.
4+// Current Biology, 10, 679-682.
5+///+ Prefix
6+//// Include Psychlops Package
7+using Psychlops;
8+
9+namespace PsychlopsSilverlightApp
10+{
11+
12+ public class PsychlopsMain
13+ {
14+ Psychlops.Widgets.Slider distance, duration, stimulus_type;
15+ ///- Prefix
16+
17+ public void psychlops_main()
18+ {
19+ GlassPattern();
20+ }
21+
22+ readonly int DOTNUM = 512;
23+
24+ ///+ Stimulus drawing function
25+ //// A function for stimulus drawing (main body)
26+ void GlassPattern() {
27+
28+ ///+ Preperation
29+ //// Declare and initialize local variables
30+ Canvas cnvs = new Canvas(400,400); //Prepare drawing window
31+ double dotsize = 2;
32+ double dot_lum = 0.5;
33+ double bg_lum = 0.2;
34+ double fieldsize = 300;
35+ double[] orientation = new double[DOTNUM];
36+ Rectangle dots = new Rectangle(dotsize, dotsize);
37+ ///+ prepare dots position
38+ //// prepare dots position and paired orientation
39+ Matrix positionmat = Matrix.gen(DOTNUM,2);
40+ //Math.random(positionmat, -0.5*fieldsize, 0.5*fieldsize);
41+ positionmat.each( (v) => Math.random(-0.5*fieldsize, 0.5*fieldsize) );
42+
43+
44+ for(int i=0; i<DOTNUM; i++){orientation[i] = Math.atan2(positionmat[i+1,2], positionmat[i+1,1]);}
45+ ///- prepare dots position
46+
47+
48+ ///+ Draw Gaussian Envelope
49+ ////Draw offscreen Gaussian Envelope
50+ Image envelope = new Image(fieldsize+100, fieldsize+100);
51+ envelope.clear(new Color(bg_lum)); //clear offscreen image
52+ double _x, _y;
53+ for(int i=0; i<fieldsize+100; i++){
54+ _x=i-0.5*fieldsize-50;
55+ for(int j=0; j<fieldsize+100; j++){
56+ _y=j-0.5*fieldsize-50;
57+ envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*Math.pow(fieldsize/6.0, 2.0) ))));
58+ }
59+ }
60+ envelope.cache();
61+ ///- Draw Gaussian Envelope
62+ ///+ set Independent
63+ //// set variables and value ranges for interaction
64+ Interval rng = new Interval();
65+ stimulus_type = new Psychlops.Widgets.Slider("Stimulus Type", 0.0 <= rng <= 2.0, 1, 1);
66+ stimulus_type.setValue(0);
67+ distance = new Psychlops.Widgets.Slider("distance between pairs", 1 <= rng <= 100, 1, 1);
68+ distance.setValue(3.0);
69+ duration = new Psychlops.Widgets.Slider("Refresh", 0.0 <= rng <= 10.0, 1, 1);
70+ duration.setValue(10);
71+ ///- set Independent
72+
73+ int frame = 0;
74+ while(!Keyboard.esc.pushed()) {
75+ ///+ position change
76+ //// Re-randomize position with a desingated interval
77+ if(frame > duration)
78+ {
79+ //Math.random(positionmat, -0.5 * fieldsize, 0.5 * fieldsize);
80+ positionmat.each((v) => Math.random(-0.5 * fieldsize, 0.5 * fieldsize));
81+ for (int i = 0; i < DOTNUM; i++) { orientation[i] = Math.atan2(positionmat[i + 1, 2], positionmat[i + 1, 1]); }
82+ frame = 0;
83+ }
84+ ///- position change
85+ Display.clear(new Color(bg_lum)); //Clear window
86+
87+ //// Draw DOTNUM pairs of dots
88+ for(int i=0; i<DOTNUM; i++){
89+ ///+ draw first dots
90+
91+ ///+ switch stimulus type
92+ //// draw the second dots to generate selected stimulu type.
93+ switch((int)stimulus_type){
94+ ///+ case rotation
95+ //// Rotation
96+ case 0:
97+ dots.centering().shift(positionmat[i+1,1],positionmat[i+1,2]); // move to center position
98+ dots.shift(-0.5*distance*Math.cos(orientation[i]+0.5*Math.PI),-0.5*distance*Math.sin(orientation[i]+0.5*Math.PI));// move to the first position
99+ dots.draw(new Color(dot_lum)); // draw first dot
100+ dots.shift(distance*Math.cos(orientation[i]+0.5*Math.PI),distance*Math.sin(orientation[i]+0.5*Math.PI));// move to the second position
101+ //cnvs.msg("Rotation", cnvs.getCenter().x, cnvs.getHeight() - 20);
102+ break;
103+ ///- case rotation
104+ ///+ case diversion
105+ ////Diversion
106+ case 1:
107+ dots.centering().shift(positionmat[i+1,1],positionmat[i+1,2]);// move to center position
108+ dots.shift(-0.5*distance*Math.cos(orientation[i]+0.5*Math.PI),-0.5*distance*Math.sin(orientation[i]+0.5*Math.PI));// move to the first position
109+ dots.draw(new Color(dot_lum));// draw first dot
110+ dots.shift(distance*Math.cos(orientation[i]),distance*Math.sin(orientation[i]));// move to the second position
111+ break;
112+ ///- case diversion
113+ ///+ case spiral
114+ //// Spiral
115+ case 2:
116+ dots.centering().shift(positionmat[i+1,1],positionmat[i+1,2]);// move to center position
117+ dots.shift(-0.5*distance*Math.cos(orientation[i]+0.5*Math.PI),-0.5*distance*Math.sin(orientation[i]+0.5*Math.PI));// move to the first position
118+ dots.draw(new Color(dot_lum));// draw first dot
119+ dots.shift(distance*Math.cos(orientation[i]+0.25*Math.PI),distance*Math.sin(orientation[i]+0.25*Math.PI));// move to the second position
120+ break;
121+ ///- case spiral
122+ }
123+ ///- switch stimulus type
124+
125+ dots.draw(new Color(dot_lum)); // Draw dots at a desinated position.
126+ }
127+ ///- Draw dots
128+ envelope.centering().draw(); //Draw offscreen Gaussian onto screen
129+ Display.flip(); // Flip frame buffers
130+ frame++;
131+ }
132+ }
133+ }
134+}
135+
136+
137+
138+
139+/*
140+ * //Psychlops Code Template
2141 // Please visit following web site to get sample codes.
3142 // http://psychlops.sourceforge.jp/ja/?StartCode
4143 // CodeDresser at following address is also available to view the code.
@@ -117,6 +256,8 @@ namespace PsychlopsSilverlightApp
117256
118257 }
119258
259+*/
260+
120261 /*
121262 public void psychlops_main() {
122263
Show on old repository browser