/// <summary> /// The start button was clicked. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void StartClicked(object sender, RoutedEventArgs e) { this.gardener = new Gardener(); var comm = CommType.Udp; if (this.WebComms.IsChecked ?? false) { comm = CommType.Web; } // Define the way the gardener should behave var settings = new GardenerSettings { CommType = comm, //EnableColorDetection = this.EnableColorDetection.IsChecked ?? false, //EnableImageDetection = this.EnableImageDetection.IsChecked ?? false, EnableShakeDetection = this.EnableShakeDetection.IsChecked ?? false, // EnableNoiseDetection = this.EnableNoiseDetection.IsChecked ?? false, //NoiseThreshold = 1500, //NoiseDuration = 2, //ColorToDetect = Colors.Blue, //ColorDetectionThreshold = 40, // These two properties must be set like this for the camera to be // able to be used to do color and image detection ViewFinderBrush = this.viewfinderBrush, ViewFinderBrushTransform = this.viewfinderBrushTransformation, }; this.gardener.Initialize(settings); this.AddHandlersForDetectedEvents(); // Handle notification, from another device, that a node has been added/changed this.gardener.OnNodeChanged += nodeId => this.Dispatcher.BeginInvoke(() => { var gardenerNode = this.gardener.Nodes.FirstOrDefault(n => n.Id == nodeId); var visualNode = this.nodes.FirstOrDefault(n => n.Id == nodeId); if (gardenerNode != null) { if (visualNode == null) { var vn = new VisualNode(rand, MainCanvas) { X = gardenerNode.X, Y = gardenerNode.Y, Tag = gardenerNode.Tag, Id = gardenerNode.Id, DisableVirtualMovement = true }; this.nodes.Add(vn); } else { var idx = this.nodes.IndexOf(visualNode); this.nodes[idx].X = gardenerNode.X; this.nodes[idx].Y = gardenerNode.Y; this.nodes[idx].Tag = gardenerNode.Tag; } } else { if (visualNode != null) { visualNode.Remove(this.MainCanvas); this.nodes.Remove(visualNode); } } }); this.ConfigureOtherOptions(); this.nodes = new List<VisualNode>(); this.CreateOwnNode(); this.gardener.WhereIsEveryBody(); this.CreateDefaultNodes(Convert.ToInt32(Math.Floor(this.AdditionalNodesCount.Value))); this.CreateLines(); //get hold of the user's node selfNode = this.nodes.FirstOrDefault(n => n.Id == gardener.GetSelfNodeId()); //add all nodes to dictionary nodePositionAndNote = this.nodes.ToDictionary(x => x, x => ((int)Math.Round(x.CurrentX / (double)JUMP) * JUMP)); this.nodeMovementTimer.Interval = TimeSpan.FromMilliseconds(10); this.nodeMovementTimer.Tick += this.UpdateDisplay; this.nodeMovementTimer.Start(); }
/// <summary> /// Animate the note's colour /// </summary> /// <param name="vn">The note to animate</param> public void AnimateNote(VisualNode vn) { //create a colour animation as the set duration to 800ms Duration duration = new Duration(TimeSpan.FromMilliseconds(800)); ColorAnimation ca = new ColorAnimation(); ca.Duration = duration; Storyboard sb = new Storyboard(); sb.Duration = duration; sb.Children.Add(ca); //set the target to be the note path and the property to be "Fill" Storyboard.SetTarget(ca, vn.noteNode.notePath); Storyboard.SetTargetProperty(ca, new PropertyPath("(Shape.Fill).(SolidColorBrush.Color)")); //animate it to a random colour ca.To = GetRandomColour(); //once animated, return back to its original colour (black by default) sb.AutoReverse = true; // Make the Storyboard a resource. if (!MainCanvas.Resources.Contains("animate_note")) MainCanvas.Resources.Add("animate_note", sb); //start the animation sb.Begin(); }