Welcome to Phrogram Sign in | Join | Help
in Search


PlotCosineFunction - an example for David Brin

Last post 09-26-2006, 5:29 PM by JonS. 0 replies.
Sort Posts: Previous Next
  •  09-26-2006, 5:29 PM 675

    PlotCosineFunction - an example for David Brin

    Here's a link to my blog post, which responds to a comment directly from David, about his essay "Why Johnny Can't Code."

    http://theschwartz.wordpress.com/2006/09/26/david-brin-proves-blogs-work/ 

    The attached zip file (see link above) has the Phrogram code for this example. 

    Here a screenshot: 

     

    And here's the code, pasted:

     

    Program PlotCosineFunction

     

          Method Main()

     

                Define X As Decimal = -300.0

                Define Y As Decimal = 0.0

                Define myPen As Pen

               

                SetAlgebraCoordinates()

         

                // Draw the axes

                myPen.LineWidth = 3

                myPen.Color = Colors.Black

                myPen.MoveTo(-300, 0)

                myPen.DrawTo(300, 0)

                myPen.MoveTo(0,-300)

                myPen.DrawTo(0, 300)

               

                // draw the function

                myPen.Color = Blue

               

                Define LastX As Decimal

                Define LastY As Decimal

               

                While X < 300

               

                      LastX = X

                      LastY = Y

     

                      // Divide and multiply by 40 in order to exagerate the

                      // function so it's pattern is visible using pixel

                      // coordinates.  You can see different functions plotted

                      // by commenting one out and uncommenting another

                      Y = Cos(X / 40) * 40          // Cosine function

                      //Y = Sin(X / 40) * 40          // Sine function

                      //Y = Tan(X / 40) * 40        // Tangent function

                      //Y = ArcTan(X / 40) * 40     // ArcTangent function

                      //Y = ((X/40) * (X/40)) * 40  // X squared is a parabola

                     

                      X = X + 3

     

                      // Don't draw the line when calculating the very first point

                      If LastX > -300 Then

                            myPen.DrawTo( X, Y )

                      Else

                            myPen.MoveTo( X, Y )

                      End If

                     

                End While

     

          End Method

     

    End Program

     

    This could of course be a fancier example, but in the interests of blogging an example I wanted to keep it as simple as possible.

View as RSS news feed in XML