Commits

insolor committed 801f6db

plot3d: Some refactoring

Comments (0)

Files changed (1)

 origin_x = 400
 origin_y = 150
 
-integer func_no
-integer grid_width, fine
+-- integer func_no
+integer grid_width--, fine
 integer x_res, y_res
 
 atom h_magnifier, v_magnifier
     end if
 end function
 
-function the_function(atom x, atom y)
+function the_function(atom x, atom y, integer func_no)
 -- compute a function z of two variables x and y
 -- There are actually several different functions below,
 -- selected by the func_no variable
-    sequence pq, pr, ps -- points in the plane
-    atom dq, dr, ds     -- distance from p
-    atom z, w
 
     if func_no = 1 then
 	return 100*x*x + 100*y*y - 50
 	return 50 * cos(8*(x+y))
 
     elsif func_no = 5 then
+	atom z, w
 	z = 50 * cos(50 * sqrt(x*x+y*y))
 	if z >= -0.01 then
 	    if (x < 0 and y < 0) or (x > 0 and y > 0) then
 	    return -0.01
 	end if
     elsif func_no = 6 then
+	sequence pq, pr, ps -- points in the plane
+	atom dq, dr, ds     -- distance from p
 	pq = {.6, -.4}
 	pr = {-.6, 0}
 	ps = {.5, +.5}
 	    v_magnifier * (origin_y - z + k)}
 end function
 
-procedure plot(atom x, atom y)
+procedure plot(atom x, atom y, integer func_no)
 -- plot the point according to 3-D perspective
     atom z, col
     sequence coord
 
-    z = the_function(x, y)
+    z = the_function(x, y, func_no)
     coord = set_coord(x, y, z)
     note_extreme(coord, z)
     -- select color by quadrant
     prev_coord = coord
 end procedure
 
-function plot_a_function()
+function plot_a_function(integer func_no, integer fine)
 -- generate 3d plotted graph
 
     for x = x_min to x_max by grid_width * x_inc do
 	end if
 	prev_coord = {}
 	for y = y_min to y_max by fine * y_inc do
-	    plot(x, y)
+	    plot(x, y, func_no)
 	end for
     end for
 
 	end if
 	prev_coord = {}
 	for x = x_min to x_max by fine * x_inc do
-	    plot(x, y)
+	    plot(x, y, func_no)
 	end for
     end for
     return 1
 
 procedure plot3d()
 -- main program
-    func_no = 1
+    integer func_no = 1
     while func_no <= NFUNCS do
 	set_range()
 	-- do a quick trial run to establish range of values
 	grid_width = 20
-	fine = 4
-	if plot_a_function() then
+	integer fine = 4
+	if plot_a_function(func_no, fine) then
 	    clear_screen()
 	    box()
 	    -- make next one fit screen better
 	    origin_y -= yc_min
 	    grid_width = 20
 	    fine = 1
-	    if plot_a_function() then
+	    if plot_a_function(func_no, fine) then
 		position(2, 2)
 		printf(SCREEN, "x: %5.1f to %4.1f", {x_min, x_max})
 		position(3, 2)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.