【Processing】

【Processing】

#Processing五项实验汇总

第0章 随机游走

实验结果:
在这里插入图片描述
这个实现的图案就是火箭发射的样子,两个三角形构成火箭的简易形象,然后运用了粒子的效果,实现了尾气的感觉。
相关代码如下:
main:

Walker w;
float g;
ArrayList lightPointsArr = new ArrayList();
PVector gravity = new PVector(g,g);

void setup() {
   
  size(600, 600);
  //frameRate(30);
  // Create a walker object
  w = new Walker();
}

void draw() {
   
  background(0);
  // Run the walker object`在这里插入代码片`
  for(int i = 0;i< lightPointsArr.size();i++){
   
       lightPoints points = (lightPoints) lightPointsArr.get(i);
       points.draw();
     }
     
        for (int i = 0; i < prevX/10; i++) {
   
       lightPointsArr.add(new lightPoints());
        }
    
  w.step();
  w.render();
}

Walker

float x, y;
  float tx, ty;
  float prevX, prevY;
class Walker {
   
    PVector speed;
    PVector acceleration;
    float circleR;
  Walker() {
   
    tx = 0;
    ty = 10000;
    x = map(noise(tx), 0, 1, 0, width);
    y = map(noise(ty), 0, 1, 0, height);
    speed =  new PVector(random(-30,30), random(-30, 30));
   acceleration = new PVector(0, random(0, 1));
   circleR = random(50,100);
  }

  void render() {
   
    stroke(255);
    
    speed.add(acceleration);//v = v0 + a*t
      
      acceleration.add(gravity);
      gravity.mult(0);
      fill(255, random(0, 250), 0,  random(50, 250));
      //ellipse(prevX, prevY, circleR, circleR); 
      triangle(prevX-20, prevY-20,prevX+20, prevY,prevX, prevY+20);
      triangle(prevX-50, prevY-50,prevX+10, prevY-60,prevX-50, prevY+10);
  
  }

  // Randomly move according to floating point values
  void step() {
   

    prevX = x;
    prevY = y;

    x = map(noise(tx), 0, 1, 0, width);
    y = map(noise(ty), 0, 1, 0, height);

    tx += 0.01;
    ty += 0.01;

  }
}

lightPoints:

class lightPoints{
   
    PVector location;
    PVector speed;
    PVector acceleration;
    float circleR;
    lightPoints(){
   
       location = new PVector(prevX, prevY);
       speed =  new PVector(random(100), random(100));
       acceleration = new PVector(0, random(0, 1));
       circleR = random(5,15);
    }


     void draw(){
   

      speed.add(acceleration);//v = v0 + a*t
      location.add(speed);//s = s0 + v*t;
      acceleration.add(gravity);
     ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200105204414865.gif) gravity.mult(0);
      fill(255, random(0, 250), 0,  random(50, 250));
      ellipse(location.x, location.y, circleR, circleR);
      //triangle(location.x+5, location.y,location.x-5, location.y,location.x, location.y);
    }
}

这里主要运用的函数就是random(),由它随机生成的数配合其他的函数构成新的点坐标或者说是小球的颜色。

第1章 向量

实验结果:
在这里插入图片描述
通过鼠标实现连续画点,然后画出来的点向着鼠标运动的方向运动,代码如下:
这里的主要应用的原理就是利用好PVector mouse = new PVector(mouseX,mouseY);让生成的的点和已经生成后的点都围绕鼠标做相对应的运动
main:

float g;
ArrayList lightPointsArr = new ArrayList();
PVector gravity = new PVector(g,g);

void setup() {
   
  size(640,640);
}

void draw() {
   
  background(0);
  for(int i = 0;i< lightPointsArr.size();i++){
   
       lightPoints points = (lightPoints) lightPointsArr.get(i);
       points.draw();
     }
       
    for (int i = 0; i < mouseX/10; i++) {
   
       lightPointsArr.add(new lightPoints());
         }
  
}

lightPoints:

class lightPoints{
   
    PVector location;
    PVector speed;
    PVector acceleration;
    float circleR;
    float topspeed;
    lightPoints(){
   
       location = new PVector(mouseX,mouseY);
       speed =  new PVector(0,0);
       acceleration = new PVector(0, random(0, 1))
  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值