L
L
LazariusPaskalius2019-12-02 13:50:41
Java
LazariusPaskalius, 2019-12-02 13:50:41

When drawing a graph, half of it is erased, how can I fix this?

I'm creating a straight line graph in java, it should look like this: r7WIW.pngWhen drawing, the entire graph is drawn, but then its right side disappears, how can I fix this?

import java.awt.*;

class FillPolygonCanvas extends Canvas{
    public int x0 = 200;
    public int y0 = 200;
    public int a = 100;
    public double y;
    public double x;
    public double r;
    public double fi=-(Math.PI/4);
    public void paint(Graphics g){
       Polygon poly = new Polygon();
       Polygon poly1 = new Polygon();
        while (fi<=Math.PI/4){
            r=a*Math.sqrt(2*Math.cos(2*fi));
            x=r*Math.cos(fi);
            y=r*Math.sin(fi);
            if(fi==-Math.PI/4){
                poly1.addPoint(x0,y0);
            }else{
                poly1.addPoint(x0+(int)x,y0-(int)y);
            }
            fi=fi+0.0001;
            g.drawPolygon(poly1);
        }


        fi=3*Math.PI/4+0.0001;
       while (fi<=5*Math.PI/(4-0.0001)){   //left
           r=a*Math.sqrt(2*Math.cos(2*fi));
           x=r*Math.cos(fi);
           y=r*Math.sin(fi);
           if(fi==3*Math.PI/4+0.0001){
               poly.addPoint(x0,y0);
           }else{
               poly.addPoint(x0+(int)x,y0-(int)y);
           }
           fi=fi+0.0001;

       }
        g.drawPolygon(poly);



    }
}
class MyFrame extends Frame{
    public MyFrame(){
        super("Graphics");
//        setLayout(new GridLayout(3,3));
        add(new FillPolygonCanvas());
        setSize(500,300);
        setVisible(true);

    }

}
public class Main{
    public static void main(String[] args) {
        Frame f = new MyFrame();
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
gansm, 2019-12-12
@LazariusPaskalius

transfer fi to paint - rubs

public void paint(Graphics g){
       Polygon poly = new Polygon();
       Polygon poly1 = new Polygon();
       double fi=-(Math.PI/4);
....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question