用processing制作套圈大小的效果

运行结果

代码部分

void setup(){
  size(800,800);
}
void draw(){
  background(0);
  noFill();
  stroke(255,255);
  
  for(int i = 0;i<11;i++){
    float pingPong=sin(radians((frameCount+10*i)/0.7));
    strokeWeight(map(abs(pingPong),0,1,25,0));
    ellipse(width/2,height/2,i*70,i*70);
  }
}

因为学习的深度还尚浅,其中一些代码参考老师提供的代码

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
制作粒子效果,使用Processing可以使用两种方式:使用现有的粒子库或自己编写代码。 1. 使用现有的粒子库:Processing有许多粒子库可供使用,如Toxiclibs、Traer等。这些库提供了许多现成的函数和类,可以轻松地创建和控制粒子效果。 例如,使用Toxiclibs库可以轻松地创建一个简单的粒子效果: ``` import toxi.geom.*; import toxi.physics.*; import toxi.physics.behaviors.*; VerletPhysics physics; VerletParticle[] particles; void setup() { size(400, 400); physics = new VerletPhysics(); particles = new VerletParticle[100]; for (int i = 0; i < particles.length; i++) { particles[i] = new VerletParticle(new Vec2D(random(width), random(height))); physics.addParticle(particles[i]); physics.addBehavior(new AttractionBehavior(particles[i], 20, -1)); } } void draw() { background(255); physics.update(); stroke(0); for (int i = 0; i < particles.length; i++) { point(particles[i].x, particles[i].y); } } ``` 2. 自己编写代码:如果你想更深入地了解粒子效果的原理和实现方法,可以自己编写代码。通常需要使用向量、物理引擎等概念和技术。 例如,可以使用向量来表示粒子的位置和速度,使用物理引擎来模拟粒子的运动和碰撞: ``` Particle[] particles; void setup() { size(400, 400); particles = new Particle[100]; for (int i = 0; i < particles.length; i++) { particles[i] = new Particle(new PVector(random(width), random(height)), new PVector(random(-1, 1), random(-1, 1))); } } void draw() { background(255); for (int i = 0; i < particles.length; i++) { particles[i].update(); particles[i].display(); } } class Particle { PVector pos, vel, acc; Particle(PVector pos, PVector vel) { this.pos = pos; this.vel = vel; this.acc = new PVector(0, 0.1); } void update() { vel.add(acc); pos.add(vel); if (pos.x < 0 || pos.x > width) vel.x *= -1; if (pos.y < 0 || pos.y > height) vel.y *= -1; } void display() { stroke(0); ellipse(pos.x, pos.y, 10, 10); } } ``` 以上是两种制作粒子效果的方法,你可以根据自己的需求和技能选择适合自己的方式。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值