簡體   English   中英

使用標准繪圖在Dr.Java中填充三角形

[英]Filling in Triangles in Dr.Java using standard draw

所以我有這個程序,我必須畫一個鏟子,球桿,心形和均勻大小的鑽石。 我完成了形狀,但無法弄清楚如何填充用於鍬和棍棒的三角形。 非常感謝您的幫助!

唯一的問題:填充三角形。

    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

在線找到stdDraw 這應該做您需要的。 這樣做的關鍵是要了解坐標的順序很重要。 例如, xc[1]y[1]組成一個點,依此類推。

//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 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM