Can someone tell me why sometimes it looks like the circle will teleport?
import com.thomasdiewald.pixelflow.java.DwPixelFlow;
import com.thomasdiewald.pixelflow.java.dwgl.DwGLTexture;
import com.thomasdiewald.pixelflow.java.fluid.DwFluid2D;
import com.thomasdiewald.pixelflow.java.imageprocessing.filter.DwFilter;
import processing.core.*;
import processing.opengl.PGraphics2D;
DwPixelFlow context;
DwFluid2D fluid;
PGraphics2D pg_fluid;
PVector pos = new PVector(300,300);
void setup() {
size(600, 600, P2D);
context = new DwPixelFlow(this);
fluid = new DwFluid2D(context, width, height, 1);
fluid.param.dissipation_velocity = .5f;
fluid.param.dissipation_density = 1f;
fluid.addCallback_FluiData(new DwFluid2D.FluidData(){
public void update(DwFluid2D fluid) {
if(mousePressed){
float px = mouseX;
float py = height-mouseY;
float vx = (mouseX - pmouseX) * +15;
float vy = (mouseY - pmouseY) * -15;
fluid.addVelocity(px, py, 14, vx, vy);
fluid.addDensity (px, py, 20, 0.0f, 0.4f, 1.0f, 1.0f);
fluid.addDensity (px, py, 8, 1.0f, 1.0f, 1.0f, 1.0f);
}
}
});
pg_fluid = (PGraphics2D) createGraphics(width, height, P2D);
}
DwGLTexture tex_vel_small;
float[] data_vel;
void draw() {
fluid.update();
if(tex_vel_small == null){
tex_vel_small = fluid.tex_velocity.src.createEmtpyCopy();
tex_vel_small.resize(context, width, height);
}
DwFilter.get(context).copy.apply(fluid.tex_velocity.src, tex_vel_small);
context.begin();
data_vel = tex_vel_small.getFloatTextureData(data_vel);
context.end();
for(int gy = 0; gy < height; gy++){
for(int gx = 0; gx < width; gx++){
int gid_fluid = (height - 1 - gy) * tex_vel_small.w + gx;
float vel_x = data_vel[gid_fluid * 2 + 0];
float vel_y = data_vel[gid_fluid * 2 + 1];
if(gy == round(pos.y) && gx == round(pos.x)){
pos.x += vel_x;
pos.y += -vel_y;
}
}
}
pg_fluid.beginDraw();
pg_fluid.background(0);
pg_fluid.endDraw();
fluid.renderFluidTextures(pg_fluid, 0);
image(pg_fluid, 0, 0);
ellipse(pos.x,pos.y,10,10);
}