Processing 中使用函数来定义图形

 时间:2024-10-12 09:12:51

1、Processing 中使用 map 映射函数输入代码:void 衡痕贤伎setup() {size(240, 120);strokeWeight(12);smooth();}void draw() {background(204);stroke(255);line(120, 60, mouseX, mouseY); // 白色线条stroke(0);float mx = map(mouseX, 0, width, 60, 180);line(120, 60, mx, mouseY); // 黑色线条}运行函数,效果是通过鼠标的晃动可以使两个线条跟随着鼠标而动

Processing 中使用函数来定义图形

3、Processing 中识别鼠标的点击动作输入代码:void setup() {size(240, 120);smooth();strokeWeight(30);}void draw() {background(204);stroke(102);line(40, 0, 70, height);if (mousePressed == true) {stroke(0);}line(0, 70, width, 50);}当单击鼠标左键时,线条会变成黑色

Processing 中使用函数来定义图形

4、线条通过鼠标的指示运动输入代码:float x;int offset = 10;void setup() {size(240, 120);s罪焐芡拂mooth();x = width/2;}void draw() {background(204);if (mouseX > x) {x += 0.5;offset = -10;}if (mouseX < x) {x -= 0.5;offset = 10;}line(x, 0, x, height);line(mouseX, mouseY, mouseX + offset, mouseY - 10);line(mouseX, mouseY, mouseX + offset, mouseY + 10);line(mouseX, mouseY, mouseX + offset*3, mouseY);}

Processing 中使用函数来定义图形

6、鼠标放置在图形的位置,图形变为黑色输入代码:int x = 80;坡纠课柩int y = 30;int w = 80;int h = 60;void setup() {size(240, 120);}void draw() {background(204);if ((mouseX > x) && (mouseX < x+w) &&(mouseY > y) && (mouseY < y+h)) {fill(0);} else {fill(255);}rect(x, y, w, h);}

Processing 中使用函数来定义图形

7、代码回顾1:使用 if 语句

Processing 中使用函数来定义图形
  • PS窗口排列四联在哪怎么设
  • 如何用ps怎么把图片变成圆形
  • Illustrator中怎样给路径增加锚点?
  • C4D 怎么渲染一个透明的图片
  • PS如何制作爆炸蘑菇云效果
  • 热门搜索
    成都市旅游局 丽江旅游团 亲和力旅游 广州旅游景区 尼泊尔旅游攻略 雁荡山旅游风景区 白俄罗斯旅游 网络旅游 内蒙古旅游地图 兰卡威旅游