PixelFlow GetStart(一)
程序员文章站
2022-04-27 13:17:13
...
鼠标跟随:
import com.thomasdiewald.pixelflow.java.DwPixelFlow;
import com.thomasdiewald.pixelflow.java.fluid.DwFluid2D;
import processing.core.*;
import processing.opengl.PGraphics2D;
// fluid simulation
DwFluid2D fluid;
// render targets
PGraphics2D pg_fluid;
public void settings() {
size(800, 800, P2D);
}
public void setup() {
// library context
DwPixelFlow context = new DwPixelFlow(this);
context.print();
context.printGL();
// fluid simulation
fluid = new DwFluid2D(context, width, height, 1);
// some fluid parameters
fluid.param.dissipation_velocity = 0.70f; // 加速度
fluid.param.dissipation_density =0.99; // fluid消散速度
//adding data to the fluid simulation
fluid.addCallback_FluiData(new DwFluid2D.FluidData(){
public void update(DwFluid2D fluid) {
if(mousePressed){
float px = mouseX;
float py = height-mouseY; // 转换到 fluid坐标
float vx = (mouseX - pmouseX) * +15; // * ( +15)
float vy = (mouseY - pmouseY) * -15; // * ( -15)
fluid.addVelocity(px, py, 14, vx, vy); // 这个 14 没看懂是干啥的,有人知道 @ 我
fluid.addDensity (px, py, 20, 0.0f, 0.4f, 1.0f, 1.0f); // 20 是宽度 后面四个参数是颜色
fluid.addDensity (px, py, 8, 1.0f, 0f, 0f, 1.0f);
}
}
});
// render-target
pg_fluid = (PGraphics2D) createGraphics(width, height, P2D);
frameRate(60);
}
public void draw() {
// update simulation
fluid.update();
// clear render target
pg_fluid.beginDraw();
pg_fluid.background(0); // 参数 颜色
pg_fluid.endDraw();
// render fluid stuff=>填充
fluid.renderFluidTextures(pg_fluid, 0);
// display
image(pg_fluid, 0, 0);
}
上一篇: 互动编程习作——表现随机行为及牛顿运动学
下一篇: mysql event