2022-04-29
突然动了一个念头。送给自己一幅画。
画作虽不美观,但毕竟是自己编写了程序,并用这个程序画的。
程序说明:
按着f(代表flower),拖动鼠标绘制梅花花朵;按着s(代表stem),拖动鼠标绘制梅花主干。
int angle = 0;
void setup() {
size(640, 360);
background(102);//背景可更改。
noStroke();
fill(0, 102);
}
void draw() {
if (keyPressed) {
if (key == 'f' || key == 'F') { //flower
// Draw only when mouse is pressed
if (mousePressed == true) {
angle += 5;
float val = cos(radians(angle)) * 12.0;
for (int a = 0; a < 360; a += 75) {
float xoff = cos(radians(a)) * val;
float yoff = sin(radians(a)) * val;
fill(0);
ellipse(mouseX + xoff, mouseY + yoff, val, val);
}
fill(255,0,0);
ellipse(mouseX, mouseY, 5, 5);
}
}
if (key == 's' || key == 'S') { //stem
stroke(0);
strokeWeight(abs(mouseX-pmouseX));
line(mouseX,mouseY,pmouseX,pmouseY);
}
}
}
调整一下颜色似乎好些。
int angle = 0;
void setup() {
size(640, 360);
background(245);
noStroke();
fill(0, 102);
}
void draw() {
if (keyPressed) {
if (key == 'f' || key == 'F') { //flower
// Draw only when mouse is pressed
if (mousePressed == true) {
angle += 5;
float val = cos(radians(angle)) * 12.0;
for (int a = 0; a < 360; a += 75) {
float xoff = cos(radians(a)) * val;
float yoff = sin(radians(a)) * val;
fill(255,0,0);
ellipse(mouseX + xoff, mouseY + yoff, val, val);
}
fill(255,255,0);
ellipse(mouseX, mouseY, 5, 5);
}
}
if (key == 's' || key == 'S') { //stem
stroke(abs(mouseX-pmouseX));
strokeWeight(abs(mouseX-pmouseX));
line(mouseX,mouseY,pmouseX,pmouseY);
}
}
}
以下试图用noise来实现主干的颜色灰度自然变化。但效果不好。待改进。
int angle = 0;
float x;
float t;
void setup() {
size(640, 360);
background(245);
noStroke();
fill(0, 102);
}
void draw() {
if (keyPressed) {
if (key == 'f' || key == 'F') { //flower
// Draw only when mouse is pressed
if (mousePressed == true) {
angle += 5;
float val = cos(radians(angle)) * 12.0;
for (int a = 0; a < 360; a += 75) {
float xoff = cos(radians(a)) * val;
float yoff = sin(radians(a)) * val;
noStroke();
fill(255,0,0);
ellipse(mouseX + xoff, mouseY + yoff, val, val);
}
stroke(0);
fill(255,255,0);
ellipse(mouseX, mouseY, 5, 5);
}
}
if (key == 's' || key == 'S') { //stem
//x=map(noise(t),0,1,0,abs(mouseX-pmouseX)+abs(mouseY-pmouseY));
x=map(noise(t),0,1,0,90);
stroke(x);
strokeWeight(abs(mouseX-pmouseX)+abs(mouseY-pmouseY));
line(mouseX,mouseY,pmouseX,pmouseY);
t+=0.01;
}
}
}