利用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);
}
}
转载:https://blog.csdn.net/gzn00417/article/details/104521856
查看评论