|
| 1 | +import traer.physics.Particle; |
| 2 | +import traer.physics.ParticleSystem; |
| 3 | +import traer.physics.Vector3D; |
| 4 | + |
| 5 | +float angnoise; |
| 6 | +float radiusnoise; |
| 7 | +float angle = -1.570796F; |
| 8 | +float radius; |
| 9 | +ParticleSystem physics; |
| 10 | +Particle[][] particles; |
| 11 | +int gridSizeX = 125; |
| 12 | +int gridSizeY = 75; |
| 13 | +int gridMidX; |
| 14 | +int gridMidY; |
| 15 | +int moverX; |
| 16 | +int moverY; |
| 17 | + |
| 18 | +public void setup() |
| 19 | +{ |
| 20 | + size(500, 300); |
| 21 | + smooth(); |
| 22 | + frameRate(24.0F); |
| 23 | + strokeCap(4); |
| 24 | + gridMidX = (int)(gridSizeX / 2); |
| 25 | + gridMidY = (int)(gridSizeY / 2); |
| 26 | + restart(); |
| 27 | +} |
| 28 | + |
| 29 | +public void restart() |
| 30 | +{ |
| 31 | + background(255); |
| 32 | + |
| 33 | + angnoise = random(10.0F); |
| 34 | + radiusnoise = random(10.0F); |
| 35 | + |
| 36 | + physics = new ParticleSystem(0.0F, 0.01F); |
| 37 | + |
| 38 | + particles = new Particle[gridSizeY][gridSizeX]; |
| 39 | + |
| 40 | + float f1 = width / gridSizeX; |
| 41 | + float f2 = height / gridSizeY; |
| 42 | + float f3 = f1 / 2.0F; |
| 43 | + moverX = (int)(random(gridSizeX)); |
| 44 | + moverY = (int)(random(gridSizeY)); |
| 45 | + for (int i = 0; i < gridSizeY; i++) { |
| 46 | + for (int j = 0; j < gridSizeX; j++) { |
| 47 | + particles[i][j] = physics.makeParticle(0.2F, j * f1 + f3, i * f2, 0.0F); |
| 48 | + } |
| 49 | + } |
| 50 | + for (int i = 0; i < gridSizeX; i++) { |
| 51 | + for (int j = 1; j < gridSizeY; j++) |
| 52 | + { |
| 53 | + physics.makeSpring(particles[(j - 1)][i], particles[j][i], 8.0F, 0.5F, f2); |
| 54 | + if (i > 0) { |
| 55 | + physics.makeSpring(particles[j][(i - 1)], particles[j][i], 8.0F, 0.5F, f1); |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +public void clearBackground() |
| 62 | +{ |
| 63 | + fill(255, 15.0F); |
| 64 | + noStroke(); |
| 65 | + rect(0.0F, 0.0F, width, height); |
| 66 | +} |
| 67 | + |
| 68 | +public void draw() |
| 69 | +{ |
| 70 | + physics.tick(0.15F); |
| 71 | + if (frameCount % 100 == 0) |
| 72 | + { |
| 73 | + moverX = (int)(random(gridSizeX)); |
| 74 | + moverY = (int)(random(gridSizeY)); |
| 75 | + } |
| 76 | + clearBackground(); |
| 77 | + stroke(0, 5.0F); |
| 78 | + |
| 79 | + radiusnoise += 0.02F; |
| 80 | + radius = (noise(radiusnoise) * 400.0F + 100.0F); |
| 81 | + angnoise += 0.01F; |
| 82 | + angle += noise(angnoise) * 10.0F - 5.0F; |
| 83 | + if (angle > 360.0F) { |
| 84 | + angle -= 360.0F; |
| 85 | + } |
| 86 | + if (angle < 0.0F) { |
| 87 | + angle += 360.0F; |
| 88 | + } |
| 89 | + float f1 = radians(angle); |
| 90 | + float f2 = 250.0F + radius * cos(f1); |
| 91 | + float f3 = 150.0F + radius * sin(f1); |
| 92 | + |
| 93 | + Particle localParticle = particles[moverY][moverX]; |
| 94 | + localParticle.position().set(f2, f3, 0.0F); |
| 95 | + localParticle.velocity().set(150.0F, 150.0F, 0.0F); |
| 96 | + |
| 97 | + noFill(); |
| 98 | + for (int i = 0; i < gridSizeY; i++) |
| 99 | + { |
| 100 | + beginShape(); |
| 101 | + for (int j = 0; j < gridSizeX; j++) { |
| 102 | + if (particles[i][j] != localParticle) { |
| 103 | + curveVertex(particles[i][j].position().x(), particles[i][j].position().y()); |
| 104 | + } |
| 105 | + } |
| 106 | + endShape(); |
| 107 | + } |
| 108 | + for (int i = 0; i < gridSizeX; i++) |
| 109 | + { |
| 110 | + beginShape(); |
| 111 | + for (int j = 0; j < gridSizeY; j++) { |
| 112 | + if (particles[j][i] != localParticle) { |
| 113 | + curveVertex(particles[j][i].position().x(), particles[j][i].position().y()); |
| 114 | + } |
| 115 | + } |
| 116 | + endShape(); |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +public void mousePressed() |
| 121 | +{ |
| 122 | + restart(); |
| 123 | +} |
0 commit comments