Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open Xwt
- open Xwt.Drawing
- open System
- open System.Net
- open System.Threading
- type Pen = Pen of color:Color * width:float
- type Font = Font of size:float * isBold:bool
- type Line = Line of x1:float * y1:float * x2:float * y2:float
- type Rect = Rect of width:float * height:float
- type Triangle = Triangle of x1:float * y1:float * x2:float * y2:float * x3:float * y3:float
- type Ellipse = Ellipse of width:float * height:float
- type Shape =
- | LineShape of line:Line * pen:Pen
- | RectShape of rect:Rect * pen:Pen * fill:Color
- | TriangleShape of triangle:Triangle * pen:Pen * fill:Color
- | EllipseShape of Ellipse * pen:Pen * fill:Color
- | ImageShape of image:Image
- | TextShape of textRef:string ref * font:Font * color:Color
- type Drawing =
- | DrawLine of line:Line * pen:Pen
- | DrawRect of rect:Rect * pen:Pen
- | DrawTriangle of triangle:Triangle * pen:Pen
- | DrawEllipse of ellipse:Ellipse * pen:Pen
- | DrawImage of image:Image ref * x:float * y:float
- | DrawText of x:float * y:float * text:string * font:Font * color:Color
- | DrawBoundText of x:float * y:float * width:float * text:string * font:Font * color:Color
- | FillRect of rectangle:Rect * fill:Color
- | FillTriangle of triangle:Triangle * fill:Color
- | FillEllipse of ellipse:Ellipse * fill:Color
- | DrawShape of name:string * shape:Shape
- let drawEllipse (ctx:Context) (x,y,w,h) =
- let kappa = 0.5522848
- let ox = (w/2.0) * kappa
- let oy = (h/2.0) * kappa
- let xe = x + w
- let ye = y + h
- let xm = x + w / 2.0
- let ym = y + h / 2.0
- ctx.MoveTo(x,ym)
- ctx.CurveTo(x, ym - oy, xm - ox, y, xm, y)
- ctx.CurveTo(xm + ox, y, xe, ym - oy, xe, ym)
- ctx.CurveTo(xe, ym + oy, xm + ox, ye, xm, ye)
- ctx.CurveTo(xm - ox, ye, x, ym + oy, x, ym)
- let drawTriangle (ctx:Context) (Triangle(x1,y1,x2,y2,x3,y3)) =
- ctx.MoveTo(x1,y1)
- ctx.LineTo(x2,y2)
- ctx.LineTo(x3,y3)
- ctx.LineTo(x1,y1)
- let penStroke (ctx:Context) (Pen(color,width)) =
- ctx.SetColor(color)
- ctx.SetLineWidth(width)
- ctx.Stroke()
- let fill (ctx:Context) (color:Color) =
- ctx.SetColor(color)
- ctx.Fill()
- type DrawingInfo = {
- Drawing:Drawing;
- mutable Offset:Point;
- mutable Opacity:float option
- mutable IsVisible:bool }
- let draw (ctx:Context) (info:DrawingInfo) =
- let x,y = info.Offset.X, info.Offset.Y
- let withOpacity (color:Color) =
- match info.Opacity with
- | Some opacity -> color.WithAlpha(color.Alpha * opacity)
- | None -> color
- match info.Drawing with
- | DrawLine(Line(x1,y1,x2,y2),pen) ->
- ctx.MoveTo(x1,y1)
- ctx.LineTo(x2,y2)
- penStroke ctx pen
- | DrawRect(Rect(w,h),pen) ->
- ctx.Rectangle(x,y,w,h)
- penStroke ctx pen
- | DrawTriangle(triangle,pen) ->
- drawTriangle ctx triangle
- penStroke ctx pen
- | DrawEllipse(Ellipse(w,h),pen) ->
- drawEllipse ctx (x,y,w,h)
- penStroke ctx pen
- | DrawImage(image,x,y) ->
- if !image <> null then
- ctx.DrawImage(!image,x,y)
- | DrawText(x,y,text,Font(size,isBold),color) ->
- let layout = new TextLayout(Text=text)
- layout.Font <- layout.Font.WithSize(size)
- if isBold then layout.Font <- layout.Font.WithWeight(FontWeight.Bold)
- ctx.SetColor(color)
- ctx.DrawTextLayout(layout,x,y)
- | DrawBoundText(x,y,width,text,Font(size,isBold),color) ->
- let layout = new TextLayout(Text=text)
- layout.Font <- layout.Font.WithSize(size)
- layout.Width <- width
- if isBold then layout.Font <- layout.Font.WithWeight(FontWeight.Bold)
- ctx.SetColor(color)
- ctx.DrawTextLayout(layout,x,y)
- | FillRect(Rect(w,h),fillColor) ->
- ctx.Rectangle(x,y,w,h)
- fill ctx fillColor
- | FillTriangle(triangle,fillColor) ->
- drawTriangle ctx triangle
- fill ctx fillColor
- | FillEllipse(Ellipse(w,h),fillColor) ->
- drawEllipse ctx (x,y,w,h)
- fill ctx fillColor
- | DrawShape(_,LineShape(Line(x1,y1,x2,y2),pen)) ->
- ctx.MoveTo(x+x1,y+y1)
- ctx.LineTo(x+x2,y+y2)
- penStroke ctx pen
- | DrawShape(_,RectShape(Rect(w,h),pen,fillColor)) ->
- ctx.Rectangle(x,y,w,h)
- fill ctx fillColor
- ctx.Rectangle(x,y,w,h)
- penStroke ctx pen
- | DrawShape(_,TriangleShape(triangle,pen,fillColor)) ->
- drawTriangle ctx triangle
- fill ctx (withOpacity fillColor)
- drawTriangle ctx triangle
- penStroke ctx pen
- | DrawShape(_,EllipseShape(Ellipse(w,h),pen,fillColor)) ->
- drawEllipse ctx (x,y,w,h)
- fill ctx (withOpacity fillColor)
- drawEllipse ctx (x,y,w,h)
- penStroke ctx pen
- | DrawShape(_,TextShape(textRef,Font(size,isBold),color)) ->
- let layout = new TextLayout()
- layout.Text <- !textRef
- layout.Font <- layout.Font.WithSize(size)
- if isBold then layout.Font <- layout.Font.WithWeight(FontWeight.Bold)
- ctx.SetColor(color)
- ctx.DrawTextLayout(layout,x,y)
- | DrawShape(name,shape) ->
- failwith "Not implemented"
- let loadImageAsync (url:string) = async {
- let request = HttpWebRequest.Create(url)
- use! response = request.AsyncGetResponse()
- use stream = response.GetResponseStream()
- return Image.FromStream(stream)
- }
- [<AllowNullLiteral>]
- type DrawingCanvas () =
- inherit Canvas ()
- let drawings = ResizeArray<DrawingInfo>()
- let onShape shapeName f =
- drawings
- |> Seq.tryPick (function
- | { Drawing=DrawShape(name,_) } as info when name = shapeName -> Some info
- | _ -> None
- )
- |> Option.iter f
- member canvas.AddDrawing(drawing) =
- { Drawing=drawing; Offset=Point(); Opacity=None; IsVisible=true }
- |> drawings.Add
- canvas.QueueDraw()
- member canvas.AddDrawingAt(drawing, offset:Point) =
- { Drawing=drawing; Offset=offset; Opacity=None; IsVisible=true }
- |> drawings.Add
- canvas.QueueDraw()
- member canvas.MoveShape(shape, offset:Point) =
- onShape shape (fun info -> info.Offset <- offset; canvas.QueueDraw())
- member canvas.SetShapeOpacity(shape, opacity) =
- onShape shape (fun info -> info.Opacity <- Some opacity; canvas.QueueDraw())
- member canvas.SetShapeVisibility(shape, isVisible) =
- onShape shape (fun info -> info.IsVisible <- isVisible; canvas.QueueDraw())
- member canvas.RemoveShape(shape) =
- drawings |> Seq.tryFindIndex (function
- | { DrawingInfo.Drawing=DrawShape(shapeName,_) } -> shapeName = shape
- | _ -> false
- )
- |> function Some index -> drawings.RemoveAt(index) | None -> ()
- member canvas.Invalidate() =
- canvas.QueueDraw()
- override this.OnDraw(ctx, rect) =
- base.OnDraw(ctx, rect)
- for drawing in drawings do
- if drawing.IsVisible then draw ctx drawing
- type internal MyApp () =
- let mutable mainWindow : Window = null
- let mutable mainCanvas : DrawingCanvas = null
- let mutable keyUp = Action<string>(ignore)
- let mutable keyDown = Action<string>(ignore)
- let mutable mouseDown = fun () -> ()
- let mutable mouseUp = fun () -> ()
- let mutable mouseMove = fun () -> ()
- let mutable mouseX = 0.0
- let mutable mouseY = 0.0
- let mutable isLeftButtonDown = false
- let runApp onRun =
- Application.Initialize (ToolkitType.Gtk)
- mainWindow <- new Window(Title="App", Padding = WidgetSpacing(), Width=800., Height=600.)
- mainCanvas <- new DrawingCanvas(BackgroundColor=Colors.White)
- mainCanvas.KeyPressed.Add(fun args -> keyDown.Invoke(args.Key.ToString()))
- mainCanvas.KeyReleased.Add(fun args -> keyUp.Invoke(args.Key.ToString()))
- mainCanvas.ButtonPressed.Add(fun args ->
- mouseX <- args.X
- mouseY <- args.Y
- if args.Button = PointerButton.Left then isLeftButtonDown <-true
- mouseDown()
- )
- mainCanvas.ButtonReleased.Add(fun args ->
- mouseX <- args.X
- mouseY <- args.Y
- if args.Button = PointerButton.Left then isLeftButtonDown <- false
- mouseUp()
- )
- mainCanvas.MouseMoved.Add(fun args ->
- mouseX <- args.X
- mouseY <- args.Y
- mouseMove()
- )
- mainWindow.Content <- mainCanvas
- mainCanvas.CanGetFocus <- true
- mainCanvas.SetFocus()
- mainWindow.Show()
- mainWindow.Closed.Add(fun e -> Application.Exit())
- let onRun = unbox<unit->unit> onRun
- onRun ()
- Application.Run()
- let startAppThread () =
- use isInitialized = new AutoResetEvent(false)
- let thread = Thread(ParameterizedThreadStart runApp)
- thread.SetApartmentState(ApartmentState.STA)
- thread.Start(fun () -> isInitialized.Set() |> ignore)
- isInitialized.WaitOne() |> ignore
- do startAppThread()
- member app.Window = mainWindow
- member app.Canvas = mainCanvas
- member app.Invoke action = Application.Invoke action
- member app.KeyUp with set action = keyUp <- action
- member app.KeyDown with set action = keyDown <- action
- member app.MouseDown with set action = mouseDown <- action
- member app.MouseUp with set action = mouseUp <- action
- member app.MouseMove with set action = mouseMove <- action
- member app.MouseX with get() = mouseX
- member app.MouseY with get() = mouseY
- member app.IsLeftButtonDown with get() = isLeftButtonDown
- [<Sealed>]
- type internal My private () =
- static let app = lazy (MyApp())
- static member App = app.Value
- let addDrawing drawing =
- My.App.Invoke (fun () -> My.App.Canvas.AddDrawing(drawing))
- let addDrawingAt drawing (x,y) =
- My.App.Invoke (fun () -> My.App.Canvas.AddDrawingAt(drawing,Point(x,y)))
- [<Sealed>]
- type GraphicsWindow private () =
- static let mutable lastKey : string = null
- static let mutable backgroundColor = Colors.White
- static let mutable width = 640.0
- static let mutable height = 480.0
- static let pen () = Pen(GraphicsWindow.PenColor,GraphicsWindow.PenWidth)
- static let brush () = GraphicsWindow.BrushColor
- static let font () = Font(GraphicsWindow.FontSize,GraphicsWindow.FontBold)
- static let draw drawing = addDrawing drawing
- static let drawAt (x,y) drawing = addDrawingAt drawing (x,y)
- static member Title
- with set title =
- My.App.Invoke (fun () -> My.App.Window.Title <- title)
- static member BackgroundColor
- with get () = backgroundColor
- and set color =
- backgroundColor <- color
- My.App.Invoke (fun () -> My.App.Canvas.BackgroundColor <- color)
- static member Width
- with get () = width
- and set newWidth =
- width <- newWidth
- My.App.Invoke (fun () -> My.App.Window.Width <- newWidth)
- static member Height
- with get () = height
- and set newHeight =
- height <- newHeight
- My.App.Invoke (fun () -> My.App.Window.Height <- newHeight)
- static member val PenColor = Colors.Black with get, set
- static member val PenWidth = 2.0 with get, set
- static member val BrushColor = Colors.Purple with get,set
- static member val FontSize = 12.0 with get,set
- static member val FontBold = false with get,set
- static member DrawLine(x1,y1,x2,y2) =
- DrawLine(Line(x1,y1,x2,y2),pen()) |> draw
- static member DrawRectangle(x,y,width,height) =
- DrawRect(Rect(width,height),pen()) |> drawAt (x,y)
- static member DrawTriangle(x1,y1,x2,y2,x3,y3) =
- DrawTriangle(Triangle(x1,y1,x2,y2,x3,y3),pen()) |> draw
- static member DrawEllipse(x,y,width,height) =
- DrawEllipse(Ellipse(width,height),pen()) |> drawAt (x,y)
- static member DrawImage(imageName,x,y) =
- let imageRef = ref null
- async {
- let! image = loadImageAsync imageName
- imageRef := image
- My.App.Invoke(fun () -> My.App.Canvas.Invalidate())
- } |> Async.Start
- DrawImage(imageRef,x,y) |> draw
- static member DrawText(x,y,text) =
- DrawText(x,y,text,font(),brush()) |> draw
- static member DrawBoundText(x,y,width,text) =
- DrawBoundText(x,y,width,text,font(),brush()) |> draw
- static member FillRectangle(x,y,width,height) =
- FillRect(Rect(width,height),brush()) |> drawAt (x,y)
- static member FillTriangle(x1,y1,x2,y2,x3,y3) =
- FillTriangle(Triangle(x1,y1,x2,y2,x3,y3),brush()) |> draw
- static member FillEllipse(x,y,width,height) =
- FillEllipse(Ellipse(width,height),brush()) |> drawAt (x,y)
- static member LastKey with get() : string = lastKey
- static member KeyUp
- with set (action:unit -> unit) =
- My.App.Invoke (fun () ->
- My.App.KeyUp <- (fun key -> lastKey <- key; action())
- )
- static member KeyDown
- with set (action:unit -> unit) =
- My.App.Invoke (fun () ->
- My.App.KeyDown <- (fun key -> lastKey <- key; action())
- )
- static member MouseX with get() = My.App.MouseX
- static member MouseY with get() = My.App.MouseY
- static member MouseDown
- with set (action:unit -> unit) = My.App.MouseDown <- action
- static member MouseUp
- with set (action:unit -> unit) = My.App.MouseUp <- action
- static member MouseMove
- with set (action:unit -> unit) = My.App.MouseMove <- action
- static member GetColorFromRGB(r,g,b) =
- Color.FromBytes(byte r,byte g,byte b)
- static member Show() = ()
- static member Hide() = ()
- [<Sealed>]
- type Mouse private () =
- static member IsLeftButtonDown = My.App.IsLeftButtonDown
- static member X = My.App.MouseX
- static member Y = My.App.MouseY
- open System.Collections.Generic
- type ShapeInfo = { Shape:Shape; mutable Offset:Point; mutable Opacity:float }
- [<Sealed>]
- type Shapes private () =
- static let pen () = Pen(GraphicsWindow.PenColor,GraphicsWindow.PenWidth)
- static let brush () = GraphicsWindow.BrushColor
- static let font () = Font(GraphicsWindow.FontSize,GraphicsWindow.FontBold)
- static let shapes = Dictionary<string,ShapeInfo>()
- static let addShape name shape =
- let info = { Shape=shape; Offset=Point(); Opacity=1.0 }
- shapes.Add(name,info)
- addDrawing (DrawShape(name,shape))
- static let onShape shapeName action =
- match shapes.TryGetValue(shapeName) with
- | true, info -> action info
- | false, _ -> ()
- static let genName name = name + Guid.NewGuid().ToString()
- static member Remove(shapeName) =
- My.App.Invoke (fun () -> My.App.Canvas.RemoveShape(shapeName))
- static member AddLine(x1,y1,x2,y2) =
- let name = genName "Line"
- LineShape(Line(x1,y1,x2,y2),pen()) |> addShape name
- name
- static member AddRectangle(width,height) =
- let name = genName "Rectangle"
- RectShape(Rect(width,height),pen(),brush()) |> addShape name
- name
- static member AddTriangle(x1,y1,x2,y2,x3,y3) =
- let name = genName "Triangle"
- TriangleShape(Triangle(x1,y1,x2,y2,x3,y3),pen(),brush()) |> addShape name
- name
- static member AddEllipse(width,height) =
- let name = genName "Ellipse"
- EllipseShape(Ellipse(width,height),pen(),brush()) |> addShape name
- name
- static member AddImage(imageName) =
- let name = genName "Image"
- ImageShape(imageName) |> addShape name
- name
- static member AddText(text) =
- let name = genName "Text"
- TextShape(ref text, font(), brush()) |> addShape name
- name
- static member HideShape(shapeName) =
- My.App.Invoke (fun () -> My.App.Canvas.SetShapeVisibility(shapeName,false))
- static member ShowShape(shapeName) =
- My.App.Invoke (fun () -> My.App.Canvas.SetShapeVisibility(shapeName,true))
- static member Move(shapeName,x,y) =
- onShape shapeName (fun info ->
- info.Offset <- Point(x,y)
- My.App.Invoke (fun () -> My.App.Canvas.MoveShape(shapeName,info.Offset))
- )
- static member GetLeft(shapeName) =
- match shapes.TryGetValue(shapeName) with
- | true, info -> info.Offset.X
- | false, _ -> 0.0
- static member GetTop(shapeName) =
- match shapes.TryGetValue(shapeName) with
- | true, info -> info.Offset.Y
- | false, _ -> 0.0
- static member SetOpacity(shapeName, opacity) =
- onShape shapeName (fun info ->
- info.Opacity <- opacity
- My.App.Invoke (fun () -> My.App.Canvas.SetShapeOpacity(shapeName,opacity))
- )
- static member GetOpacity(shapeName) =
- match shapes.TryGetValue(shapeName) with
- | true, info -> info.Opacity
- | false, _ -> 1.0
- static member SetText(shapeName, text) =
- failwith "Not implemented"
- [<Sealed>]
- type Turtle private () =
- static let mutable angle = 0.0
- static let mutable _x = 0.0
- static let mutable _y = 0.0
- static let mutable isPenUp = false
- static member Angle
- with get () = angle
- and set value = angle <- value
- static member X
- with get () = _x
- and set value = _x <- value
- static member Y
- with get () = _y
- and set value = _y <- value
- static member Turn(amount:float) =
- angle <- angle + amount
- static member Move(distance:float) =
- let r = angle * Math.PI / 180.0
- let x' = _x + distance * cos r
- let y' = _y + distance * sin r
- if not isPenUp then
- GraphicsWindow.DrawLine(_x,_y,x',y')
- _x <- x'
- _y <- y'
- static member MoveTo(x:float,y:float) =
- _x <- x; _y = y
- static member PenUp() =
- isPenUp <- true
- static member PenDown() =
- isPenUp <- false
- [<Sealed>]
- type Program private () =
- static member Delay(ms:int) = Thread.Sleep(ms)
- module Math =
- let private rand = System.Random()
- let GetRadians (deg:float) = deg * Math.PI / 180.
- let GetRandomNumber(n) = rand.Next(n)
- type Clock private () =
- static member Hour = DateTime.Now.Hour |> float
- static member Minute = DateTime.Now.Minute |> float
- static member Second = DateTime.Now.Second |> float
- (*
- // [snippet:Turtle sample]
- GraphicsWindow.PenColor <- Colors.Purple
- Turtle.X <- 150.0
- Turtle.Y <- 150.0
- for i in 0..5..200 do
- Turtle.Move(float i)
- Turtle.Turn(90.0)
- // [/snippet]
- // [snippet:Random circles sample]
- let rand = Random()
- let colors = [Colors.Red; Colors.Green; Colors.Blue; Colors.Yellow]
- GraphicsWindow.BackgroundColor <- Colors.Black
- for i = 1 to 1200 do
- GraphicsWindow.BrushColor <- colors.[rand.Next(colors.Length)]
- GraphicsWindow.FillEllipse(rand.NextDouble()*800., rand.NextDouble()*600., 30., 30.)
- // [/snippet]
- // [snippet:Paint program sample]
- let onKeyDown () =
- match GraphicsWindow.LastKey with
- | "K1" -> GraphicsWindow.PenColor <- Colors.Red
- | "K2" -> GraphicsWindow.PenColor <- Colors.Blue
- | "K3" -> GraphicsWindow.PenColor <- Colors.LightGreen
- | s -> System.Diagnostics.Debug.WriteLine(s)
- let mutable prevX = 0.0
- let mutable prevY = 0.0
- let onMouseDown () =
- prevX <- GraphicsWindow.MouseX
- prevY <- GraphicsWindow.MouseY
- let onMouseMove () =
- let x = GraphicsWindow.MouseX
- let y = GraphicsWindow.MouseY
- if Mouse.IsLeftButtonDown then
- GraphicsWindow.DrawLine(prevX, prevY, x, y)
- prevX <- x
- prevY <- y
- GraphicsWindow.BackgroundColor <- Colors.Black
- GraphicsWindow.PenColor <- Colors.White
- GraphicsWindow.MouseDown <- onMouseDown
- GraphicsWindow.MouseMove <- onMouseMove
- GraphicsWindow.KeyDown <- onKeyDown
- // [/snippet]
- *)
- // [snippet:Clock sample]
- let GW = GraphicsWindow.Width
- let GH = GraphicsWindow.Height
- let Radius = 200.0
- let MidX = GW/2.0
- let MidY = GW/2.0
- let initWindow () =
- GraphicsWindow.Show()
- GraphicsWindow.Title <- "Analog Clock"
- GraphicsWindow.BackgroundColor <- Colors.Black
- GraphicsWindow.BrushColor <- Colors.BurlyWood
- GraphicsWindow.DrawEllipse(MidX-Radius-15.,MidY-Radius-5.,Radius*2.+30.,Radius*2.+20.)
- GraphicsWindow.FillEllipse(MidX-Radius-15.,MidY-Radius-5.,Radius*2.+30.,Radius*2.+20.)
- for angle in 1.0..180.0 do
- let X = MidX+(Radius+15.)*Math.Cos(Math.GetRadians(angle))
- let Y1 = MidY+Radius*Math.Sin(Math.GetRadians(angle))+15.
- let Y2 = MidY+(Radius+15.)*Math.Sin(Math.GetRadians(-angle))+10.
- let Blue = Math.GetRandomNumber(40)+30
- GraphicsWindow.PenWidth <- Math.GetRandomNumber(5) |> float
- GraphicsWindow.PenColor <- GraphicsWindow.GetColorFromRGB(Blue+100+Math.GetRandomNumber(10),Blue+60+Math.GetRandomNumber(20),Blue)
- Shapes.AddLine(X,Y1,X,Y2) |> ignore
- GraphicsWindow.BrushColor <- Colors.White
- let ClockNum = Dictionary<_,_>()
- for i in 1. .. 12. do
- let Radians = Math.GetRadians(-i * 30. + 90.)
- ClockNum.[i] <- Shapes.AddText(i.ToString())
- Shapes.Move(ClockNum.[i],MidX-4.+Radius*Math.Cos(Radians),MidY-4.-Radius*Math.Sin(Radians))
- let mutable HourHand = ""
- let mutable MinuteHand = ""
- let mutable SecondHand = ""
- let mutable Hour = 0.
- let mutable Minute = 0.
- let mutable Second = 0.
- let initHands () =
- if (Clock.Hour + Clock.Minute/60. + Clock.Second/3600. <> Hour) then
- Shapes.Remove(HourHand)
- Hour <- Clock.Hour + Clock.Minute/60. + Clock.Second/3600.
- GraphicsWindow.PenColor <- Colors.Black
- GraphicsWindow.PenWidth <- 3.
- HourHand <- Shapes.AddLine(MidX,MidY,MidX+Radius/2.*Math.Cos(Math.GetRadians(Hour*30.-90.)),MidY+Radius/2.*Math.Sin(Math.GetRadians(Hour*30.-90.)))
- if Clock.Minute <> Minute then
- Shapes.Remove(MinuteHand)
- Minute <- Clock.Minute + Clock.Second/60.
- GraphicsWindow.PenColor <- Colors.Blue
- GraphicsWindow.PenWidth <- 2.
- MinuteHand <- Shapes.AddLine(MidX,MidY,MidX+Radius/1.2*Math.Cos(Math.GetRadians(Minute*6.-90.)),MidY+Radius/1.2*Math.Sin(Math.GetRadians(Minute*6.-90.)))
- if Clock.Second <> Second then
- Shapes.Remove(SecondHand)
- Second <- Clock.Second
- GraphicsWindow.PenColor <- Colors.Red
- GraphicsWindow.PenWidth <- 1.
- SecondHand <- Shapes.AddLine(MidX,MidY,MidX+Radius*Math.Cos(Math.GetRadians(Second*6.-90.)),MidY+Radius*Math.Sin(Math.GetRadians(Second*6.-90.)))
- initWindow()
- while true do
- initHands()
- //Sound.PlayClick()
- Program.Delay(1000)
- // [/snippet]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement