|
| 1 | +import com.thomasdiewald.pixelflow.java.DwPixelFlow; |
| 2 | +import com.thomasdiewald.pixelflow.java.fluid.DwFluid2D; |
| 3 | +import java.util.Random; |
| 4 | + |
| 5 | + |
| 6 | +DwFluid2D fluid; |
| 7 | + |
| 8 | + |
| 9 | +PGraphics2D pg_fluid; |
| 10 | + |
| 11 | +public void setup() { |
| 12 | + size(800, 800, P2D); |
| 13 | + |
| 14 | + DwPixelFlow context = new DwPixelFlow(this); |
| 15 | + |
| 16 | + |
| 17 | + fluid = new DwFluid2D(context, width, height, 1); |
| 18 | + |
| 19 | + |
| 20 | + fluid.param.dissipation_velocity = 0.70f; |
| 21 | + fluid.param.dissipation_density = 0.99f; |
| 22 | + |
| 23 | + |
| 24 | + fluid.addCallback_FluiData(new DwFluid2D.FluidData() { |
| 25 | + public void update(DwFluid2D fluid) { |
| 26 | + if (true) { |
| 27 | + Random rand = new Random(); //instance of random class |
| 28 | + int upperboundx = 800; |
| 29 | + int upperboundy = 800; |
| 30 | + |
| 31 | + int int_randomx = rand.nextInt(upperboundx); |
| 32 | + int int_randomy = 500+rand.nextInt(upperboundy); |
| 33 | + int int_randomvx = rand.nextInt(upperboundx); |
| 34 | + int int_randomvy = rand.nextInt(upperboundy); |
| 35 | + float px = int_randomx; |
| 36 | + float py = height-int_randomy; |
| 37 | + float vx = (int_randomvx - int_randomx) * +15; |
| 38 | + float vy = (int_randomvy - int_randomy) * -15; |
| 39 | + fluid.addVelocity(px, py, 14, vx, vy); |
| 40 | + fluid.addDensity (px, py, 20, 0.0f, 0.4f, 1.0f, 1.0f); |
| 41 | + fluid.addDensity (px, py, 8, 1.0f, 1.0f, 1.0f, 1.0f); |
| 42 | + fluid.addDensity (100,650,50, 1.0f,1.0f,1.0f, 1.0f); |
| 43 | + |
| 44 | + |
| 45 | + } |
| 46 | + } |
| 47 | + }); |
| 48 | + |
| 49 | + pg_fluid = (PGraphics2D) createGraphics(width, height, P2D); |
| 50 | +} |
| 51 | + |
| 52 | + |
| 53 | +public void draw() { |
| 54 | + fluid.update(); |
| 55 | + |
| 56 | + |
| 57 | + pg_fluid.beginDraw(); |
| 58 | + pg_fluid.background(0); |
| 59 | + pg_fluid.endDraw(); |
| 60 | + |
| 61 | + |
| 62 | + fluid.renderFluidTextures(pg_fluid, 0); |
| 63 | + |
| 64 | + |
| 65 | + image(pg_fluid, 0, 0); |
| 66 | +} |
0 commit comments