This site requires JavaScript, please enable it in your browser!
Greenfoot back
nooby123
nooby123 wrote ...

2012/3/4

Sin, cos, and tan?

nooby123 nooby123

2012/3/4

#
I got found the maths package, but I can't find out how to use them. Help?
danpost danpost

2012/3/4

#
You do not have to 'import' anything, just prefix the functions with 'Math.' (that 'Math', followed by a dot, followed by the function with its parameters).
nooby123 nooby123

2012/3/4

#
Thanks, but it's still not working. The code is:
static double x, y;    
GreenfootImage line=new GreenfootImage(600,600);  

public void act() {
    y=Math.sin(x);
    line.setColor(Color.RED);        
    line.drawLine((int)x,(int)y,(int)x,(int)y);
    setImage(line); 
}

The line isn't drawing.
danpost danpost

2012/3/4

#
I have places to go, and people to meet. I will be back later. But for now, try putting a value in for x in line 5
y = Math.sin((double) 0.5);
and see what happens. If you still do not get line drawing, try changing the length of the line on line 7
line.drawLine((int)x, (int)y, (int)(x + 1), (int)y);
and see if that helps. Gotta go. Check ya on the flipside.
Duta Duta

2012/3/4

#
The problem is (as danpost kind of said) that the line you're attempting to draw is of 0 length (x -> x, y -> y) so it won't draw.
nooby123 nooby123

2012/3/4

#
What should I do?
Duta Duta

2012/3/4

#
Well what are you trying to do?
nooby123 nooby123

2012/3/4

#
I'm trying to draw a line on a graph.
davmac davmac

2012/3/4

#
Do you mean that you're trying to draw a graph of the sine function?
Duta Duta

2012/3/4

#
If its that you're wanting to do, click here. (^Shameless self promotion)
You need to login to post a reply.