@Override public void create() { Arrays.fill(heights, defaultHeight); Core.interval(.0005).onEvent(this::step).addChild(this); // onUpdate(dt -> { // Util.repeat(detail, i -> heights[i] += dt * speeds[i]); // Util.repeat(detail - 1, i -> { // deltas[i] = heights[i + 1] - heights[i]; // speeds[i] += deltas[i] * dt * 3000; // speeds[i + 1] -= deltas[i] * dt * 3000; // }); // Util.repeat(detail, i -> speeds[i] = speeds[i] * Math.pow(.1, dt * dt) + dt * 10 * // (defaultHeight - heights[i])); // Util.repeat(detail - 1, i -> { // heights[i] += deltas[i] * dt; // heights[i + 1] -= deltas[i] * dt; // }); // }); onRender( () -> { glDisable(GL_TEXTURE_2D); glBegin(GL_TRIANGLE_STRIP); Util.repeat( detail, i -> { double x = position.x + width * (2. * i / detail - 1); new Color4(0, 0, .6).glColor(); new Vec2(x, bottom).glVertex(); new Color4(0, .2, 1).glColor(); new Vec2(x, heights[i]).glVertex(); }); glEnd(); }); Core.renderLayer(1) .onEvent( () -> { glDisable(GL_TEXTURE_2D); glBegin(GL_TRIANGLE_STRIP); Util.repeat( detail, i -> { double x = position.x + width * (2. * i / detail - 1); new Color4(0, 0, .6, .5).glColor(); new Vec2(x, bottom).glVertex(); new Color4(0, .2, 1, .5).glColor(); new Vec2(x, heights[i]).glVertex(); }); glEnd(); }) .addChild(this); }
public void step() { Util.repeat(detail, i -> heights[i] += .01 * speeds[i]); Util.repeat( detail - 1, i -> { deltas[i] = heights[i + 1] - heights[i]; speeds[i] += deltas[i]; speeds[i + 1] -= deltas[i]; }); Util.repeat( detail, i -> speeds[i] = speeds[i] * Math.pow(.5, .001) + .01 * (defaultHeight - heights[i])); Util.repeat( detail - 1, i -> { heights[i] += deltas[i] * .01; heights[i + 1] -= deltas[i] * .01; }); }
public void splash(double x, double strength, ParticleEmitter drops) { int index = indexOf(x); speeds[index] = strength * strength / 500; Util.repeat( (int) (strength * strength) / 2000, () -> { Vec2 dir = Vec2.fromPolar(Math.random(), Math.random() * Math.PI); drops.particles.add( new Particle( new Vec2(x, heights[index]).add(dir), dir.multiply(50 * Math.sqrt(strength)))); }); }
public static void addParticle(int num, Supplier<Particle> s) { Util.repeat(num, () -> ALL.add(s.get())); }