\r
public class Canvas : Drawable\r
{\r
- public static System.Windows.Controls.Image default_instance;\r
+ public static System.Windows.Controls.Image default_buffer_frame;\r
public static System.Windows.Controls.UserControl default_panel;\r
- public static WriteableBitmap default_buffer; \r
+ public static WriteableBitmap default_buffer;\r
System.Windows.Controls.Image instance;\r
System.Windows.Controls.UserControl panel; \r
WriteableBitmap buffer;\r
public Canvas(int wid, int hei)\r
{\r
panel = default_panel;\r
- instance = default_instance;\r
- instance.Width = wid;\r
- instance.Height = hei;\r
- buffer = new WriteableBitmap((int)instance.Width, (int)instance.Height);\r
- instance.Source = buffer;\r
- instance.MouseMove += Mouse.Canvas_MousePos;\r
- instance.MouseLeftButtonDown += Mouse.Canvas_LDown;\r
- instance.MouseLeftButtonUp += Mouse.Canvas_LUp;\r
- instance.MouseWheel += Mouse.Canvas_MouseWheel;\r
- Mouse._prime = instance;\r
- Main.drawable = this;\r
- default_buffer = buffer;\r
+ instance = default_buffer_frame;\r
+ initialize(wid, hei);\r
}\r
public Canvas(int wid, int hei, System.Windows.Controls.Image target, System.Windows.Controls.UserControl system)\r
{\r
panel = system;\r
instance = target;\r
+ initialize(wid, hei);\r
+ }\r
+ protected void initialize(int wid, int hei)\r
+ {\r
instance.Width = wid;\r
instance.Height = hei;\r
buffer = new WriteableBitmap((int)instance.Width, (int)instance.Height);\r
- instance = target;\r
instance.Source = buffer;\r
instance.MouseMove += Mouse.Canvas_MousePos;\r
instance.MouseLeftButtonDown += Mouse.Canvas_LDown;\r
instance.MouseWheel += Mouse.Canvas_MouseWheel;\r
Mouse._prime = instance;\r
Main.drawable = this;\r
+ default_buffer = buffer;\r
}\r
public Point getCenter()\r
{\r
buffer.SetPixel(x, y, col);\r
}\r
\r
+ static System.Windows.Shapes.Line api_line;\r
+ static System.Windows.Shapes.Path api_curve;\r
+ static System.Windows.Shapes.Rectangle api_rect;\r
+ static System.Windows.Shapes.Ellipse api_ellipse;\r
+ static System.Windows.Shapes.Polygon api_polygon;\r
+ static System.Windows.Shapes.Polyline api_polyline;\r
+ static System.Windows.Media.Color api_color;\r
+ static System.Windows.Media.SolidColorBrush api_fill;\r
+ static System.Windows.Media.SolidColorBrush api_stroke;\r
+ static System.Windows.Media.TranslateTransform api_translation;\r
+ static Canvas()\r
+ {\r
+ api_line = new System.Windows.Shapes.Line();\r
+ api_curve = new System.Windows.Shapes.Path();\r
+ api_rect = new System.Windows.Shapes.Rectangle();\r
+ api_ellipse = new System.Windows.Shapes.Ellipse();\r
+ api_polygon = new System.Windows.Shapes.Polygon();\r
+ api_polyline = new System.Windows.Shapes.Polyline();\r
+ api_color = new System.Windows.Media.Color();\r
+ api_fill = new System.Windows.Media.SolidColorBrush();\r
+ api_stroke = new System.Windows.Media.SolidColorBrush();\r
+ api_translation = new System.Windows.Media.TranslateTransform();\r
+ }\r
\r
public void line(Line drawee, Color col)\r
{\r
}\r
public void rect(Rectangle drawee, Color col)\r
{\r
- buffer.DrawRectangle((int)drawee.v1.x, (int)drawee.v1.y, (int)drawee.v2.x, (int)drawee.v2.y, col);\r
+ //buffer.DrawRectangle((int)drawee.v1.x, (int)drawee.v1.y, (int)drawee.v2.x, (int)drawee.v2.y, col);\r
+ api_rect.Width = drawee.width;\r
+ api_rect.Height = drawee.height;\r
+ api_fill.Color = col;\r
+ api_rect.Fill = api_fill;\r
+ api_translation.X = drawee.left;\r
+ api_translation.Y = drawee.top;\r
+ buffer.Render(api_rect, api_translation);\r
}\r
public void ellipse(Ellipse drawee, Color col)\r
{\r
}\r
\r
\r
+ public int frame;\r
public void flip()\r
{\r
buffer.Invalidate();\r
+ frame++;\r
}\r
}\r
\r
{\r
public System.ComponentModel.BackgroundWorker main_routine;\r
public System.Windows.Controls.Image master;\r
+ public PsychlopsMain main;\r
public MainPage()\r
{\r
InitializeComponent();\r
- initialize();\r
// Show fps counter\r
- Canvas.default_instance = image;\r
+ Canvas.default_buffer_frame = main_buffer;\r
+ Canvas.default_panel = this;\r
System.Windows.Application.Current.Host.Settings.MaxFrameRate = 60;\r
System.Windows.Application.Current.Host.Settings.EnableFrameRateCounter = true;\r
System.Windows.Application.Current.Host.Settings.EnableCacheVisualization = true;\r
//main_routine = new System.ComponentModel.BackgroundWorker();\r
//main_routine.DoWork += new System.ComponentModel.DoWorkEventHandler(psychlops_main);\r
//main_routine.RunWorkerAsync();\r
+\r
+ \r
+ main = new PsychlopsMain();\r
+ main.initialize();\r
}\r
int background;\r
private void backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs args)\r
{\r
frame++;\r
//Canvas.default_buffer.Invalidate();\r
- trial();\r
+ main.each_frames();\r
}\r
\r
- Canvas cnvs;\r
- Image img;\r
- int isize = 100;\r
- double tfreq = 1;\r
- public void initialize()\r
- {\r
- cnvs = new Canvas(500, 500, image, this);\r
- img = new Image(isize*2, isize*2);\r
- cnvs.clear(Color.gray);\r
- }\r
- public void trial()\r
- {\r
- cnvs.clear(new Color(Mouse.left.pressed() ? 1.0 : 0.5));\r
- img.field(\r
- (x, y) => new Color(.5 + Math.gaussian(Math.radius(x - isize, y - isize), isize / 8.0) * .5 * Math.sin(frame*2*Math.PI/tfreq/60 + x / 3.0))\r
- );\r
- img.centering(Mouse.position);\r
- //img.shift(1,0);\r
- img.draw();\r
- cnvs.flip();\r
- }\r
/*\r
Canvas cnvs;\r
Rectangle[] rects;\r
--- /dev/null
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlight3test\r
+{\r
+ public class PsychlopsMain\r
+ {\r
+ Canvas cnvs;\r
+ Image img;\r
+ Rectangle fixation;\r
+ int isize = 100;\r
+ double tfreq = 1;\r
+\r
+ public void initialize()\r
+ {\r
+ cnvs = new Canvas(500, 500);\r
+ img = new Image(isize * 2, isize * 2);\r
+ fixation = new Rectangle(10, 10);\r
+ cnvs.clear(Color.gray);\r
+ }\r
+\r
+ public void each_frames()\r
+ {\r
+ cnvs.clear(new Color(Mouse.left.pressed() ? 1.0 : 0.5));\r
+ img.field(\r
+ (x, y) => new Color(.5 + Math.gaussian(Math.radius(x - isize, y - isize), isize / 8.0) * .5 * Math.sin(cnvs.frame * 2 * Math.PI / tfreq / 60 + x / 3.0))\r
+ );\r
+ img.centering(Mouse.position);\r
+ //img.shift(1,0);\r
+ img.draw();\r
+ fixation.centering();\r
+ fixation.draw(Color.red);\r
+ cnvs.flip();\r
+ }\r
+ }\r
+}\r