# 实验过程以及代码展示

## 1.星星帽子

function maozi(){
//画帽子主体
push();
fill(cmaozi);
noStroke();
triangle(240, 220, 360, 220, 300, 100);
triangle(300,100,380,75,325,150);
pop();
//画帽子边缘
push();
strokeWeight(2);
stroke(255,255,0);
line(240,220,360,220);
line(240,220,300,100);
line(300,100,380,75);
line(380,75,325,150);
line(325,150,360,220);
pop();
//帽子球
fill(cball);
ellipse(380,75,20);
//画星星
push();
fill(255,255,0);
stroke(255,255,0);
star(320,120,5,10);
star(300,140,6,13);
star(330,190,4,10);
//画月亮
arc(290, 180, 32, 32, PI/3, 5*PI/3, OPEN);
fill(cmaozi);
arc(306, 180, 32, 32, 2*PI/3, 4*PI/3, OPEN);
pop();
}

function star(x, y, radius1, radius2) {
let angle = PI*2/5;
let halfAngle = angle / 2.0;
beginShape();
for (let a = 0; a < PI*2; a += angle) {
let sx = x + cos(a) * radius1;
let sy = y + sin(a) * radius1;
vertex(sx, sy);
sx = x + cos(a + halfAngle) * radius2;
sy = y + sin(a + halfAngle) * radius2;
vertex(sx, sy);
}
endShape(CLOSE);
}

## 2.背景以及人物设计

function draw() {
background(100);
fill(0,0,150);
rect(0,0,600,600);
push();
noStroke();
fill(255,255,0);
arc(300,800,700,700,0,2*PI,OPEN);
arc(0,200,180,180,0,2*PI,OPEN);
arc(500,100,50,50,0,2*PI,OPEN);
star(500,300,20,40);
star(300,50,10,20);
arc(100, 400, 80, 80, PI/3, 5*PI/3, OPEN);
fill(0,0,150);
arc(140, 400, 80, 80, 2*PI/3, 4*PI/3, OPEN);
fill(200,255,0);
arc(300,800,660,660,0,2*PI,OPEN);
pop();
fill(200,255,200);
//画脖子
rect(290,390,20,20);
//画头
ellipse(300,300,180,200);

//画身体
fill(cbody);
rect(240,405,120,100,20,20,20,20);
//画手
fill(200,255,200);
rect(240,425,40,20,2,10,10,2);
rect(320,425,40,20,10,2,2,10);

//画腿
fill(clegs)
rect(260,505,20,70,0,0,10,10);
rect(320,505,20,70,0,0,10,10);
//画眼
fill(255,255,255)
ellipse(250,300,30,20);
ellipse(350,300,30,20);
fill(0,0,0);
ellipse(250,300,18,15);
ellipse(350,300,18,15);
//画嘴
push();
fill(255,0,80);
arc(300, 366, 32, 32, -PI/6, 7*PI/6, OPEN);
pop()
//画耳朵
fill(200,255,200);
arc(210,300,32,32,PI/2,3*PI/2,OPEN);
arc(390,300,32,32,-PI/2,PI/2,OPEN);
//画帽子
maozi();
//画头发
push()
fill(chair);
noStroke();
rect(280, 220, 40, 40, 0, 0, 30, 30);
rect(240, 220, 40, 40, 0, 0, 30, 30);
rect(320, 220, 40, 40, 0, 0, 30, 30);
arc(240,220,40,40, 0, 2*PI,OPEN);
arc(360,220,40,40, 0, 2*PI,OPEN);
arc(240,240,40,40, 0, 2*PI,OPEN);
arc(360,240,40,40, 0, 2*PI,OPEN);
pop()
//手拿星星
fill(255,255,0);
star(300,pos,15,30);
}

## 交互设计

if(mouseIsPressed){
if(mouseButton===LEFT){
cmaozi=color(255,0,0);
cball=color(255,255,0);
chair=color(0,255,0);
cbody=color(255,0,0);
clegs=color(0,255,0);
}
if(mouseButton===CENTER){
cmaozi=color(255,0,255);
cball=color(255,0,0);
chair=color(200,0,80);
cbody=color(0,0,0);
clegs=color(100,200,0);
}
if(mouseButton===RIGHT){
cmaozi=color(0,0,255);
cball=color(255,0,0);
chair=color(0,0,0);
cbody=color(0,0,255);
clegs=color(0,0,0);
}
}


let pos=425;
//手拿星星
fill(255,255,0);
star(300,pos,15,30);
function mouseWheel(event) {
pos += event.delta/10;
}

# 实验总结

• 0
点赞
• 0
评论
• 1
收藏
• 一键三连
• 扫一扫，分享海报

10-24
10-20 1441

10-27 1105
11-24 1854
11-03 379
11-03 961
11-03 1378
12-30 773
11-04 716
12-16 869
12-30 4805
10-18
09-28 5638
12-16 757
12-30 2526
11-23 2359
©️2021 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。