size(800, 600);
background(200);
boolean isFirstVersion = true; // 标记当前显示的版本
void setup() {
surface.setTitle("鼠标点击切换表情");
}
void draw() {
background(200); // 灰色背景
int hairColor = color(200, 150, 80); // 黄棕色
int clothesColor = color(187, 255, 255); // 天蓝色衣服
if (isFirstVersion) {
// 第一个版本的代码
fill(hairColor);
noStroke();
ellipse(width/2, height/2 - 50, 200, 200); // 圆形头发
rectMode(CENTER);
rect(width/2, height/2 + 50, 200, 200); // 长方形头发
// 绘制脸部
fill(255, 230, 210); // 肤色
ellipse(width/2, height/2, 150, 180); // 脸部椭圆
// 眼睛(保持不变)
fill(255); // 眼白
ellipse(width/2 - 40, height/2 - 30, 25, 20); // 左眼白
ellipse(width/2 + 40, height/2 - 30, 25, 20); // 右眼白
fill(160, 80, 40); // 棕色虹膜
ellipse(width/2 - 40, height/2 - 30, 12, 10); // 左虹膜
ellipse(width/2 + 40, height/2 - 30, 12, 10); // 右虹膜
fill(0); // 黑色瞳孔
ellipse(width/2 - 40, height/2 - 30, 8, 8); // 左瞳孔
ellipse(width/2 + 40, height/2 - 30, 8, 8); // 右瞳孔
// 眉毛
strokeWeight(2);
line(width/2 - 50, height/2 - 50, width/2 - 30, height/2 - 40); // 左眉
line(width/2 + 30, height/2 - 50, width/2 + 50, height/2 - 40); // 右眉
noStroke();
// 鼻子
fill(180, 140, 120); // 浅棕色
triangle(
width/2, height/2 - 10, // 鼻尖Y坐标从-20改为-10(下移10像素)
width/2 - 10, height/2,
width/2 + 10, height/2
);
// 嘴巴(椭圆上半圆)
fill(255, 180, 180); // 淡粉色
ellipseMode(CENTER);
arc(width/2, height/2 + 20, 60, 30, 0, PI); // 上半圆(0到PI弧度)
// 眉毛(黑色椭圆下半圆)
fill(0); // 黑色
ellipseMode(CENTER);
// 左眉毛:椭圆下半圆
arc(width/2 - 40, height/2 - 45, 30, 15, PI, TWO_PI); // 中心在左眼上方
// 右眉毛:椭圆下半圆
arc(width/2 + 40, height/2 - 45, 30, 15, PI, TWO_PI); // 对称位置
// 绘制衣服
fill(187,255,255);
noStroke();
rectMode(CORNER);
rect(width/2 - 60, height/2 + 80, 120, 150); // 衣服
} else {
// 第二个版本的代码
// 绘制头发
fill(hairColor);
noStroke();
ellipse(width/2, height/2 - 50, 200, 200);
rectMode(CENTER);
rect(width/2, height/2 + 50, 200, 200);
// 绘制脸部
fill(255, 230, 210);
ellipse(width/2, height/2, 150, 180);
// 眼睛(增大黑色瞳孔)
fill(255); // 眼白
ellipse(width/2 - 40, height/2 - 30, 30, 25); // 左眼白
ellipse(width/2 + 40, height/2 - 30, 30, 25); // 右眼白
fill(160, 80, 40); // 棕色虹膜
ellipse(width/2 - 40, height/2 - 30, 20, 18);
ellipse(width/2 + 40, height/2 - 30, 20, 18);
fill(0); // 黑色瞳孔
ellipse(width/2 - 40, height/2 - 30, 15, 15);
ellipse(width/2 + 40, height/2 - 30, 15, 15);
// 眉毛(保持不变)
strokeWeight(2);
line(width/2 - 50, height/2 - 50, width/2 - 30, height/2 - 40);
line(width/2 + 30, height/2 - 50, width/2 + 50, height/2 - 40);
noStroke();
// 鼻子
fill(180, 140, 120);
triangle(
width/2, height/2 - 10,
width/2 - 10, height/2,
width/2 + 10, height/2
);
// 嘴巴(椭圆)
fill(255, 180, 180);
ellipseMode(CENTER);
ellipse(width/2, height/2 + 25, 60, 40);
// 衣服
fill(clothesColor);
rectMode(CORNER);
rect(width/2 - 60, height/2 + 80, 120, 150);
// 眉毛(黑色椭圆下半圆,微微抬起)
fill(0);
ellipseMode(CENTER);
arc(width/2 - 40, height/2 - 50, 40, 12, PI, TWO_PI);
arc(width/2 + 40, height/2 - 50, 40, 12, PI, TWO_PI);
}
}
void mousePressed() {
isFirstVersion =!isFirstVersion;
}
size(800, 600);
background(200); // 灰色背景
int hairColor = color(200, 150, 80); // 黄棕色
// 绘制头发
fill(hairColor);
noStroke();
ellipse(width/2, height/2 - 50, 200, 200); // 圆形头发
rectMode(CENTER);
rect(width/2, height/2 + 50, 200, 200); // 长方形头发
// 绘制脸部
fill(255, 230, 210); // 肤色
ellipse(width/2, height/2, 150, 180); // 脸部椭圆
// ======================
// 眼睛(保持不变)
// ======================
fill(255); // 眼白
ellipse(width/2 - 40, height/2 - 30, 25, 20); // 左眼白
ellipse(width/2 + 40, height/2 - 30, 25, 20); // 右眼白
fill(160, 80, 40); // 棕色虹膜
ellipse(width/2 - 40, height/2 - 30, 12, 10); // 左虹膜
ellipse(width/2 + 40, height/2 - 30, 12, 10); // 右虹膜
fill(0); // 黑色瞳孔
ellipse(width/2 - 40, height/2 - 30, 8, 8); // 左瞳孔
ellipse(width/2 + 40, height/2 - 30, 8, 8); // 右瞳孔
// 眉毛
strokeWeight(2);
line(width/2 - 50, height/2 - 50, width/2 - 30, height/2 - 40); // 左眉
line(width/2 + 30, height/2 - 50, width/2 + 50, height/2 - 40); // 右眉
noStroke();
// ======================
fill(180, 140, 120); // 浅棕色
triangle(
width/2, height/2 - 10, // 鼻尖Y坐标从-20改为-10(下移10像素)
width/2 - 10, height/2,
width/2 + 10, height/2
);
// ======================
// 嘴巴(椭圆上半圆)
// ======================
fill(255, 180, 180); // 淡粉色
ellipseMode(CENTER);
arc(width/2, height/2 + 20, 60, 30, 0, PI); // 上半圆(0到PI弧度)
// ======================
// 眉毛(黑色椭圆下半圆)
// ======================
fill(0); // 黑色
ellipseMode(CENTER);
// 左眉毛:椭圆下半圆
arc(width/2 - 40, height/2 - 45, 30, 15, PI, TWO_PI); // 中心在左眼上方,宽30,高15
// 右眉毛:椭圆下半圆
arc(width/2 + 40, height/2 - 45, 30, 15, PI, TWO_PI); // 对称位置
// ======================
// 绘制衣服(覆盖部分脸部)
// ======================
fill(187,255,255);
noStroke();
rectMode(CORNER);
rect(
width/2 - 60, // 左边界:不变
height/2 + 80, // 上边界:从+60改为+80,向下移动20像素
120, // 宽度:120像素(比脸部窄)
150 // 高度:150像素
);
当鼠标点击时,让这两个表情切换
帮我生成一段processing能用的代码
最新发布