simplegraph2.frink

Download or view simplegraph2.frink in plain text format


// This is a simple but rather interesting program that graphs equations.
// You enter equations in terms of x and y, something like one of the
// following:
//
//  y = sin[x]
//
//  x^2 + y^2 = 81
//
//  y cos[x] = x sin[y]
// 
lasteq = ""

while func = input["Enter equation: ", lasteq]
{
   lasteq = func
   func =~ %s/=/ PEQ /            // Replace = with possibly equals
   expr = parseToExpression[func]
   
   g = new graphics
   
   xsteps = 1024
   xmin = -10
   xmax = 10
   xstep = (xmax-xmin) / xsteps

   ysteps = 1024
   ymin = -10
   ymax = 10
   ystep = (ymax-ymin) / ysteps

   for yy=ymax to ymin step -ystep
   {
      y = new interval[yy, yy+ystep]
      for xx=xmin to xmax step xstep
      {
         x = new interval[xx, xx+xstep]

         if eval[expr]
            g.fillRectSize[xx,-yy,xstep,ystep]
      }
   }

   g.drawRectSides[xmin,ymin,xmax,ymax]

   g.show[]
}


Download or view simplegraph2.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 19963 days, 16 hours, 13 minutes ago.