Heart Line equation: R=a (1-sinθ)
Convert to parametric equation
X=2R (sin (t)-sin (2t)/2)
y=2r (cos (t)-cos (2t)/2)
Program code:
Learn more about F# on http://fsharp.net // See the f# Tutorial project for more help. DLL if not, you need to add the reference manually Open system.drawingopen system.windows.forms[<entrypoint>]let main argv = system.console.writeline ("Heart Line Drawing Program by tsybius") system.console.writeline ("September 21, 2014 21:53:52") System.Console.WriteLine ("=============================\n") system.console.writeline (" Building Forms (Form) //add form Form let frmheart = new form () //set form Properties frmheart.name <- "Frmheart" frmHeart.Text <- "Heart Line r=a (1-sinθ)" frmheart.autoscaledimensions <- new system.drawing.sizef (6.0f, 12.0f) frmheart.autoscalemode <-&nBsp system.windows.forms.autoscalemode.font frmheart.clientsize <- new System.Drawing.Size (480, 458) frmHeart.FormBorderStyle <- system.windows.forms.formborderstyle.fixed3d frmheart.startposition <- system.windows.forms.formstartposition.centerscreen //frmheart.backcolor <- System.Drawing.SystemColors.ActiveCaption frmHeart.MaximizeBox <- false frmheart.minimizebox <- false frmheart.showicon <- false frmheart.topmost <- true system.console.writeline ("Building picture Frame (PictureBox)") //set up picture frame picturebox let picimage = new System.Windows.Forms.PictureBox () picimage.dock <- system.windows.forms.dockstyle.fill Picimage.location <- new system.drawing.point (0, 0) picimage.name <- "Picimage" picImage.Size <- new System.Drawing.Size (480, 458) picImage.BackColor <- system.drawing.systemcolors.activecaption picimage.image <- new Bitmap (picimage.width, picimage.height) frmheart.controls.add (picImage) system.console.writeline ("Start drawing image") //drawing image let grph: graphics = graphics.fromimage (picImage.Image) system.console.writeline ("Draw horizontal axis") //Horizontal axis grph. DrawLine ((New pen (brushes.green, 5.0f)), 30, 135, 450, 135) grph. FillPolygon (brushes.green, //left arrow [| new Point (60, 125); new point (10, 135); new point (60, 145 ); new point (90, 135) |]); grph. FillPolygon (brushes.green, //right ARROW [| new point ( 420, 125); new point (470, 135); new point (420, 145); new point (390, 135) |]); &Nbsp; system.console.writeline ("Draw vertical axis") //longitudinal axis grph. DrawLine ((New pen (brushes.green, 5.0f)), 240, 30, 240, 428) grph. FillPolygon (brushes.green, //on the side arrow [| new Point (240,&NBSP;20); new point (225, &NBSP;30); new point (240, 70) ; new point (255, 30) |]); grph. FillPolygon (brushes.green, //lower side Arrow [| new Point (240, 370); new point (225, 400); &nBsp; new point (240, 445); new point (255, 400) |]); System.Console.WriteLine ("Draw Heart Line") //Heart Draw begins let r = 50.0 let funt (T: int) = (float) t * 2.0 * 3.1416 / 10000.0 : float //Horizontal let funx (t: float) = -1 * ( int) (2.0 * r * (sin (t) - sin (2.0 * t) / 2.0 + 0.5) ) : int //ordinate let funy (t: float) = -1 * (int) (2.0 * r * (cos (t) - cos (2.0&NBSP;*&NBSP;T) / 2.0 + 0.5)) : int let p: Point[] = &NBSP;&NBSP;[|&NBSP;FOR&NBSP;T&NBSP;IN&NBSP;0&NBSP, .... 10000 -> new Point (Funx (Funt (t)) + 290, funy (Funt (t)) + 235) |] grph. FillPolygon (brushes.pink, p) grph. DrawPolygon ((New pen (brushes.red, 5.0f)), p) // Heart Draw End system.console.writeline ("draw character") Let brushstr1 = new solidbrush (Color.Blue) let fontstr1 = new font ("Consolas", 24.0f) grph. DrawString ("cardioid", fontstr1, brushstr1, 160.0f, 175.0f ) grph. DrawString ("R=a (1-sinθ)", fontstr1, brushstr1, 140.0f, 215.0f ) system.console.writeline ("Draw signature: Tsybius") let Brushstr2 = new solidbrush (Color.White) let fontstr2 = New font ("Consolas", 24.0f) grph. DrawString ("TSYBIUS&NBSP;2014/9/21", fontstr2, brushstr2, 150.0f, 405.0f ) system.console.writeline (open form) //open the form let result = frmheart.showdialog () system.console.writeline () //Press any key to continue (exit) System.Console.WriteLine ("Press any key to continue") let temp = system.console.readkey () let&nBsp;temp = system.console.write ("\b\t") //Delete the pressed "any key" character 0 // Returns an integer exit code
To run the example:
END
F # Draws a heart line in a PictureBox in a form