crazyparticle.pde

来自「This is processing for java examples.」· PDE 代码 · 共 48 行

PDE
48
字号
// A subclass of Particleclass CrazyParticle extends Particle {  // Just adding one new variable to a CrazyParticle  // It inherits all other fields from "Particle", and we don't have to retype them!  float theta;  // The CrazyParticle constructor can call the parent class (super class) constructor  CrazyParticle(PVector l) {    // "super" means do everything from the constructor in Particle    super(l);    // One more line of code to deal with the new variable, theta    theta = 0.0;  }  // Notice we don't have the method run() here; it is inherited from Particle  // This update() method overrides the parent class update() method  void update() {    super.update();    // Increment rotation based on horizontal velocity    float theta_vel = (vel.x * vel.mag()) / 10.0f;    theta += theta_vel;  }  // Override timer  void timer() {    timer -= 0.5;  }    // Method to display  void render() {    // Render the ellipse just like in a regular particle    super.render();    // Then add a rotating line    pushMatrix();    translate(loc.x,loc.y);    rotate(theta);    stroke(255,timer);    line(0,0,25,0);    popMatrix();  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?