Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified LIQUID/bin/liquid/core/DesktopLauncher.class
Binary file not shown.
Binary file modified LIQUID/bin/liquid/core/LiquidApplication.class
Binary file not shown.
Binary file modified LIQUID/bin/liquid/engine/LiquidEngine.class
Binary file not shown.
Binary file modified LIQUID/bin/liquid/gui/ConsolePanel.class
Binary file not shown.
Binary file modified LIQUID/bin/liquid/gui/LiquidFrame.class
Binary file not shown.
Binary file modified LIQUID/bin/liquid/gui/LiquidGUI.class
Binary file not shown.
Binary file modified LIQUID/bin/liquid/gui/LiquidMenuBar$1.class
Binary file not shown.
Binary file modified LIQUID/bin/liquid/gui/LiquidMenuBar$2.class
Binary file not shown.
Binary file modified LIQUID/bin/liquid/gui/LiquidMenuBar.class
Binary file not shown.
Binary file modified LIQUID/bin/liquid/gui/ParameterPanel.class
Binary file not shown.
1 change: 1 addition & 0 deletions LIQUID/src/liquid/core/DesktopLauncher.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// DONE!
package liquid.core;

/**
Expand Down
1 change: 1 addition & 0 deletions LIQUID/src/liquid/core/Interfaceable.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// DONE!
package liquid.core;

/**
Expand Down
1 change: 1 addition & 0 deletions LIQUID/src/liquid/core/LiquidApplication.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// DONE!
package liquid.core;

import liquid.engine.LiquidEngine;
Expand Down
19 changes: 14 additions & 5 deletions LIQUID/src/liquid/engine/Flowmeter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package liquid.engine;

import java.text.DecimalFormat;
import java.util.ArrayList;

import org.jbox2d.common.Vec2;
Expand All @@ -15,24 +16,32 @@
public class Flowmeter {
private World myWorld;
private Vec2 myLoc;
private float timer;
private int myID;

/**
*
* @param imHere the world this flow meter is monitoring
* @param loc the location this flow meter monitors
*/
public Flowmeter(World imHere, Vec2 loc){
public Flowmeter(World imHere, Vec2 loc, int ID){
myWorld = imHere;
myLoc = loc;
timer = 0;
myID = ID;
}

public String update(){
DecimalFormat adj = new DecimalFormat();
Vec2 curVel = pollVelocity();
adj.setMaximumFractionDigits(4);
String send = "" + myID + ": " + "X-Velocity " + adj.format(curVel.x) + " Y-Velocity " + adj.format(curVel.y);
return send;
}

/**
* Gets the average x and y velocities of particles within 2.0 units of this flowmeter's position
* @return Vec2 object containing the average x and y velocities of nearby particles
*/
public Vec2 pollVelocity(float delta){
timer += delta;
private Vec2 pollVelocity(){
ArrayList<Vec2> vel = new ArrayList<Vec2>();
Vec2[] pos = myWorld.getParticlePositionBuffer();
Vec2 bounds = new Vec2(10.0f, 10.0f); //To change boundaries to check, simply change parameters of constructor
Expand Down
10 changes: 5 additions & 5 deletions LIQUID/src/liquid/engine/FluidEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void update(float delta){
if(timer >= 10){
timer = 0;
for (Flowmeter f: meters){
System.out.println(f.pollVelocity(delta));
System.out.println(f.update());
}
}
}
Expand All @@ -96,17 +96,17 @@ public void addObstacle(Shape s,float x, float y){
b.createFixture(fd);
}

public void addSource(float x, float y, float velx, float vely){
sources.add(new Source(this, x, y, velx, vely));
public void addSource(float x, float y, float velx, float vely, float flow){
sources.add(new Source(this, x, y, velx, vely, flow));
}

/**
* Creates a Flow meter at the specified coordinates
* @param x x-position of the new flow meter
* @param y y-position of the new flow meter
*/
public void addFlowmeter(float x, float y){
meters.add(new Flowmeter(world, new Vec2(x, y)));
public void addFlowmeter(float x, float y, int ID){
meters.add(new Flowmeter(world, new Vec2(x, y), ID));
}

public void addParticle(float x, float y, float velx, float vely){
Expand Down
10 changes: 7 additions & 3 deletions LIQUID/src/liquid/engine/LiquidEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ public void initiateSim(String[] args) {
String[] tokens = args[6].split(" ");
enviro = new FluidEnvironment(Float.parseFloat(tokens[0]),
Float.parseFloat(tokens[1]));
float x, y, l, w;

int ID = 1;
float x, y, l, w, r;

for (int i = 7; i < args.length; i++) {
tokens = args[i].split(" ");
if (tokens[0].equals("Rectangular")) {
Expand Down Expand Up @@ -165,12 +168,13 @@ public void initiateSim(String[] args) {
y = Float.parseFloat(tokens[2]);
l = Float.parseFloat(tokens[3]);
w = Float.parseFloat(tokens[4]);
enviro.addSource(x, y, l, w);
r = Float.parseFloat(tokens[5]);
enviro.addSource(x, y, l, w, r);
}
if (tokens[0].equals("Flowmeter")) {
x = Float.parseFloat(tokens[1]);
y = Float.parseFloat(tokens[2]);
enviro.addFlowmeter(x, y);
enviro.addFlowmeter(x, y, ID++);
}
}
enviro.init();
Expand Down
6 changes: 4 additions & 2 deletions LIQUID/src/liquid/engine/Source.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import org.jbox2d.common.Vec2;

import liquid.core.LiquidApplication;

/**
* @author Rafael Zamora
*
Expand All @@ -17,11 +19,11 @@ public class Source {
private float flowspeed;
private float timer;

public Source(FluidEnvironment enviro, float x, float y, float velx, float vely){
public Source(FluidEnvironment enviro, float x, float y, float velx, float vely, float flow){
this.enviro = enviro;
pos = new Vec2(x, y);
force = new Vec2(velx,vely);
flowspeed = force.length();
flowspeed = flow;
timer = 0;
}

Expand Down
1 change: 1 addition & 0 deletions LIQUID/src/liquid/gui/ConsolePanel.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// DONE!
package liquid.gui;

import java.awt.Color;
Expand Down
119 changes: 119 additions & 0 deletions LIQUID/src/liquid/gui/EnviroAddiParamPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package liquid.gui;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

import liquid.core.LiquidApplication;

/**
* Class creates the additional parameters of the EnvironmentEditorPanel. This is currently
* located at the bottom of the panel, where it is shared by all drop-down options.
*/
public class EnviroAddiParamPanel extends JPanel {

private static final long serialVersionUID = 1L;

// defines variables of the additional parameters
JButton selectNext;
JButton selectPrev;
JButton selectUpdate;
JButton delete;

/**
* Constructor adds the additional parameters of the EnvironmentEditorPanel.
*/
public EnviroAddiParamPanel() {
initComponents();
}

/**
* Initializes the buttons of the additional parameters.
*/
public void initComponents() {
setBounds(5,240,240,65);
setBackground(Color.LIGHT_GRAY);
setLayout(null);

//selectNext = new JButton("Next Item");
//selectNext.setBounds(35,5,(this.getWidth()/2),25);
//add(selectNext);

selectNext = new JButton("Next Item");
selectPrev = new JButton("Prev Item");
selectUpdate = new JButton("Update Item");
delete = new JButton("Delete");
nextParam();
prevParam();
updateParam();
deleteParam();
}

public void nextParam() {
selectNext.setBounds(5,4,(int)(this.getWidth()/2.2),25);
ActionListener next = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
if (LiquidApplication.getGUI().variables.selectedObject < LiquidApplication.getGUI().variables.objects.size()-1){
LiquidApplication.getGUI().variables.selectedObject += 1;
} else {
LiquidApplication.getGUI().variables.selectedObject = 0;
}
LiquidApplication.getGUI().enviroeditor.update();
LiquidApplication.getGUI().variables.saveState();
LiquidApplication.getGUI().sim.repaint();
}
};
selectNext.addActionListener(next);
add(selectNext);
}

public void prevParam() {
selectPrev.setBounds(125,4,(int)(this.getWidth()/2.2),25);
ActionListener prev = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
if( LiquidApplication.getGUI().variables.selectedObject > 0) {
LiquidApplication.getGUI().variables.selectedObject -= 1;
} else {
LiquidApplication.getGUI().variables.selectedObject = LiquidApplication.getGUI().variables.objects.size()-1;
}
LiquidApplication.getGUI().enviroeditor.update();
LiquidApplication.getGUI().variables.saveState();
LiquidApplication.getGUI().sim.repaint();
}
};
selectPrev.addActionListener(prev);
add(selectPrev);
}

public void updateParam() {
selectUpdate.setBounds(5,34,(int)(this.getWidth()/2.2),25);
selectUpdate.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent actionEvent) {
if (LiquidApplication.getGUI().enviroeditor.select.getSelectedItem().equals("Obstacles")) {
LiquidApplication.getGUI().enviroeditor.obstacles.createObstacle(true);
} else if (LiquidApplication.getGUI().enviroeditor.select.getSelectedItem().equals("Initial Forces")) {
LiquidApplication.getGUI().enviroeditor.forces.createForce(true);
} else if (LiquidApplication.getGUI().enviroeditor.select.getSelectedItem().equals("Flow Sensors")) {
LiquidApplication.getGUI().enviroeditor.sensors.createSensor(true);
}
}
});
add(selectUpdate);
}

public void deleteParam() {
delete.setBounds(125,34,(int)(this.getWidth()/2.2),25);
delete.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent actionEvent) {
LiquidApplication.getGUI().variables.objects.remove(LiquidApplication.getGUI().variables.selectedObject);
LiquidApplication.getGUI().variables.selectedObject = 0;
LiquidApplication.getGUI().variables.saveState();
LiquidApplication.getGUI().sim.repaint();
}
});
add(delete);
}
}
Loading