Private Gist
All pages are served over SSL and all pushing and pulling is done over SSH. No one may fork, clone, or view it unless they are given this private URL.
Every gist with this icon (
) is private.
Public Gist
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#light
open System
open Cairo
open Gtk
open Gdk
Gtk.Application.Init()
let window = new Gtk.Window("Fucull")
let drawingArea = new Gtk.DrawingArea()
drawingArea.AddEvents((int)Gdk.EventMask.ButtonPressMask)
drawingArea.AddEvents((int)EventMask.ButtonReleaseMask)
drawingArea.AddEvents((int)EventMask.KeyPressMask)
drawingArea.AddEvents((int)EventMask.PointerMotionMask)
let points = new ResizeArray<Cairo.Point>()
let click (x, y) =
let p = new Cairo.Point(x, y)
points.Add(p)
()
let sketchCircle (c:Cairo.Context, xc, yc, r) =
c.Save()
c.Translate (xc, yc)
c.MoveTo (r, 0.)
c.Arc (0., 0., r, 0., (2.*Math.PI))
c.ClosePath()
c.Restore()
let drawBackground (c:Cairo.Context, w, h) =
c.Save()
c.Color <- new Cairo.Color(32./255., 74./255., 135./255.) //blue
c.LineWidth <- 1.
c.Rectangle(0.5, 0.5, (float)w - 1., (float)h - 1.)
c.FillPreserve()
c.Color <- new Cairo.Color(0., 0., 0.) //black
c.Stroke()
c.Restore()
let drawPoint (c:Context, point:Cairo.Point) =
c.Save()
let x = (float)point.X
let y = (float)point.Y
let radius = 3.5
let lineLength = 11.
let lineThickness = 1.
sketchCircle(c, (Math.Floor(x):float) + 0.5, (Math.Floor(y):float) + 0.5, radius)
c.Color <- new Cairo.Color(1., 1., 1.) //white
c.LineWidth <- lineThickness
c.MoveTo(Math.Floor(x) + 0.5, Math.Floor(y) - 5.)
c.LineTo(Math.Floor(x) + 0.5, Math.Floor(y) + 6.)
c.MoveTo(Math.Floor(x) - 5., Math.Floor(y) + 0.5)
c.LineTo(Math.Floor(x) + 6., Math.Floor(y) + 0.5)
c.Stroke()
c.Restore()
let drawPoints (c:Context) =
ResizeArray.iter (fun p -> drawPoint(c, p)) points
let draw (c:Context, w, h) =
drawBackground (c, w, h)
drawPoints (c)
let doTheVooDoo(da:Gtk.DrawingArea) =
use drawable = da.GdkWindow
let w, h = da.Allocation.Width, da.Allocation.Height
use cairoContext = Gdk.CairoHelper.Create (drawable)
draw(cairoContext, (float)w, (float)h)
window.WindowPosition <- Gtk.WindowPosition.Center
window.SetDefaultSize(640, 480)
window.Destroyed.Add (fun _ -> Application.Quit() )
drawingArea.ExposeEvent.Add (fun _ -> doTheVooDoo(drawingArea))
drawingArea.ButtonReleaseEvent.Add (fun e ->
click((int)e.Event.X, (int)e.Event.Y)
drawingArea.QueueDraw()
)
window.Add(drawingArea)
window.ShowAll()
Gtk.Application.Run()
Please log in to comment.







