package com.danbrookes.main;
import java.util.ArrayList;
import processing.core.*;
public class Base extends PApplet {
private static final long serialVersionUID = -7052994455601885135L;
private ArrayList<TestObject> list = new ArrayList<TestObject>();
private PApplet app = this;
private int amount = 2500;
private float rnd;
private float ms;
// main
public static void main(String[] args) {
PApplet.main(new String[] {Base.class.getName()});
}
// setup
@Override
public void setup() {
size(640, 360);
frameRate(60);
fill(255, 128);
strokeWeight(1);
stroke(0, 128);
textSize(48);
smooth();
for (int i = 0; i < amount; i++) {
rnd = random(10);
list.add(new TestObject(app, random(width), random(height), rnd, rnd));
}
}
// draw
@Override
public void draw() {
background(255);
fill(0, 64);
ms = millis();
for (int i = 0; i < amount; i++) {
list.get(i).setPos(list.get(i).getX() + random(-2,2), list.get(i).getY() + random(-2,2));
}
fill(255,0,0);
text(millis() - ms + "", 10, 10, 200, 200);
}
}
---------------------------------------------
package com.danbrookes.main;
import processing.core.*;
public class TestObject {
private PApplet pro;
private float x;
private float y;
private float w;
private float h;
public TestObject(PApplet processing, float tX, float tY, float tW, float tH) {
pro = processing;
pro.registerDraw(this);
x = tX;
y = tY;
w = tW;
h = tH;
}
public void draw() {
pro.ellipse(x, y, w, h);
}
public void setPos(float x, float y) {
this.x = x;
this.y = y;
}
public float getX() {
return x;
}
public float getY() {
return y;
}
public void setScale(float w, float h) {
this.w = w;
this.h = h;
}
public float getW() {
return w;
}
public float getH() {
return h;
}
}