using Psychlops; namespace PsychlopsSilverlight3test { public partial class MainPage : System.Windows.Controls.UserControl { public System.ComponentModel.BackgroundWorker main_routine; public System.Windows.Controls.Image master; public MainPage() { InitializeComponent(); initialize(); // Show fps counter Canvas.default_instance = image; System.Windows.Application.Current.Host.Settings.MaxFrameRate = 60; System.Windows.Application.Current.Host.Settings.EnableFrameRateCounter = true; System.Windows.Application.Current.Host.Settings.EnableCacheVisualization = true; System.Windows.Media.CompositionTarget.Rendering += new System.EventHandler(CompositionTarget_Rendering); //main_routine = new System.ComponentModel.BackgroundWorker(); //main_routine.DoWork += new System.ComponentModel.DoWorkEventHandler(psychlops_main); //main_routine.RunWorkerAsync(); } int background; private void backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs args) { while (true) { System.Threading.Thread.Sleep(10); background++; } } int frame; private void CompositionTarget_Rendering(object sender, System.EventArgs e) { frame++; //Canvas.default_buffer.Invalidate(); trial(); } Canvas cnvs; Image img; int isize = 100; double tfreq = 1; public void initialize() { cnvs = new Canvas(500, 500, image, this); img = new Image(isize*2, isize*2); cnvs.clear(Color.gray); } public void trial() { cnvs.clear(new Color(Mouse.left.pressed() ? 1.0 : 0.5)); img.field( (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)) ); img.centering(Mouse.position); //img.shift(1,0); img.draw(); cnvs.flip(); } /* Canvas cnvs; Rectangle[] rects; double tfreq = 1; public void initialize() { cnvs = new Canvas(500, 500, image, this); rects = new Rectangle[100]; for (int i = 0; i < rects.Length; i++) { rects[i] = new Rectangle(10,10); } cnvs.clear(Color.gray); } public void trial() { cnvs.clear(new Color(Mouse.left.pressed() ? 1.0 : 0.5)); foreach (Rectangle rect in rects) { rect.centering().shift(background,0).draw(); } cnvs.flip(); } */ } }