Click to See Complete Forum and Search --> : [RESOLVED] drawLine


SepetPhalanx
04-12-2005, 01:26 PM
I have a program, at home (otherwise I would show you it), that draws a spirograph type of drawing by connecting two points.
I want to use drawLine to plot points that are 5 degrees apart without the lines connecting them:
drawLine(int, int, int, int)
but the my calculations for the integers are something like:
double x, y;
int r = 100; //raduis
for (int num = 5; num < 360; num +=5){
x = r*cos(num); //x coord
y = r*sin(num); //y coord
}
I don't remember exactly what the algerythm is but I know it works because when it draws a very rough circle as you might imagine because it rounds the double to a integer somewhere (either to make itself happy or maybe I programmed it that way JUST so it'll compile and execute I don't remember exactly) the only thing I need is something like drawLine(double, double, double, double). Hopefully something like this will cooperate with the applet.
ANY info regarding this will be much appreciated. I can put the algerythem on this thread later tonight (I am posting this at almost 12:30 my time so you have a bit of waiting to do if you need to see it :p )
Thanks

SepetPhalanx
04-13-2005, 12:07 AM
Ok here's what you've been waiting patiently for...

import java.awt.*;
import java.awt.event.*;

public class Design
{
public static void main(String args[])
{
Windows win = new Windows();
win.setSize(800,600);
win.addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);}});
win.show();
}
}

class Windows extends Frame
{
public void paint(Graphics g)
{
design(g);
}
public void design(Graphics g)
{
double xCoord[] = new double[360];
//int xCoord[] = new int[360];
double yCoord[] = new double[360];
//int yCoord[] = new int[360];
int center = 300;
int radius = 200;
double x, y;
//int x, y;
int m;
int k = 0;

for(m = 1; m <= 360; m++)
{
k++;
xCoord[m] = (Math.cos(k) * radius) + center;
yCoord[m] = (Math.sin(k) * radius) + center;
x = xCoord[m];
y = yCoord[m];
g.drawLine(x, y, x, y);
}
}
}
--------------------Configuration: java14 <Default>--------------------
C:\Documents and Settings\Andy\My Documents\JavaRelatedStuff\Design\Design.java:43: drawLine(int,int,int,int) in java.awt.Graphics cannot be applied to (double,double,double,double)
g.drawLine(x, y, x, y);
^
1 error

Process completed.
Any suggestions?

ray326
04-13-2005, 12:34 AM
Subclass Graphics and override drawLine() with a version that takes four doubles, converts them to ints and calls super.drawLine() with them.

SepetPhalanx
04-13-2005, 12:31 PM
i don't want to convert them to int. is there a way to graph a point with a double coord instead of an int?

ray326
04-14-2005, 12:20 AM
I doubt it. Raster interfaces are integer things. Maybe you want to find a JNI interface to an OpenGL library.