// 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] // // This uses a recursive method to subdivide and test rectangles. use ArbitraryPrecision.frink lasteq = "" while func = input["Enter equation: ", lasteq] { lasteq = func func =~ %s/>=/ PGE /g // Replace >= with possibly greater than or equals func =~ %s/<=/ PLE /g // Replace <= with possibly less than or equals func =~ %s/!=/ PNE /g // Replace != with possibly not equals func =~ %s/>/ PGT /g // Replace > with possibly greater than func =~ %s/= 0) { cx = (x1 + x2)/2 cy = (y1 + y2)/2 testRect[x1, cx, y1, cy, g, eq, nextLevel] testRect[cx, x2, y1, cy, g, eq, nextLevel] testRect[x1, cx, cy, y2, g, eq, nextLevel] testRect[cx, x2, cy, y2, g, eq, nextLevel] } else if (res) // Valid point g.fillRectSides[x1, -y1, x2, -y2] else { // Error in evaluating point g.color[1,0,0] g.fillRectSides[x1, -y1, x2, -y2] g.color[0,0,0] } } }