{\r
polygonStack[i] = new Polygon();\r
lettersStack[i] = new Letters();\r
- //imageStack[i] = new Image();\r
+ imageStack[i] = new Image(1,1);\r
}\r
}\r
\r
\r
public virtual void line(Line drawee)\r
{\r
-// stack.Enqueue(drawee.clone());\r
+ // stack.Enqueue(drawee.clone());\r
+ drawee.copyToStack(this);\r
}\r
\r
public virtual void rect(Rectangle drawee)\r
internal int ellipsePoolN;\r
internal System.Windows.Shapes.Polygon[] polygonPool;\r
internal int polygonPoolN;\r
+ internal System.Windows.Controls.TextBlock[] lettersPool;\r
+ internal int lettersPoolN;\r
+ internal System.Windows.Controls.Image[] imagePool;\r
+ internal int imagePoolN;\r
\r
#region initializer\r
\r
api_canvas = apicnvs;\r
initialize(wid, hei);\r
}\r
+\r
+ protected bool AsyncInitBool;\r
protected void initialize(int wid, int hei)\r
{\r
+ AsyncInitBool = false;\r
width_ = wid;\r
height_ = hei;\r
api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei);\r
+ while(!AsyncInitBool)\r
+ {\r
+ }\r
Mouse._prime = api_canvas;\r
Main.drawable = this;\r
Main.canvas = this;\r
brushPool = new SolidColorBrush[10000];\r
linePool = new System.Windows.Shapes.Line[10000];\r
rectPool = new System.Windows.Shapes.Rectangle[10000];\r
+ ellipsePool = new System.Windows.Shapes.Ellipse[10000];\r
for (int i = 0; i < 10000; i++)\r
{\r
pointPool[i] = new System.Windows.Point();\r
brushPool[i] = new SolidColorBrush();\r
linePool[i] = new System.Windows.Shapes.Line();\r
rectPool[i] = new System.Windows.Shapes.Rectangle();\r
+ ellipsePool[i] = new System.Windows.Shapes.Ellipse();\r
}\r
- for (int i = 0; i < 300; i++)\r
+ polygonPool = new System.Windows.Shapes.Polygon[1000];\r
+ lettersPool = new System.Windows.Controls.TextBlock[1000];\r
+ for (int i = 0; i < 1000; i++)\r
{\r
- api_canvas.Children.Add(rectStack[i].poolNative(this));\r
- api_canvas.Children.Add(rectStack[i].poolNative(this));\r
+ polygonPool[i] = new System.Windows.Shapes.Polygon();\r
+ lettersPool[i] = new System.Windows.Controls.TextBlock();\r
}\r
\r
masterPool = new System.Windows.Controls.Canvas();\r
prevPool = new System.Windows.Controls.Canvas();\r
-// masterPool.Children.Add()\r
+ api_canvas.Children.Add(masterPool);\r
+ //api_canvas.Children.Remove(Internal.Main.widgetStack);\r
+\r
+ AsyncInitBool = true;\r
}\r
\r
#endregion\r
public override void clear(Color col)\r
{\r
back_panel.fill = col;\r
-// stack.Clear();\r
stackN = 0;\r
rect(back_panel);\r
}\r
\r
int nextIntervalFrame = 1, chacked = 0;\r
- /*\r
- public void flip()\r
+ public void flip(int n)\r
{\r
- //api_canvas.Dispatcher.BeginInvoke(flipexec);\r
- //flipexec();\r
- //System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);\r
- lock (this)\r
- {\r
- nextIntervalFrame = 1;\r
- chacked = 1;\r
- }\r
-// pointPoolN = 0;\r
-// brushPoolN = 0;\r
-// linePoolN = 0;\r
- rectPoolN = 0;\r
- lineStackN = 0;\r
- rectStackN = 0;\r
- Internal.Main.canvas_flag.WaitOne();\r
+ flip();\r
}\r
- public void executeFlip()\r
- {\r
- lock (this)\r
- {\r
- nextIntervalFrame--;\r
- }\r
- if (nextIntervalFrame <= 0)\r
- {\r
- var rr = new Random();\r
- //Psychlops.AppState.statusBar = chacked.ToString();\r
- if (chacked > 0)\r
- {\r
- // prevPool.Children.Clear();\r
- var tmp = new System.Windows.Controls.Canvas();\r
- if (stack.Count > 0)\r
- // if (stackN > 0)\r
- {\r
- //foreach (UIElement e in api_canvas.Children)\r
- //{\r
- //}\r
-// foreach (Internal.PrimitiveFigure f in stack)\r
- for (int i = 0; i < stackN - 2; i++)\r
- {\r
- // tmp.Children.Add(f.toNative());\r
-// tmp.Children.Add(f.poolNative(this));\r
- tmp.Children.Add(stack[i].poolNative(this));\r
- // System.Windows.Controls.Canvas.SetLeft(api_canvas.Children[i + 1], rectStack[i].left);\r
- // api_canvas.Children[0] = api_canvas.Children[0];\r
- }\r
- stackN = 0;\r
-\r
- }\r
- api_canvas.Children.Clear();\r
- api_canvas.Children.Add(tmp);\r
- // stack.Clear();\r
- lock (this)\r
- {\r
- chacked = 0;\r
- }\r
- Psychlops.Internal.Main.canvas_flag.Set();\r
- // prevPool = tmp;\r
- }\r
- }\r
- System.Threading.Thread.Sleep(0);\r
- }\r
- */\r
-\r
public void flip()\r
{\r
lock (this)\r
}\r
// pointPoolN = 0;\r
// brushPoolN = 0;\r
- // linePoolN = 0;\r
+ linePoolN = 0;\r
rectPoolN = 0;\r
lineStackN = 0;\r
rectStackN = 0;\r
+ polygonStackN = 0;\r
+ ellipseStackN = 0;\r
+ lettersStackN = 0;\r
+ imageStackN = 0;\r
+\r
+ pointPoolN = 0;\r
+ brushPoolN = 0;\r
+ linePoolN = 0;\r
+ rectPoolN = 0;\r
+ ellipsePoolN = 0;\r
+ polygonPoolN = 0;\r
+ lettersPoolN = 0;\r
+ imagePoolN = 0;\r
+\r
Internal.Main.canvas_flag.WaitOne();\r
}\r
public void executeFlip()\r
{\r
if (chacked > 0)\r
{\r
- //api_canvas.Children.Clear();\r
- //var tmp = new System.Windows.Controls.Canvas();\r
+ masterPool.Children.Clear();\r
if (stackN > 0)\r
{\r
for (int i = 0; i < stackN - 2; i++)\r
{\r
- //api_canvas.Children.Add(stack[i].poolNative(this));\r
- api_canvas.Children.Add(stack[i].poolNative(this));\r
+ masterPool.Children.Add(stack[i].poolNative(this));\r
}\r
stackN = 0;\r
}\r
- //api_canvas.Children.Clear();\r
- //api_canvas.Children.Add(tmp);\r
lock (this)\r
{\r
chacked = 0;\r
}\r
public UIElement toNative() { return this; }\r
\r
+ public void copyToStack(Templates.StackableDrawable d)\r
+ {\r
+ var tmp = d.lineStack[d.lineStackN];\r
+ tmp.begin.x = begin.x;\r
+ tmp.begin.y = begin.y;\r
+ tmp.end.x = end.x;\r
+ tmp.end.y = end.y;\r
+ tmp.fill = fill;\r
+ tmp.stroke = stroke;\r
+ d.stack[d.stackN] = tmp;\r
+ d.lineStackN++;\r
+ d.stackN++;\r
+ }\r
public UIElement poolNative(Canvas d)\r
{\r
var tmp = d.linePool[d.linePoolN];\r
tmp.ydiameter = ydiameter;\r
tmp.fill = fill;\r
d.stack[d.stackN] = tmp;\r
- d.rectStackN++;\r
+ d.ellipseStackN++;\r
d.stackN++;\r
}\r
public UIElement poolNative(Canvas d)\r
System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
tmp.Visibility = Visibility.Visible;\r
d.ellipsePoolN++;\r
- return this;\r
+ return tmp;\r
}\r
}\r
\r
}\r
tmp.fill = fill;\r
d.stack[d.stackN] = tmp;\r
- d.rectStackN++;\r
+ d.polygonStackN++;\r
d.stackN++;\r
}\r
public UIElement poolNative(Canvas d)\r
{\r
var tmp = d.polygonPool[d.polygonPoolN];\r
tmp.Fill = fill;\r
- /*\r
- System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
- System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
- */ \r
+ tmp.Points.Clear();\r
+ foreach (var v in vertices)\r
+ {\r
+ tmp.Points.Add(v);\r
+ }\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+ System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y);\r
tmp.Visibility = Visibility.Visible;\r
d.polygonPoolN++;\r
- return this;\r
+ return tmp;\r
}\r
\r
}\r
\r
public void copyToStack(Templates.StackableDrawable d)\r
{\r
- var tmp = d.polygonStack[d.polygonStackN];\r
+ var tmp = d.lettersStack[d.lettersStackN];\r
+ tmp.str = str;\r
tmp.datum = datum;\r
tmp.fill = fill;\r
d.stack[d.stackN] = tmp;\r
- d.rectStackN++;\r
+ d.lettersStackN++;\r
d.stackN++;\r
}\r
public UIElement poolNative(Canvas d)\r
{\r
- /* var tmp = d.rectPool[d.rectPoolN];\r
- tmp.Width = width;\r
- tmp.Height = height;\r
- tmp.Fill = fill;\r
- System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
- System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
- tmp.Visibility = Visibility.Visible;\r
- d.rectPoolN++;\r
-*/\r
- return this;\r
+ var tmp = d.lettersPool[d.lettersPoolN];\r
+ tmp.Text = str;\r
+ tmp.Width = 500;\r
+ tmp.Height = 500;\r
+ tmp.FontSize = font.size;\r
+ //tmp.FontFamily = ,\r
+ tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];\r
+ tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];\r
+ tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];\r
+ tmp.Foreground = fill;\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+ System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y);\r
+ tmp.Visibility = Visibility.Visible;\r
+ d.lettersPoolN++;\r
+ return tmp;\r
}\r
}\r
\r
internal void create__(int wid, int hei)\r
{\r
buffer = new WriteableBitmap(wid, hei);\r
+ AsyncBool = true;\r
}\r
delegate void FieldFunc1(System.Func<int, int, System.Windows.Media.Color> func);\r
delegate void FieldFunc2(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func);\r
}\r
public UIElement toNative() { return this; }\r
\r
+ public void copyToStack(Templates.StackableDrawable d)\r
+ {\r
+ var tmp = d.imageStack[d.imageStackN];\r
+ tmp.datum = datum;\r
+ tmp.buffer = buffer;\r
+ tmp.self_rect = self_rect;\r
+ d.stack[d.stackN] = tmp;\r
+ d.imageStackN++;\r
+ d.stackN++;\r
+ }\r
public UIElement poolNative(Canvas d)\r
{\r
- /* var tmp = d.rectPool[d.rectPoolN];\r
- tmp.Width = width;\r
- tmp.Height = height;\r
- tmp.Fill = fill;\r
- System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
- System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
- tmp.Visibility = Visibility.Visible;\r
- d.rectPoolN++;\r
-*/\r
+ var tmp = d.imagePool[d.imagePoolN];\r
+ tmp.Source = buffer;\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+ System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y);\r
+ tmp.Visibility = Visibility.Visible;\r
+ d.rectPoolN++;\r
return this;\r
}\r
\r
\r
public static class Math\r
{\r
- public static readonly double PI = 3.14159265, E = 2.718281828459045;\r
+ public static readonly double PI = 3.14159265, E = 2.718281828459045, LOG2E = 1.44269504088896340736;\r
public static Random random_generator;\r
static Math()\r
{\r
random_generator = new Random();\r
}\r
\r
+ public static double max(double val1, double val2)\r
+ {\r
+ return val1 > val2 ? val1 : val2;\r
+ }\r
+ public static double min(double val1, double val2)\r
+ {\r
+ return val1 < val2 ? val1 : val2;\r
+ }\r
+ public static void shuffle<X>(X[] array, int n)\r
+ {\r
+ int a;\r
+ X tmp;\r
+ for(int i = 1; i < n; i++){\r
+ a = random(i + 1);\r
+ tmp = array[i];\r
+ array[i] = array[a];\r
+ array[a] = tmp;\r
+ }\r
+ }\r
+\r
+\r
+ public static double mod(double lhs, double rhs)\r
+ {\r
+ return lhs - System.Math.Floor(lhs/rhs)*rhs;\r
+ }\r
public static double abs(double x)\r
{\r
return System.Math.Abs(x);\r
{\r
return System.Math.Log(x);\r
}\r
+ public static double log2(double val)\r
+ {\r
+ return log(val) * LOG2E;\r
+ }\r
+ /*public static int round(double val)\r
+ {\r
+ double integer_part, particle = modf(val, &integer_part);\r
+ return ((particle < 0.5 | (particle == 0.5 && (int)integer_part % 2 == 0)) ? (int)integer_part : (int)integer_part + 1);\r
+ }*/\r
+\r
public static double radius(double x, double y)\r
{\r
return System.Math.Sqrt(x * x + y * y);\r
{\r
return (random_generator.NextDouble());\r
}\r
+ public static int random(int x)\r
+ {\r
+ return (int)((random_generator.NextDouble()) * x);\r
+ }\r
public static double random(double x)\r
{\r
return (random_generator.NextDouble()) * x;\r
-\r
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlight4test\r
+{\r
+\r
+ public class PsychlopsMain\r
+ {\r
+\r
+ Canvas cnvs;\r
+ int i;\r
+ object xxx;\r
+ double x, y, z, t, p, temp, xx, yy;\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 DotNumber = 50, thetaSpeed = 3.0, Axis = 0.0, BGRadii = 150, BGSize = 5.0;\r
+ Psychlops.Widgets.Slider DotNumberS;\r
+\r
+ public void psychlops_main()\r
+ {\r
+ DotNumberS = new Psychlops.Widgets.Slider("test", new Interval(10, 500));\r
+ //Independent ind = new Independent();\r
+\r
+ cnvs = new Canvas(500, 500);\r
+ xxx = 1;\r
+ Image img = new Image(100,100);\r
+ for (int x = 0; x < 100; x++)\r
+ {\r
+ for (int y = 0; y < 100; y++)\r
+ {\r
+ img.pix(x,y, new Color( Math.sin(x+y)) );\r
+ }\r
+ }\r
+\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
+\r
+\r
+ //Declare Matrix to keep back ground dots' coordinate value\r
+ double[] DotX=new double[2048];\r
+ double[] DotY = new double[2048];\r
+\r
+\r
+\r
+ //Set Independent variables to manipulate\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
+\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
+\r
+ //Main stimulus loop\r
+ while(true){\r
+ //Clear the main window\r
+ cnvs.clear(Color.black);\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
+ cnvs.msg(TargetNumber.ToString(), 0, 30);\r
+ for (int i = 0; i < 5; i++)\r
+ {\r
+ cnvs.msg(i.ToString(), 50+50*i, 30);\r
+ t = 2.0 * Math.PI/TargetNumber;\r
+ x = 10.0 * i;//TargetEcce*Math.cos(i*t+temp);\r
+ y = 10.0 * i;//TargetEcce*Math.sin(i*t+temp);\r
+ Target[i].centering().shift(x,y);\r
+ Target[i].fill = Color.yellow;\r
+ Target[i].draw();\r
+ }\r
+\r
+// img.centering().draw();\r
+ //Reflect drawing at the next frame;\r
+ cnvs.flip();\r
+ }\r
+\r
+\r
+\r
+ }\r
+ }\r
+\r
+}\r
+\r
+\r
/*\r
using Psychlops;\r
\r
\r
*/\r
\r
+/*\r
+\r
+\r
using Psychlops;\r
\r
namespace Psychlops\r
}\r
\r
}\r
-\r
+ * \r
+ * */\r
\r
\r