So I have this program where I had to draw a spade, club, heart, and a diamond in uniform size. I accomplished the shapes but cannot figure out how to fill the triangles used for the spade and club. Would really appreciate any help!

Only Problem: Fill triangles.

    public class CardSymbols
    { //beginning program
      public static void main(String[] args)
       { //beginning method
         StdDraw.setXscale(-1.5, +1.5);
         StdDraw.setYscale(-1.5, +1.5);

         //Drawing a Heart
        StdDraw.setPenColor(StdDraw.RED);//color for Heart & Diamond
        double[] xh = {.6,.7,.8,.7};
        double[] yh = {-.725,-.825,-.725,-.625};;
        StdDraw.filledPolygon(xh, yh); //diamond
        StdDraw.filledCircle(+.65, -.675, .1 / Math.sqrt(2)); //half circles
        StdDraw.filledCircle(.75, -.675, .1 / Math.sqrt(2)); //half circles


        //Drawing a Diamond
        double[] xd = {.6,.7,.8,.7};
        double[] yd = {.775,.9,.775,.65};
        StdDraw.filledPolygon(xd,yd);

        //Drawing a Spade
        StdDraw.setPenColor(StdDraw.BLACK);
        double[] xs = {-.6,-.7,-.8,-.7};
        double[] ys = {-.7,-.8,-.7,-.6};
        StdDraw.filledPolygon(xs,ys); //diamond
        StdDraw.filledCircle(-0.75, -0.75,.1 / 1.4142); //half circle
        StdDraw.filledCircle(-0.65, -0.75,.1 / 1.4142); //half circle
        StdDraw.line(-0.7,-0.8, -.75,-.85); 
        StdDraw.line(-0.7,-0.8,-.65,-.85);   //forming a triangle
        StdDraw.line(-0.75,-0.85,-.65,-.85); 


        //Drawing a Club
       StdDraw.filledCircle(-0.75, 0.75,.1 / 1.4142); //half circle
       StdDraw.filledCircle(-0.65, 0.75,.1 / 1.4142); //half circle
       StdDraw.filledCircle(-0.7, 0.835,.1 / 1.4142); //half circle
       StdDraw.line(-0.7,0.7, -.75,.65); 
       StdDraw.line(-0.75,0.65,-.65,.65); //forming a triangle
       StdDraw.line(-0.65,0.65,-.7,.7); 
      } //end method
     } //end program
有帮助吗?

解决方案

Found stdDraw online. This should do what you need. The key to this is to understand that the order of the coords matter. For example, xc[1] and y[1] compose one point, and so on.

//club
double[] xc = {-.7,-.75,-.65};
double[] yc = {.7,.65,.65};
StdDraw.filledPolygon(xc,yc);

//spade
double[] xs1 = {-.7,-.75,-.65};
double[] ys1 = {-.8,-.85,-.85};
StdDraw.filledPolygon(xs1,ys1);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top