use of math.Vector2d in project SimpleAsteroids by ljialin.
the class VoronoiGrid method paintComponent.
public void paintComponent(Graphics go) {
Graphics2D g = (Graphics2D) go;
Dimension d = getSize();
ElapsedTimer timer = new ElapsedTimer();
int nCells = 0;
for (int y = 0; y < d.getHeight(); y += cellSize) {
for (int x = 0; x < d.getWidth(); x += cellSize) {
nCells++;
int closestIndex = getClosestPointIndex(new Vector2d(x, y));
g.setColor(colors.get(closestIndex));
g.fillRect(x, y, cellSize, cellSize);
}
// System.out.println(y);
}
System.out.println("Painted n cells: " + nCells);
System.out.println(timer);
// if (!dimension.equals(d) || )
}
use of math.Vector2d in project SimpleAsteroids by ljialin.
the class MonkeyBall method update.
@Override
public void update() {
s.add(v);
v.y += gravity;
// now take account of the anchor
if (anchor != null) {
// introduce a tension force on the MonkeyBall towards the anchor
Vector2d tension = new Vector2d(anchor);
tension.subtract(s);
tension.mul(hooke);
v.add(tension);
}
v.mul(loss);
}
use of math.Vector2d in project SimpleAsteroids by ljialin.
the class RopeGameTestController method main.
public static void main(String[] args) throws Exception {
// make a game state
// make a view based on the state
// figure out a way to update it
// the idea is to provide a simple demo of the game
RopeGameState gameState = new RopeGameState();
RopeGameView view = new RopeGameView(gameState);
JEasyFrame frame = new JEasyFrame(view, "Monkey Ball");
Random random = new Random();
// this is the delay per frame update, but also use it
// as the basis of switching an anchor point on and off
int delay = 40;
Vector2d anchor = null;
for (int i = 0; i < 5000; i++) {
// // each time update
// if ((i / 40) % 2 == 0) {
// anchor = null;
// } else {
// // if it is null, make a new one at a Random location
// // otherwise leave alone
// int w = RopeGameState.width;
// if (anchor == null) {
// anchor = new Vector2d(w/4 + random.nextInt(w/2), w/5 + random.nextInt(w/3));
// }
// }
gameState.update(view.anchor);
view.repaint();
Thread.sleep(delay);
}
}
use of math.Vector2d in project SimpleAsteroids by ljialin.
the class TrackTest method drawTrack.
public void drawTrack(Graphics2D g) {
int s = size / 2;
for (double t = 0; t < 20; t += inc) {
Vector2d a = f(t);
Vector2d b = f(t + inc);
g.drawLine((int) (s * a.x), (int) (s * a.y), (int) (s * b.x), (int) (s * b.y));
}
}
use of math.Vector2d in project SimpleAsteroids by ljialin.
the class AgentCentric method main.
// currenty this is just handling the transform
// part of the feature extraction
public static void main(String[] args) {
AgentCentric ac = new AgentCentric(new Vector2d(100, 50), new Vector2d(0, 1));
Vector2d z = new Vector2d(100, 100);
// System.out.println(ac.transform(z));
}
Aggregations