#include "library.h" const int screen_size = 600; const double function_max = 60.0; const double pi = acos(-1.0); double f1(double x, double y) { const double w = x/3, z = y/3; const double a = sqrt(w*w+z*z); const double b = sin(a)/pi; const double c = sqrt((w-5)*(w-5)+(z-2)*(z-2)); const double d = cos(c)/pi; return 9.86*b*d; } void screen_pos_to_function(int scrx, int scry, double & x, double & y) { x = (scrx-screen_size/2.0)/(screen_size/2.0)*function_max; y = (screen_size/2.0-scry)/(screen_size/2.0)*function_max; } void function_to_screen_pos(double x, double y, int & scrx, int & scry) { scrx = (int)(x/function_max*(screen_size/2)+screen_size/2); scry = screen_size/2-(int)(y/function_max*(screen_size/2)); } void draw_cross(int x, int y) { move_to(x-10, y-10); draw_to(x+10, y+10); move_to(x-10, y+10); draw_to(x+10, y-10); } void main() { make_window(screen_size, screen_size); while (true) { wait_for_mouse_click(); int scrx = get_click_x(), scry = get_click_y(); cout << "(" << scrx << ", " << scry << ") -> "; double x, y; screen_pos_to_function(scrx, scry, x, y); cout << x << ", " << y << " -> "; int nx, ny; function_to_screen_pos(x, y, nx, ny); cout << "(" << nx << ", " << ny << ")\n"; draw_cross(nx, ny); } } /* double minz=f1(0, 0); double maxz=minz; for (int scrx=0; scrxmaxz) maxz=z; if (z0) set_pixel_color(scrx, scry, make_color(z, 0, 0)); else set_pixel_color(scrx, scry, make_color(0, 0, -z)); } } cout << "min = " << minz << "\n"; cout << "max = " << maxz << "\n"; } */