问题现象:1、复制粘贴程序的代码进行合并出现只有一个程序有触发
流体程序(可运行)
/**
*
* PixelFlow | Copyright (C) 2016 Thomas Diewald - http://thomasdiewald.com
*
* A Processing/Java library for high performance GPU-Computing (GLSL).
* MIT License: https://opensource.org/licenses/MIT
*
*/
import com.thomasdiewald.pixelflow.java.DwPixelFlow;
import com.thomasdiewald.pixelflow.java.fluid.DwFluid2D;
import processing.core.*;
import processing.opengl.PGraphics2D;
// Hello World Example for fluid simulations.
//
// Controls:
// LMB/MMB/RMB: add density + Velocity
//
// 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.99f;
// 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;
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);
}
}
});
// render-target
pg_fluid = (PGraphics2D) createGraphics(width, height, P2D);
frameRate(60);
```java
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);
}
视频播放程序(可独立运行)
import processing.video.*;
Movie movie;
void setup() {
size(560, 406);
background(0);
// Load and play the video in a loop
movie = new Movie(this, "launch2.mp4");
movie.loop();
}
void movieEvent(Movie m) {
m.read();
}
void draw() {
//if (movie.available() == true) {
// movie.read();
//}
image(movie, 0, 0, width, height);
}
2、经过调整后出现报错
/**
* Loop.
*
* Shows how to load and play a QuickTime movie file.
*
*/
/**
*
* PixelFlow | Copyright (C) 2016 Thomas Diewald - http://thomasdiewald.com
*
* A Processing/Java library for high performance GPU-Computing (GLSL).
* MIT License: https://opensource.org/licenses/MIT
*
*/
import com.thomasdiewald.pixelflow.java.DwPixelFlow;
import com.thomasdiewald.pixelflow.java.fluid.DwFluid2D;
import processing.video.*;
import processing.core.*;
import processing.opengl.PGraphics2D;
// Hello World Example for fluid simulations.
//
// Controls:
// LMB/MMB/RMB: add density + Velocity
//
// fluid simulation
DwFluid2D fluid;
// render targets
PGraphics2D pg_fluid;
public void settings() {
size(800, 800, P2D);
Movie movie;
}
public void setup() {
size(560, 406);
background(0);
// Load and play the video in a loop
movie = new Movie(this, "launch2.mp4");
movie.loop();
}
void movieEvent(Movie m){
m.read();
}
** ** // library context
错误处❌> 1、DwPixelFlow context = new DwPixelFlow(this);
2、 context.print();
3、context.printGL();
// fluid simulation
> 4、fluid = new DwFluid2D(context, width, height, 1,);
****
// some fluid parameters
fluid.param.dissipation_velocity = 0.70f;
fluid.param.dissipation_density = 0.99f;
// 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;
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);
}
}
});
// render-target
pg_fluid = (PGraphics2D) createGraphics(width, height, P2D);
frameRate(60);
}
public void draw() {
// update simulation
fluid.update();
//if (movie.available() == true) {
// movie.read();
//}
image(movie, 0, 0, width, height);
// clear render target
pg_fluid.beginDraw();
pg_fluid.endDraw();
// render fluid stuff
fluid.renderFluidTextures(pg_fluid, 0);
// display
image(pg_fluid, 0, 0);
}
语法错误 - Error on parameter or method declaration near 'context.print('?
思路:将背景改成透明能显示出下面的视频
尝试方法:1、背景透明化(失败)
目的:流体互动程序附着在视频上方且都能工作