【processing效果】3.4.落花-图像运动结合

图像与运动对象的结合。

input:

PImage[] dongmei = new PImage[3];  //类图像对象
Bubble[] bubbles = new Bubble[5];  //类创建对象

void setup(){
  size(600,400);
  
  for (int i = 0;i < dongmei.length;i++){
    dongmei[i] = loadImage("dongmei"+i+".png");
  }
  for (int i = 0;i < bubbles.length;i++){
    int index = int(random(0,dongmei.length));  //设定随机遍历数
    bubbles[i] = new Bubble(dongmei[index],random(width),-50,random(40,60));
  }
}

void draw(){
  background(255);
  for (int i = 0;i < bubbles.length;i++){
    bubbles[i].ascend();
    bubbles[i].display();
    bubbles[i].top();
  }
}

input附加类Bubble:

class Bubble{
  float x;
  float y;
  float diameter;  //定义直径
  float yspeed;
  
  PImage img;
  
  Bubble(PImage tempImg,float tempX,float tempY,float tempD){  //对象的特征函数,含部分变量
    x = tempX;
    y = tempY;
    diameter = tempD;
    img = tempImg;  //获取图像
    
    yspeed = random(0.3,1.0);  //气泡下降速度
  }
  
  void ascend(){  //对象的功能函数之一
    y = y + yspeed;
    x = x + random(-0.3,0.3);
  }
  
  void display(){  //新对象放置
    //stroke(0,0,205,90);
    //fill(255,215,0,75);
    //ellipse(x,y,diameter,diameter);
    imageMode(CENTER);
    image(img,x,y,diameter,diameter);  //系数1.6保持图像比例
  }
  
  void top(){
    if (y > height + 50){
      y = -50;
    }
  }
}

output:

参考视频链接:【processing落花】 https://www.bilibili.com/video/BV1rM4y1i7oP/?share_source=copy_web&vd_source=81f6714046d21d930e6f52a77c0d8811

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一叶屋檐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值