<ItemGroup>\r
<Compile Include="Properties\AssemblyInfo.cs" />\r
<Compile Include="psychlops\core\app\misc.cs" />\r
+ <Compile Include="psychlops\core\device\clock.cs" />\r
<Compile Include="psychlops\core\device\hid.cs" />\r
<Compile Include="psychlops\core\graphic\canvas.cs" />\r
+ <Compile Include="psychlops\core\graphic\image.cs" />\r
<Compile Include="psychlops\core\graphic\font.cs" />\r
<Compile Include="psychlops\core\graphic\module.cs" />\r
+ <Compile Include="psychlops\core\math\interval.cs" />\r
+ <Compile Include="psychlops\core\math\matrix.cs" />\r
<Compile Include="psychlops\core\math\util.cs" />\r
+ <Compile Include="psychlops\extention\media\svg.cs" />\r
<Compile Include="psychlops\extention\standard\figures.cs" />\r
<Compile Include="psychlops\extention\standard\widget.cs" />\r
<Compile Include="psychlops\psychlops.cs" />\r
{\r
public static Drawable drawable;\r
public static Canvas canvas;\r
- public static System.Threading.Thread routine;\r
- public static System.Threading.AutoResetEvent flag;\r
+\r
+ }\r
+\r
+ namespace Internal\r
+ {\r
+ public static class Main\r
+ {\r
+ public static System.Threading.Thread routine;\r
+ public static System.Threading.AutoResetEvent canvas_flag;\r
+\r
+ static Main()\r
+ {\r
+ canvas_flag = new System.Threading.AutoResetEvent(false);\r
+ }\r
+ }\r
}\r
}\r
--- /dev/null
+using System;\r
+\r
+namespace Psychlops\r
+{\r
+\r
+}\r
namespace Psychlops\r
{\r
\r
- public class Canvas : Drawable\r
+ namespace Templates\r
+ {\r
+\r
+ public class StackableDrawable : Drawable\r
+ {\r
+ protected System.Collections.Generic.Queue<Internal.PrimitiveFigure> stack;\r
+\r
+ public StackableDrawable()\r
+ {\r
+ stack = new System.Collections.Generic.Queue<Internal.PrimitiveFigure>();\r
+ }\r
+\r
+ public void clear()\r
+ {\r
+ clear(Color.black);\r
+ }\r
+ public virtual void clear(Color col)\r
+ {\r
+ //rect(back_panel, col);\r
+ }\r
+\r
+ public virtual void pix(int x, int y, Color col)\r
+ {\r
+ }\r
+\r
+ public virtual void line(Line drawee)\r
+ {\r
+ stack.Enqueue(drawee.clone());\r
+ }\r
+\r
+ public virtual void rect(Rectangle drawee)\r
+ {\r
+ stack.Enqueue(drawee.clone());\r
+ }\r
+\r
+ public virtual void ellipse(Ellipse drawee)\r
+ {\r
+ stack.Enqueue(drawee.clone());\r
+ }\r
+\r
+ public virtual void polygon(Polygon drawee)\r
+ {\r
+ stack.Enqueue(drawee.clone());\r
+ }\r
+\r
+ public virtual void letters(Letters drawee)\r
+ {\r
+ stack.Enqueue(drawee.clone());\r
+ }\r
+\r
+ public virtual void image(Image drawee)\r
+ {\r
+ stack.Enqueue(drawee.clone());\r
+ }\r
+\r
+ public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }\r
+ public virtual void msg(string str, double x, double y, Color col)\r
+ {\r
+ var let = new Letters(str);\r
+ let.locate(x, y);\r
+ let.fill = col;\r
+ this.letters(let);\r
+ }\r
+ public void var<Type>(Type val, double x, double y) { msg(val.ToString(), x, y, Color.white); }\r
+ public void var<Type>(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); }\r
+\r
+ public virtual Point getCenter() { return new Point(0, 0, 0); }\r
+ }\r
+\r
+ }\r
+\r
+ public class Canvas : Templates.StackableDrawable\r
{\r
\r
#region initializer\r
\r
- System.Collections.Generic.Queue<Figure> stock;\r
internal delegate void TwoIntProcedure(int x, int y);\r
internal delegate void SimpleProcedure();\r
SimpleProcedure flipexec;\r
\r
back_panel = new Rectangle(wid, hei);\r
\r
- stock = new System.Collections.Generic.Queue<Figure>();\r
flipexec = new SimpleProcedure(executeFlip);\r
}\r
protected void initialize__(int wid, int hei)\r
#endregion\r
\r
\r
- public void clear()\r
+ public override void clear(Color col)\r
{\r
- clear(Color.black);\r
- }\r
- public void clear(Color col)\r
- {\r
- //api_canvas.Children.Clear();\r
- rect(back_panel, col);\r
- }\r
-\r
- public void pix(int x, int y, Color col)\r
- {\r
- //buffer.SetPixel(x, y, col);\r
+ back_panel.fill = col;\r
+ rect(back_panel);\r
}\r
\r
- public void line(Line drawee, Color col)\r
- {\r
- var tmp = drawee.clone();\r
- tmp.fill = col;\r
- stock.Enqueue(tmp);\r
- }\r
- public void line(Line drawee)\r
- {\r
- stock.Enqueue(drawee.clone());\r
- }\r
- public void rect(Rectangle drawee, Color col)\r
- {\r
- var tmp = drawee.clone();\r
- tmp.fill = col;\r
- stock.Enqueue(tmp);\r
- }\r
- public void rect(Rectangle drawee)\r
- {\r
- stock.Enqueue(drawee.clone());\r
- }\r
- public void ellipse(Ellipse drawee, Color col)\r
- {\r
- var tmp = drawee.clone();\r
- tmp.fill = col;\r
- stock.Enqueue(tmp);\r
- }\r
- public void ellipse(Ellipse drawee)\r
- {\r
- stock.Enqueue(drawee.clone());\r
- }\r
- public void polygon(Polygon drawee, Color col)\r
- {\r
- var tmp = drawee.clone();\r
- tmp.fill = col;\r
- stock.Enqueue(tmp);\r
- }\r
- public void polygon(Polygon drawee)\r
- {\r
- stock.Enqueue(drawee.clone());\r
- }\r
- public void letters(Letters drawee, Color col)\r
- {\r
- var tmp = drawee.clone();\r
- tmp.fill = col;\r
- stock.Enqueue(tmp);\r
- }\r
- public void letters(Letters drawee)\r
- {\r
- stock.Enqueue(drawee.clone());\r
- }\r
- public void image(Image drawee)\r
- {\r
- //buffer.Blit(drawee.datum, drawee.buffer, drawee.self_rect, Colors.White, WriteableBitmapExtensions.BlendMode.None);\r
- stock.Enqueue(drawee.clone());\r
- }\r
-\r
-\r
- public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }\r
- public void msg(string str, double x, double y, Color col)\r
- {\r
- var let = new Letters(str);\r
- let.locate(x, y);\r
- this.letters(let, col);\r
- }\r
- public void var<Type>(Type val, double x, double y) { msg(val.ToString(), x, y, Color.white); }\r
- public void var<Type>(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); }\r
-\r
-\r
+ int nextIntervalFrame = 1;\r
public void flip()\r
{\r
//api_canvas.Dispatcher.BeginInvoke(flipexec);\r
//flipexec();\r
//System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);\r
- Main.flag.WaitOne();\r
+ lock (this)\r
+ {\r
+ nextIntervalFrame = 1;\r
+ }\r
+ Internal.Main.canvas_flag.WaitOne();\r
}\r
- \r
public void executeFlip()\r
{\r
- api_canvas.Children.Clear();\r
- foreach (Figure f in stock)\r
+ lock (this)\r
{\r
- api_canvas.Children.Add(f.toNative());\r
+ nextIntervalFrame--;\r
}\r
- stock.Clear();\r
+ if (nextIntervalFrame <= 0)\r
+ {\r
+ var tmp = new System.Windows.Controls.Canvas();\r
+ foreach (Internal.PrimitiveFigure f in stack)\r
+ {\r
+ tmp.Children.Add(f.toNative());\r
+ }\r
+ api_canvas.Children.Clear();\r
+ api_canvas.Children.Add(tmp);\r
+ stack.Clear();\r
+ Psychlops.Internal.Main.canvas_flag.Set();\r
+ }\r
+ System.Threading.Thread.Sleep(0);\r
}\r
\r
#region Properties\r
public Point center { get { return new Point(width / 2.0, height / 2.0, 0); } }\r
public double getWidth() { return width; }\r
public double getHeight() { return height; }\r
- public Point getCenter() { return center; }\r
+ public override Point getCenter() { return center; }\r
public double getHCenter() { return width / 2; }\r
public double getVCenter() { return height / 2; }\r
public double getRefreshRate() { return 60; }\r
\r
\r
\r
+ #region primitive tokenizer\r
\r
partial struct Point\r
{\r
public UIElement toNative() { return this; }\r
}\r
\r
- internal class CanvasTokenizer\r
- {\r
+ #endregion\r
\r
- }\r
\r
}
\ No newline at end of file
{\r
Main.drawable.letters(this);\r
}\r
- public void draw(Color c)\r
- {\r
- Main.drawable.letters(this, c);\r
- }\r
\r
public Color fill { get; set; }\r
public Stroke stroke { get; set; }\r
--- /dev/null
+using System;\r
+using System.Windows;\r
+using System.Windows.Controls;\r
+using System.Windows.Documents;\r
+using System.Windows.Input;\r
+using System.Windows.Media;\r
+using System.Windows.Media.Animation;\r
+using System.Windows.Media.Imaging;\r
+using System.Windows.Shapes;\r
+\r
+\r
+namespace Psychlops{\r
+\r
+\r
+ public partial class Image : Internal.PrimitiveFigure\r
+ {\r
+ public WriteableBitmap buffer;\r
+ public Point datum;\r
+ public Rectangle self_rect;\r
+\r
+ public Image(int wid, int hei)\r
+ {\r
+ initialize__(wid, hei);\r
+ self_rect = new Rectangle(wid, hei);\r
+ }\r
+\r
+ /*public Image shift(double x, double y)\r
+ {\r
+ datum.x += x;\r
+ datum.y += y;\r
+ return this;\r
+ }*/\r
+ public Figure shift(Point p)\r
+ {\r
+ datum += p;\r
+ return this;\r
+ }\r
+ public Figure centering(Point p)\r
+ {\r
+ datum.x = p.x - width / 2.0;\r
+ datum.y = p.y - height / 2.0;\r
+ return this;\r
+ }\r
+\r
+ public void pix(int x, int y, Color col)\r
+ {\r
+ buffer.SetPixel(x, y, col);\r
+ }\r
+\r
+\r
+ public void field(System.Func<int, int, System.Windows.Media.Color> func)\r
+ {\r
+ field__(func);\r
+ //buffer.ForEach(func);\r
+ }\r
+ public void field(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)\r
+ {\r
+ field__(func);\r
+ //buffer.ForEach(func);\r
+ }\r
+\r
+ public void draw()\r
+ {\r
+ Main.drawable.image(this);\r
+ }\r
+\r
+ public double width { get { return self_rect.width; } }\r
+ public double height { get { return self_rect.height; } }\r
+\r
+ }\r
+\r
+\r
+}
\ No newline at end of file
using System;\r
using System.Windows;\r
-using System.Windows.Controls;\r
-using System.Windows.Documents;\r
-using System.Windows.Input;\r
-using System.Windows.Media;\r
-using System.Windows.Media.Animation;\r
-using System.Windows.Media.Imaging;\r
-using System.Windows.Shapes;\r
-\r
\r
\r
namespace Psychlops\r
magenta = new Color(1, 0, 1, 1),\r
cyan = new Color(0, 1, 1, 1),\r
white = new Color(1, 1, 1, 1),\r
- gray = new Color(.5, .5, .5, 1);\r
+ gray = new Color(.5, .5, .5, 1),\r
+ null_color = new Color(0, 0, 0, 0);\r
\r
}\r
\r
void clear(Color col);\r
void pix(int x, int y, Color col);\r
void line(Line drawee);\r
- void line(Line drawee, Color col);\r
- //void line(Line drawee, Stroke strk);\r
void rect(Rectangle drawee);\r
- void rect(Rectangle drawee, Color col);\r
- //void rect(Rectangle drawee, Stroke strk);\r
void ellipse(Ellipse drawee);\r
- void ellipse(Ellipse drawee, Color col);\r
- //void ellipse(Ellipse drawee, Stroke strk);\r
void polygon(Polygon drawee);\r
- void polygon(Polygon drawee, Color col);\r
- //void polygon(Polygon drawee, Stroke strk);\r
void letters(Letters drawee);\r
- void letters(Letters drawee, Color col);\r
- //void letters(Letters drawee, Stroke strk);\r
void image(Image drawee);\r
void msg(string s, double x, double y, Color c);\r
}\r
Figure shift(Point p);\r
Figure centering(Point p);\r
void draw();\r
- UIElement toNative();\r
}\r
public static class FigureExtention\r
{\r
}\r
}\r
\r
- public partial class Image : Figure\r
+ namespace Internal\r
{\r
- public WriteableBitmap buffer;\r
- public Point datum;\r
- public Rectangle self_rect;\r
-\r
- public Image(int wid, int hei)\r
- {\r
- initialize__(wid, hei);\r
- self_rect = new Rectangle(wid, hei);\r
- }\r
-\r
- /*public Image shift(double x, double y)\r
- {\r
- datum.x += x;\r
- datum.y += y;\r
- return this;\r
- }*/\r
- public Figure shift(Point p)\r
- {\r
- datum += p;\r
- return this;\r
- }\r
- public Figure centering(Point p)\r
- {\r
- datum.x = p.x - width / 2.0;\r
- datum.y = p.y - height / 2.0;\r
- return this;\r
- }\r
-\r
- public void pix(int x, int y, Color col)\r
- {\r
- buffer.SetPixel(x, y, col);\r
- }\r
-\r
-\r
- public void field(System.Func<int,int,System.Windows.Media.Color> func)\r
- {\r
- field__(func);\r
- //buffer.ForEach(func);\r
- }\r
- public void field(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)\r
+ public interface PrimitiveFigure : Figure\r
{\r
- field__(func);\r
- //buffer.ForEach(func);\r
+ UIElement toNative();\r
}\r
-\r
- public void draw()\r
- {\r
- Main.drawable.image(this);\r
- }\r
-\r
- public double width { get { return self_rect.width; } }\r
- public double height { get { return self_rect.height; } }\r
-\r
}\r
-\r
}
\ No newline at end of file
\r
namespace Psychlops{\r
\r
- public interface Shape : Figure\r
+ public interface Shape : Internal.PrimitiveFigure\r
{\r
- void draw(Color c);\r
Color fill { get; set; }\r
Stroke stroke { get; set; }\r
}\r
public static class ShapeExtention\r
{\r
- /*\r
- public static void draw(this Shape drawee)\r
+ public static void draw(this Shape drawee, Color c)\r
{\r
- drawee.draw(Color.white);\r
+ Color tmp_col = drawee.fill;\r
+ Stroke tmp_strk = drawee.stroke;\r
+ drawee.fill = c;\r
+ drawee.stroke = new Stroke();\r
+ drawee.draw();\r
+ drawee.fill = tmp_col;\r
+ drawee.stroke = tmp_strk;\r
+ }\r
+ public static void draw(this Shape drawee, Stroke strk)\r
+ {\r
+ Color tmp_col = drawee.fill;\r
+ Stroke tmp_strk = drawee.stroke;\r
+ drawee.fill = new Color(0,0,1,1);\r
+ drawee.stroke = strk;\r
+ drawee.draw();\r
+ drawee.fill = tmp_col;\r
+ drawee.stroke = tmp_strk;\r
}\r
- */\r
}\r
\r
public partial struct Stroke\r
{\r
public double thick;\r
public Color color;\r
+ public Stroke(Color c, double t)\r
+ {\r
+ color = c;\r
+ thick = t;\r
+ }\r
public void set(Color c, double t)\r
{\r
color = c;\r
return this;\r
}\r
\r
- public void draw(Color c)\r
- {\r
- Main.drawable.line(this, c);\r
- }\r
public void draw()\r
{\r
Main.drawable.line(this);\r
return this;\r
}\r
\r
- public void draw(Color c)\r
- {\r
- Main.drawable.rect(this, c);\r
- }\r
public void draw()\r
{\r
Main.drawable.rect(this);\r
return this;\r
}\r
\r
- public void draw(Color c)\r
- {\r
- Main.drawable.ellipse(this, c);\r
- }\r
public void draw()\r
{\r
Main.drawable.ellipse(this);\r
return this;\r
}\r
\r
- public void draw(Color c)\r
- {\r
- Main.drawable.polygon(this, c);\r
- }\r
public void draw()\r
{\r
Main.drawable.polygon(this);\r
--- /dev/null
+using System;\r
+\r
+namespace Psychlops\r
+{\r
+\r
+}
\ No newline at end of file
--- /dev/null
+using System;\r
+\r
+namespace Psychlops\r
+{\r
+\r
+}
\ No newline at end of file
--- /dev/null
+\r
+namespace Psychlops\r
+{\r
+\r
+\r
+\r
+\r
+}
\ No newline at end of file
\r
main = new PsychlopsMain();\r
//main.initialize();\r
- Main.flag = new System.Threading.AutoResetEvent(false);\r
- Main.routine = new System.Threading.Thread(main.psychlops_main);\r
- Main.routine.Start();\r
+ Psychlops.Internal.Main.routine = new System.Threading.Thread(main.psychlops_main);\r
+ Psychlops.Internal.Main.routine.Start();\r
//main_routine = main.psychlops_main();\r
#if DEBUG\r
DebugConsole = new System.Windows.Controls.TextBlock();\r
this.Focus();\r
}\r
\r
- int nextIntervalFrame = 1;\r
private void CompositionTarget_Rendering(object sender, System.EventArgs e)\r
{\r
if (Main.canvas != null) Main.canvas.executeFlip();\r
- Main.flag.Set();\r
- nextIntervalFrame--;\r
- if (nextIntervalFrame<=0)\r
- {\r
- //main_routine.MoveNext();\r
- //nextIntervalFrame = main_routine.Current;\r
- }\r
+ //if (nextIntervalFrame-- <= 0)\r
+ //{\r
+ // main_routine.MoveNext();\r
+ // nextIntervalFrame = main_routine.Current;\r
+ //}\r
}\r
\r
}\r
img = new Image(isize * 2, isize * 2);\r
fixation = new Rectangle(10, 10);\r
fixation.fill = Color.red;\r
+ var poly = new Rectangle(100, 100);\r
//var poly = new Letters("日本語");\r
- var poly = new Polygon(); poly.append(0, 100); poly.append(-100, 0); poly.append(0, -100); poly.append(100, 0);\r
+ //var poly = new Polygon(); poly.append(0, 100); poly.append(-100, 0); poly.append(0, -100); poly.append(100, 0);\r
//var poly = new Ellipse(100, 100);\r
//var poly = new Line(0,0,100, 0);\r
poly.fill = Color.red;\r
- poly.stroke.set(Color.green, 10);\r
+ poly.stroke = new Stroke { color = Color.yellow, thick = 1 };\r
shape = poly;\r
\r
\r
\r
//Figures.drawGabor(ref img, 20, 100, 1, 0, frames * 2.0 * Math.PI / tfreq / 60);\r
//Figures.drawGaussian(ref img, 20, 1);\r
- Figures.drawGrating(ref img, 500, 500, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);\r
+ Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);\r
img.centering(Mouse.position);\r
img.draw();\r
\r
cnvs.var(frames, 10, 20);\r
\r
fixation.shift(100,100);\r
- fixation.draw(Color.blue);\r
+ fixation.draw(new Stroke(Color.blue, 3));\r
\r
cnvs.flip();\r
}\r