Help why program won't do what I have programmed

I am trying to get the program to draw is something that looks like this:

http://www.portmain.com/intro/hw/hw05-field.html

instead of the program drawing the lines that I need based on the acceleration that is calculated, it does not draw the lines at all. This part of the code where I think I am having problems is in the draw_field function. Does anyone know where I am going wrong in my code and why it is not drawing the lines?

Here is my code:



// Oct 10, 2011
// The purpose of this program is to open a graphics window and
// chart an acceleration field amongst three different sized
// stars within the chart.
//
//-------------------------------------------------------------
// Directives:
#include <iostream> // In case I want to debug with cout
#include <cstdlib> // Provides EXIT_SUCCESS
#include <graphics.h> // All the graphics functions
#include <cmath> // Includes all math functions
using namespace std;
//-------------------------------------------------------------

//-------------------------------------------------------------
// Global Named Constants
const int S = 500; // Size of a square graphics window
const double G = 6.67300e-11; // Gravity
const double W_MAX = 2.5e11; // Max World Coordinate
const double W_MIN = -2.5e11; // Max World Coordinate

//-------------------------------------------------------------

//-------------------------------------------------------------
// Function Prototypes.

// The dist function finds the distance between two points
//(x1, y1) and (x2, y2) with integer coordinates, for instance
// two pixels on the screen.
double distance(double x1, double y1, double x2, double y2);

// The parameters x and y give the location of a spaceship in a
// two-dimensional star field. The parameters sx and sy give the
// location of a star of mass m in this field. The return value
// is the acceleration along the y-axis that the ship feels from
// the star. All distances are in meters and the mass
// is in kilograms. The answer is in m/sec^2.
double accy(double x, double y, double sx, double sy, double m);

// The parameters x and y give the location of a spaceship in a
// two-dimensional star field. The parameters sx and sy give the
// location of a star of mass m in this field. The return value
// is the acceleration along the x-axis that the ship feels from
// the star. All distances are in meters and the mass
// is in kilograms. The answer is in m/sec^2.
double accx(double x, double y, double sx, double sy, double m);

// pixel(wx, w0, w1, p0, p1) converts wx from an interval that
// ranges from w0 to w1 into an integer interval that ranges
// from p0 to p1.
int pixel(double wx, double w0, double w1, int p0, int p1);

// draw_field draws the the chart with points at certain pixels
void draw_field();

// draws the yellow planet
void draw_yellow();

// draws the blue planet
void draw_blue();

// draws the red planet
void draw_red();

//-------------------------------------------------------------


//-------------------------------------------------------------
int main()
{
double pixel_location = 0;

initwindow(S, S, "Field of Dreams");

pixel(0, W_MIN, W_MAX, 0, S);

while(pixel_location <= 500)
{
draw_field();
++ pixel_location;


draw_yellow();
draw_blue();
draw_red();
}


delay(60000);
return EXIT_SUCCESS;
}
//-------------------------------------------------------------

//-------------------------------------------------------------

int pixel(double wx, double w0, double w1, int p0, int p1)
{

double world_width = w1 - w0;
double pixel_width = p1 - p0;

double fraction = (wx - w0)/world_width;

return int (p0 + fraction * pixel_width);

}

//-------------------------------------------------------------

void draw_field()
{
double x, y;
int px, py;
int blue_px = pixel(-4.5e10, W_MIN, W_MAX, 0, S);
int blue_py = pixel(-3.0e10, W_MIN, W_MAX, 0, S);
int red_px = pixel(4.5e10, W_MIN, W_MAX, 0, S);
int red_py = pixel(-9.0e10, W_MIN, W_MAX, 0, S);
int yellow_px = pixel(3e10, W_MIN, W_MAX, 0, S);
int yellow_py = pixel(7.5e10, W_MIN, W_MAX, 0, S);


for (x = W_MIN; x <= W_MAX; x += W_MAX/6)
{
for (y = W_MIN; y <= W_MAX; y += W_MAX/6)
{

px = pixel(x, W_MIN, W_MAX, 0, S);
py = pixel(y, W_MIN, W_MAX, 0, S);

putpixel(px, py, WHITE);

double blue_accx = accx(px, py, blue_px, blue_py, 7);
double blue_accy = accy(px, py, blue_px, blue_py, 7);
double red_accx = accx(px, py, red_px, red_py, 9);
double red_accy = accy(px, py, red_px, red_py, 9);
double yellow_accx = accx(px, py, yellow_px, yellow_py,
5);
double yellow_accy = accy(px, py, yellow_px, yellow_py,
5);

int length_x = ((blue_accx + red_accx + yellow_accx)
* pixel(5.0e10, W_MIN, W_MAX, 0, S));
int length_y = ((blue_accy + red_accy + yellow_accy)
*pixel(5.0e10, W_MIN, W_MAX, 0, S));

if(length_x || length_y < W_MAX/7.07107)
{
int ax = px + length_x;
int ay = py - length_y;
line(px, py, ax, ay);

}
}
}
}

//-------------------------------------------------------------

void draw_yellow()
{
// Convert world coordinates to pixel coordinates
int px = pixel(3e10, W_MIN, W_MAX, 0, S); // X coord
int py = pixel(7.5e10, W_MIN, W_MAX, 0, S); // Y coord

// Draw yellow circle
setfillstyle(SOLID_FILL, YELLOW);
fillellipse(px, py, 5, 5);
}


//-------------------------------------------------------------

void draw_blue()
{
// Convert world coordinates to pixel coordinates
int px = pixel(-4.5e10, W_MIN, W_MAX, 0, S); // X coord
int py = pixel(-3.0e10, W_MIN, W_MAX, 0, S); // Y coord

// Draw blue circle
setfillstyle(SOLID_FILL, BLUE);
fillellipse(px, py, 7, 7);
}

//-------------------------------------------------------------

void draw_red()
{
// Convert world coordinates to pixel coordinates
int px = pixel(4.5e10, W_MIN, W_MAX, 0, S); // X coord
int py = pixel(-9.0e10, W_MIN, W_MAX, 0, S); // Y coord

// Draw red circle
setfillstyle(SOLID_FILL, RED);
fillellipse(px, py, 9, 9);
}

//---------------------------------------------------------------

double accx(double x, double y, double sx, double sy, double m)
{
double dx = (sx - x);
double dy = (sy - y);
double denominator = pow(dx*dx + dy*dy, 1.5);

return G*m*dx/denominator;
}
//--------------------------------------------------------------

double accy(double x, double y, double sx, double sy, double m)
{
double dx = (sx - x);
double dy = (sy - y);
double denominator = pow(dx*dx + dy*dy, 1.5);

return G*m*dy/denominator;
}
//-------------------------------------------------------------

double distance(double x1, double y1, double x2, double y2)
{
return pow(pow(x1-x2, 2) + pow(y1-y2, 2), 0.5);
}

//-------------------------------------------------------------

//-------------------------------------------------------------

//-------------------------------------------------------------


//-------------------------------------------------------------

//-------------------------------------------------------------
Topic archived. No new replies allowed.