用processing利用做出一个长头发齐头帘的小女孩进行场景创作,其中包含mouse X,mouse Y,random的使用和键盘交互和鼠标交互还有random的使用,需要物体自己运动和变量的使用
时间: 2024-05-05 21:22:44 浏览: 16
好的,下面是一个简单的示例代码,其中包含了长头发齐头帘的小女孩,以及场景中的一些交互和自动化运动。
```processing
float girlX = 200;
float girlY = 200;
float girlSpeed = 2;
float hairLength = 100;
int hairColor = color(127, 63, 0);
int bgColor = color(0, 191, 255);
void setup() {
size(400, 400);
}
void draw() {
background(bgColor);
drawGirl();
moveGirl();
drawHair();
drawMouse();
}
void drawGirl() {
fill(255);
ellipse(girlX, girlY, 50, 50);
fill(0);
ellipse(girlX - 10, girlY - 10, 10, 10);
ellipse(girlX + 10, girlY - 10, 10, 10);
arc(girlX, girlY + 10, 30, 20, 0, PI);
}
void moveGirl() {
if (keyPressed) {
if (keyCode == LEFT) {
girlX -= girlSpeed;
} else if (keyCode == RIGHT) {
girlX += girlSpeed;
} else if (keyCode == UP) {
girlY -= girlSpeed;
} else if (keyCode == DOWN) {
girlY += girlSpeed;
}
}
}
void drawHair() {
strokeWeight(5);
stroke(hairColor);
line(girlX, girlY + 25, girlX, girlY + 25 + hairLength);
float hairX1 = girlX - 20;
float hairY1 = girlY + 25 + hairLength/3;
float hairX2 = girlX + 20;
float hairY2 = girlY + 25 + hairLength/2;
line(girlX, girlY + 25 + hairLength, hairX1, hairY1);
line(girlX, girlY + 25 + hairLength, hairX2, hairY2);
}
void drawMouse() {
fill(255);
ellipse(mouseX, mouseY, 10, 10);
float randX = random(-10, 10);
float randY = random(-10, 10);
fill(255, 127, 0);
ellipse(mouseX + randX, mouseY + randY, 5, 5);
}
void mouseClicked() {
hairLength = random(50, 150);
hairColor = color(random(255), random(255), random(255));
bgColor = color(random(255), random(255), random(255));
}
```
这个程序中,我们定义了一个小女孩的位置和速度,以及她的头发长度和颜色。在 `draw()` 函数中,我们首先清空了屏幕,然后分别绘制了小女孩、头发、鼠标和一些交互元素。在 `moveGirl()` 函数中,我们根据键盘的输入来改变小女孩的位置。在 `drawMouse()` 函数中,我们绘制了一个鼠标和一个随机偏移量的圆圈,来模拟鼠标的移动和点击。最后,在 `mouseClicked()` 函数中,我们随机改变了头发的长度和颜色,以及背景色。
你可以根据自己的需求来修改这个程序,比如添加更多的交互元素,改变小女孩的运动方式,或者使用更复杂的图形来构建场景。