processing:画有五角星绕圈的旗
老师布置了作业,选画一个国旗。
选了塔吉克斯坦共和国的国旗
效果如下:
代码:
//塔吉克斯坦共国旗
float x, y;//用来画宝石的数
void setup() {
size(1000, 500);
background(255, 255, 255);
//国旗底色
noStroke();
fill(255, 255, 255);
rect(0, 0, 1000, 500);
fill(#cc0001);
rect(0, 0, 1000, 145);
fill(#006700);
rect(0, 356, 1000, 145);
//半圈星星
//右四分之一
fill(#f8d206);
noStroke();
//笔记:用radians()函数可将角度转化为弧度
float r = 15;//五角星的外接圆的半径
float l = 2*r*sin(radians(36));//五角星的外接五边形的边长
float a = l/(2*sin(radians(54)));//五角星的边长
for (int i=2; i<9; i++) {
float theta = 2*PI*i/10;
float x = sin(theta)*100+480;
float y = cos(theta)*90+248;
//radians()
beginShape();
vertex(x,y);//1
vertex(x+a,y);//2
vertex(x+a+a*sin(radians(18)),y-a*cos(radians(18)));//3
vertex(x+a+2*a*sin(radians(18)),y);//4
vertex(x+2*a+2*a*sin(radians(18)),y);//5
vertex(x+2*a+2*a*sin(radians(18))-a*cos(radians(36)),y+a*sin(radians(36)));//6
vertex(x+(2*a+2*a*sin(radians(18)))*sin(radians(54)),y+(2*a+2*a*sin(radians(18)))*cos(radians(54)));//7
vertex(x+a*sin(radians(54))-a*sin(radians(27))+a*cos(radians(27)),y+a*cos(radians(54))-a*sin(radians(27))+a*cos(radians(27)));//8
vertex(x+a*sin(radians(54))-a*sin(radians(27)),y+a*cos(radians(54))+a*cos(radians(27)));//9
vertex(x+a*sin(radians(54)),y+a*cos(radians(54)));//10
endShape(CLOSE);
}
//左四分之一
//for (int i=2; i<9; i++) {
// float theta = 2*PI*i/10-;
// float x = sin(theta)*108+500;
// float y = cos(theta)*108+276;
// ellipse(x, y, 15.5, 15.5);
//}
//中间图腾
//1
noFill();
stroke(#f8d206);
strokeWeight(10.11);
ellipse(500, 232.5, 40, 30.99);
noFill();
strokeWeight(8);
line(500, 248, 500, 286.6);
//皇冠底线
strokeWeight(13);
strokeCap(PROJECT);
bezier(426, 334, 433.2, 330, 501.9, 315.1, 574.7, 334);
//3皇冠顶
fill(#f8d206);
noStroke();
beginShape();
vertex(401.3, 296.2);
bezierVertex( 401.3, 296.2, 427.4, 325, 448, 288);
bezierVertex( 480.4, 315.5, 491.6, 285.7, 500, 279.1);
bezierVertex( 506.3, 283.4, 522.6, 315.2, 552, 287);
bezierVertex( 565, 317.2, 589.6, 304, 598, 297);
bezierVertex( 583.9, 334.4, 548, 310, 548.1, 303);
bezierVertex( 524.9, 316.7, 506.8, 305.8, 500, 296.5);
bezierVertex( 478.6, 320, 451.7, 306, 451.1, 303);
bezierVertex( 428.7, 333.8, 401, 308, 401.3, 296.2);
endShape();
//控制点和坐标点是用PS标尺去测量钢笔工具的锚点的坐标点测出来的,一点一点地测量,目前还没有想到更好的办法去确定控制点的位置
//宝石(有点想枫叶的形状)
//初始化x,y
x=439.5;
y=315;
//左边
smooth();
beginShape();
vertex(x, y);
vertex(x+7, y-2);
vertex(x+11.5, y-9);
vertex(x+19, y-3);
vertex(x+27, y-3);
vertex(x+22, y+3);
vertex(x+5, y+5);
endShape();
//中间
x+=48;
y-=2;
beginShape();
vertex(x, y-3);
vertex(x+7, y-3);
vertex(x+12, y-8);
vertex(x+19, y-3);
vertex(x+27, y-3);
vertex(x+22, y+2.5);
vertex(x+5, y+2.5);
endShape();
右边
x+=47;
y+=2;
beginShape();
vertex(x, y-2);
vertex(x+7, y-2);
vertex(x+11.5, y-6);
vertex(x+19, y-1);
vertex(x+26, y+1);
vertex(x+21, y+6);
vertex(x+5, y+4);
endShape();
}
画五角星的坐标参考:https://blog.csdn.net/weixin_43624626/article/details/106150822
如果有更好的办法和其他建议,欢迎分享~