Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System.Windows.Forms
- open System.Drawing
- let DEF_SPEED()=new PointF(0.f,0.f) //velocità di default
- let DEF_DENSITY= 1.f
- let f= new Form(TopMost=true)
- f.Size <- Size(800,600)
- f.Show()
- type Pyshape(d:float32,v:PointF) =
- let mutable density = d
- let mutable speed = v
- abstract member drawshape:Graphics -> unit
- default this.drawshape(g:Graphics) = (printfn "metodo del supertipo")
- type Circle(d,v,c:PointF,r:float32) =
- inherit Pyshape(d,v)
- let mutable rad = r
- let mutable center = c
- let mutable mass = r*r*(single System.Math.PI)*d
- let getRadius() = r
- let setRadius(r1) =
- rad <- r1;
- override this.drawshape (g:Graphics)=
- g.FillEllipse(Brushes.Aquamarine, int center.X - int rad, int center.Y - int rad, 2* int rad, 2* int rad)
- type Editor() =
- inherit UserControl()
- let shapes= new System.Collections.Generic.List<Pyshape>()
- let mutable tool=0
- let mutable tmp_radius = 0.f
- let mutable tmp_center = new PointF()
- let mutable drawing = false
- let abort() =
- match tool with
- |0->
- drawing <- false
- tmp_radius <- 0.f;
- | _ -> ()
- let acquireShape(list:System.Collections.Generic.List<Pyshape>)=
- match tool with
- |1->
- let c= new Circle(DEF_DENSITY,DEF_SPEED(),tmp_center,tmp_radius)
- list.Add(c)
- |_-> ()
- let pitagora(x1:float32,y1:float32,x2:float32,y2:float32) =
- sqrt( (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2) )
- override this.OnMouseDown e=
- let tmp_loc = e.Location
- tmp_center <- PointF(single tmp_loc.X, single tmp_loc.Y)
- drawing <- true;
- override this.OnMouseMove e=
- let tmp_loc = new PointF(single e.Location.X,single e.Location.Y)
- match drawing with
- |true ->
- tmp_radius <- pitagora(tmp_loc.X,tmp_loc.Y,tmp_center.X,tmp_center.Y)
- this.Invalidate()
- |false ->
- this.Invalidate()
- override this.OnMouseUp e=
- match drawing with
- |true ->
- acquireShape(shapes)
- drawing <- false;
- tmp_radius <- 0.f;
- this.Invalidate()
- |false ->()
- override this.OnKeyDown e=
- match e.KeyCode with
- |Keys.Escape ->
- match drawing with
- |true ->
- abort()
- this.Invalidate()
- | _ -> ()
- | _ -> ()
- override this.OnPaint e =
- let g = e.Graphics
- g.DrawEllipse(Pens.Black, int tmp_center.X - int tmp_radius, int tmp_center.Y - int tmp_radius, 2* int tmp_radius, 2* int tmp_radius);
- for c in shapes do(
- c.drawshape(g)
- )
- let e=new Editor(Dock=DockStyle.Fill)
- f.Controls.Add(e)
- e.Focus()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement