关于processing的互动媒体程序实验

《代码本色》里详细介绍了关于processing的各种画图原理,在这里,我们对0~4章进行学习,并且绘制图案。

1、 00章 引言(随机游走&概率&perlin噪声)

效果图:

在这里插入图片描述
prilin噪声形成曲线,rgb颜色随机生成。

代码

float t = 0.0;

void setup() {
  size(400,200);
  smooth();
}

void draw() {
  background(255);
  float xloc = randomGaussian();
  
  float xoff = t*xloc;
  
  float r = random(255);
  float g = random(255);
  float b = random(255);
  rectMode(CENTER);
  fill(r,g,b);
  stroke(r,g,b);
  strokeWeight(0.2);
  beginShape();
  for (int i = 0; i < width; i++) 
  {
    float y = noise(xoff)*height;
    xoff += 0.01;
    vertex(i,y);
  }
  endShape();
  t+= 0.01;
}

2、 01章 向量

效果图:

在这里插入图片描述
圆形随鼠标移动,鼠标拖动的力,是赋予他们唯一的力,这些圆在运动的过程中会慢慢的趋于重叠。

代码

mover类:

class Mover {

  // The Mover tracks position, velocity, and acceleration 
  PVector position;
  PVector velocity;
  PVector acceleration;
  // The Mover's maximum speed
  float topspeed;

  Mover() {
    // Start in the center
    position = new PVector(random(width),random(height));
    velocity = new PVector(0,0);
    topspeed = 5;
  }

  void update() {
    
    // Compute a vector that points from position to mouse
    PVector mouse = new PVector(mouseX,mouseY);
    acceleration = PVector.sub(mouse,position);
    // Set magnitude of acceleration
    //acceleration.setMag(0.2);
    acceleration.normaliz
  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值