爆発の流れ
¥
/** * bursting flow * * @author aa_debdeb * @date 2016/12/06 */ ArrayList<Particle> particles; float gravity = 0.01; void setup(){ size(640, 640, P3D); colorMode(HSB, 360, 100, 100); particles = new ArrayList<Particle>(); for(int i = 0; i < 300; i++){ particles.add(new Particle()); } } void draw(){ background(0, 0, 0); noFill(); translate(width / 2, height / 6); rotateY(map(mouseX, 0, width, -HALF_PI, HALF_PI)); rotateX(map(mouseY, 0, height, -HALF_PI, HALF_PI)); for(Particle p: particles){ p.display(); p.update(); } } class Particle { ArrayList<PVector> trajectory; PVector loc, vel; float hue; Particle(){ trajectory = new ArrayList<PVector>(); vel = new PVector(random(-1, 1), random(-1, 1), random(-1, 1)); vel.normalize(); vel.mult(1.0); loc = new PVector(0, 0, 0); hue = random(300, 380); hue = hue < 360 ? hue: hue - 360; } void display(){ strokeWeight(1); stroke(hue, 100, 100); beginShape(); for(PVector t: trajectory){ vertex(t.x, t.y, t.z); } endShape(); } void update(){ vel.x += random(-gravity * 3, gravity * 3); vel.y += gravity; vel.z += random(-gravity * 3, gravity * 3); vel.limit(3); loc.add(vel); trajectory.add(new PVector(loc.x, loc.y, loc.z)); } }