#include #include #include #define WINDOW_WIDTH 800 #define WINDOW_HEIGHT 600 double cubed(double x){ return x*x*x; } double squared(double x){ return x*x; } double mod2(double x){ return (double)((int)x%2); } double half(double x){ return x/2; } #define SQRT_MAGIC_F 0x5f3759df double sqrt2_quake_weird(const double x){ const double xhalf = 0.5f*x; union{ double x; int i; } u; u.x = x; u.i = SQRT_MAGIC_F - (u.i >> 1); // gives initial guess y0 return x*u.x*(1.5f - xhalf*u.x*u.x);// Newton step, repeating increases accuracy } typedef struct{ float r; float g; float b; } Clr; Clr red_clr={1.0f,0.0f,0.0f}; Clr green_clr={0.0f,1.0f,0.0f}; Clr blue_clr={0.0f,0.0f,1.0f}; Clr white_clr={1.0f,1.0f,1.0f}; Clr yellow_clr={1.0f,1.0f,0.0f}; double integral(Clr color,double a,double b,double dx,double(*f)(double)){ if (dx <= 0.0) { printf("Error: dx must be positive.\n"); return 0.0; } double sum=0.0; double old_x=0.0; double old_y=0.0; for(double x=a;x