自画像
代码
分为人物,背景,雪花(设计鼠标左键点击下雪和停止下雪)
背景分为山和落下的太阳
let snowflakes = [];
let sun_y=200
let issnow=true;
function setup() {
createCanvas(700, 500);
}
function draw() {
background(135,206,250);
//太阳落山
push();
sun_y += 1
if(sun_y==200){
sun_y=1
}
//绘制一个太阳
fill(255,0,0)
stroke(255, 255, 0)
strokeWeight(6)
ellipse(500, sun_y, 100, 100)
//开始绘制山的图形
//设置颜色为灰色
fill(45,45,45)
stroke(0, 0, 0)
strokeWeight(1)
beginShape()
vertex(0,520)
vertex(50, 340)
vertex(120, 480)
vertex(150, 320)
vertex(200, 450)
vertex(260, 350)
vertex(400, 460)
vertex(600, 310)
vertex(800, 520)
//结束绘制图形
endShape()
pop();
push();
//头发
push();
fill(54,54,54);
stroke(54,54,54);
rect(90,160,220,200);
pop();
//身体
push();
fill(171,130,225);
triangle(200,150,120,450,280,450);
pop();
push();
fill(255,228,196);
ellipse(200,200,180,180);//绘制椭圆(x,y,宽,高)
pop();
push();
line(125,150,200,150);//绘制线段(x1,y1,x2,y2)起点至终点
line(200,150,230,115);//绘制线段(x1,y1,x2,y2)起点至终点
line(230,115,250,150);//绘制线段(x1,y1,x2,y2)起点至终点
line(250,150,275,150);//绘制线段(x1,y1,x2,y2)起点至终点
pop();
//眼睛
push();
ellipse(150,200,30,30);
ellipse(250,200,30,30);
pop();
//眼球
push();
fill(0,0,0);
ellipse(150,200,10,10);
ellipse(250,200,10,10);
pop();
//眉毛
line(130,175,170,175);//绘制线段(x1,y1,x2,y2)起点至终点
line(230,175,270,175);
push();
fill(54,54,54);
arc(200,160,220,130,PI,0);
pop();
fill(88,87,86);
arc(150, 175, 40, 15, PI, 0);//绘制弧(x,y,宽,高,起始角度,终止角度)
arc(250, 175, 40, 15, PI, 0);
pop();
//嘴巴
line(175,240,225,240);
arc(200, 240, 50, 40, 0, PI);
//手脚
line(150,450,130,500);
line(250,450,270,500);
line(100,300,150,340);
line(300,300,250,340);
push();
strokeWeight(3);
line(270,500,280,490);
line(130,500,145,505);
pop();
push();
strokeWeight(2);
stroke(171,130,225);
line(250,158,260,135);
line(260,158,270,140);
pop();
//下雪
push();
noStroke();
let t = frameCount / 60;
if (mouseIsPressed === true)
{
if(mouseButton === LEFT)
{
if(issnow===false)
issnow=true;
else
issnow=false;
}
}
if(issnow===true)
{
for (var i = 0; i < random(5); i++)
{
snowflakes.push(new snowflake());
}
for (let flake of snowflakes)
{
flake.update(t);
flake.display();
}
}
pop();
}
function snowflake() {
// initialize coordinates
this.posX = 0;
this.posY = random(-50, 0);
this.initialangle = random(0, 2 * PI);
this.size = random(2, 5);
// radius of snowflake spiral
// chosen so the snowflakes are uniformly spread out in area
this.radius = sqrt(random(pow(width / 2, 2)));
this.update = function(time) {
// x position follows a circle
let w = 0.6; // angular speed
let angle = w * time + this.initialangle;
this.posX = width / 2 + this.radius * sin(angle);
// different size snowflakes fall at slightly different y speeds
this.posY += pow(this.size, 0.5);
// delete snowflake if past end of screen
if (this.posY > height) {
let index = snowflakes.indexOf(this);
snowflakes.splice(index, 1);
}
};
this.display = function() {
ellipse(this.posX, this.posY, this.size);
};
}
人物设计的比较大是因为人物是主体(虽然丑)
太阳是美好的事物,雪花也是美好的事物,夕阳西下也不会带走美好,还会有新的美好在等你大概就是这个意思
网友评论