Java海龟画图turtle多彩螺旋线

利用turtle画多彩螺旋线

思路: 在画正多边形的基础上,步长不是一直相同,而是越来越长,并且角度比画正多边形需要的角度多一些,每次拐弯变换颜色。
    Size是螺旋的大小 Step的每一步的长度,每走一步拐弯一次 Densi是密度,角度越小,螺旋越密 ColorNum是色彩的数量,更改时要在switch里更改
/**
     * Draw your personal, custom art.
     * 
     * Many interesting images can be drawn using the simple implementation of a
     * turtle. For this function, draw something interesting; the complexity can be
     * as little or as much as you want.
     * 
     * @param turtle the turtle context
     */
    public static void drawPersonalArt(Turtle turtle) {
          
   
	int Size = 400, Step = 1, Densi = 1, ColorNum = 5;
	for (int i = 1; i <= Size; i++) {
          
   
	    switch (i % ColorNum) {
          
   
	    case 0:
		turtle.color(PenColor.BLUE);
		break;
	    case 1:
		turtle.color(PenColor.GREEN);
		break;
	    case 2:
		turtle.color(PenColor.YELLOW);
		break;
	    case 3:
		turtle.color(PenColor.RED);
		break;
	    case 4:
		turtle.color(PenColor.MAGENTA);
		break;
	    case 5:
		turtle.color(PenColor.ORANGE);
		break;
	    }
	    turtle.forward(Step * i);
	    turtle.turn(360/ColorNum + Densi);
	}
    }
经验分享 程序员 微信小程序 职场和发展