Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
Added Asteroids game from Wolfral examples
Browse files Browse the repository at this point in the history
  • Loading branch information
flideros committed May 8, 2021
1 parent 50acbb2 commit 7664e50
Show file tree
Hide file tree
Showing 3 changed files with 505 additions and 8 deletions.
6 changes: 3 additions & 3 deletions ControLibrary/Volume.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ open System.Windows.Input

/// Volume control , it shows a value and allows you to change it.
type Volume(title:string, range:int * int, value:SharedValue<int>) as this =
inherit StackPanel(Orientation=Orientation.Horizontal)
inherit StackPanel(Orientation=Orientation.Vertical,VerticalAlignment = VerticalAlignment.Center)

do Label(Content=title,Width=50.) |> this.Children.Add |> ignore
let label = Label(Content=value.Get,Width=50.)
do Label(Content=title,Width=110.) |> this.Children.Add |> ignore
let label = Label(Content=value.Get,Width=27.)
let slider = Slider(Minimum=float(fst range), Maximum=float(snd range), TickFrequency=2., Width=127.)
let changedHandler value =
label.Content <- string value
Expand Down
25 changes: 21 additions & 4 deletions WolframDisplay/WolframCanvas.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,32 @@ type WolframCanvas() as this =
cb.Margin <- Thickness(Left = 10., Top = 20., Right = 0., Bottom = 0.)
cb.ItemsSource <- ["Compute";"Animate";"Math Picture Box"]
cb
let asteroids_Button =
Button( Name = "Asteroids",
Content = "Asteroids",
HorizontalAlignment = HorizontalAlignment.Left,
Margin = Thickness(Left = 10., Top = 20., Right = 0., Bottom = 0.),
VerticalAlignment = VerticalAlignment.Top,
Width = 60.,
Height = 50.,
Background = Brushes.Aqua)
let compute_Button =
Button( Name = "Compute",
Content = "Compute",
HorizontalAlignment = HorizontalAlignment.Left,
Margin = Thickness(Left = 10., Top = 20., Right = 0., Bottom = 0.),
VerticalAlignment = VerticalAlignment.Top,
Width = 53.,
Height = 33.,
Width = 60.,
Height = 50.,
Background = Brushes.Aqua)
let command_StackPanel =
let sp = StackPanel()
do sp.Children.Add(compute_Button) |> ignore
sp.Children.Add(destination_ComboBox) |> ignore
sp.Children.Add(mathSize_Volume) |> ignore
sp.Children.Add(mathSize_Volume) |> ignore
sp.Children.Add(asteroids_Button) |> ignore
sp.Orientation <- Orientation.Horizontal
sp.VerticalAlignment <- VerticalAlignment.Center
sp
let input_TextBox =
let tb = TextBox()
Expand Down Expand Up @@ -255,6 +266,10 @@ type WolframCanvas() as this =
| "Math Picture Box" -> sendToMathPictureBox code
| _ -> sendToCompute code

let loadAsteroids = fun () -> kernel.Compute( WolframCodeBlock.asteroids )
let launchAsteroids = fun () -> kernel.Compute("Asteroids[]")
let asteroids = fun n -> n |> loadAsteroids |> launchAsteroids

(*Initialize*)
do output_ScrollViewer.Content <- output_StackPanel
canvas.Children.Add(output_ScrollViewer) |> ignore
Expand All @@ -266,5 +281,7 @@ type WolframCanvas() as this =
this.Content <- screen_Grid

//add event handlers
compute_Button.Click.AddHandler(RoutedEventHandler(fun _ _ -> send input_TextBox.Text))
compute_Button.Click.AddHandler(RoutedEventHandler(fun _ _ -> send input_TextBox.Text))
asteroids_Button.Click.AddHandler(RoutedEventHandler(fun _ _ -> asteroids ()))

destination_ComboBox.SelectionChanged.AddHandler(SelectionChangedEventHandler(fun _ _-> setButtonsText (destination_ComboBox.SelectedValue.ToString())))
Loading

0 comments on commit 7664e50

Please sign in to comment.