Hi everybody, this might be a very easy qestion - but i just don't get it. I'm playing with the HYPE library and want to add a slider to change the size of my particles on runtime. I just don't find how to get down to a single particle to mess around with its values.
Somebody can help me? (Lines 129 - 139 demonstrate the problem)
` //SWARM:
import java.util.Iterator;
import hype.*;
import hype.extended.behavior.HSwarm;
import hype.extended.behavior.HTimer;
import hype.extended.behavior.HTween;
import hype.extended.colorist.HColorPool;
import hype.interfaces.HLocatable;
import controlP5.*;
HColorPool colors;
HCanvas canvas;
HSwarm swarm;
HDrawablePool pool;
HTimer timer;
int i=0;
ControlP5 cp5;
int sliderValue = 100;
int sliderX = 450;
int sliderY = 40;
int mySize = 5;
int speed = 2;
HPath p1 = new HPath();
void setup() {
size(640,640);
cp5 = new ControlP5(this);
cp5.addSlider("speed")
.setPosition(sliderX,sliderY)
.setRange(0,10)
.setValue(2)
.setNumberOfTickMarks(10)
;
cp5.addSlider("mySize")
.setPosition(sliderX,sliderY+30)
.setRange(0.01,0.2)
.setValue(0.03)
.setNumberOfTickMarks(10)
;
H.init(this).background(#242424);
colors = new HColorPool(#FFFFFF, #F7F7F7, #ECECEC, #333333, #0095a8, #00616f, #FF3300, #FF6600);
H.add(canvas = new HCanvas()).autoClear(false).fade(400);
swarm = new HSwarm()
.speed(2)
.turnEase(0.03f)
.twitch(5)
.idleGoal(width/2,height/2)
;
//This is the target to swim to
pool = new HDrawablePool(1);
pool.autoAddToStage()
.add(new HRect(10).rounding(0))
.onCreate(
new HCallback() {
public void run(Object obj) {
final HDrawable d = (HDrawable) obj;
d
.strokeWeight(2)
//.stroke(#ECECEC)
//.fill(#111111)
.noStroke()
.noFill()
.loc((int)random(100,540), (int)random(100,540))
.anchorAt(H.CENTER)
.rotation(45)
;
final HTween tween = new HTween()
.target(d).property(H.LOCATION)
.start(d.x(), d.y())
.end((int)random(width), (int)random(height))
.ease(0.01).spring(0.9)
;
final HCallback onAnim = new HCallback() {
public void run(Object obj) {
tween
.start(d.x(), d.y())
.end((int)random(100,540), (int)random(100,540))
.ease(0.01)
.spring(0.9)
.register()
;
}
};
timer = new HTimer().interval(2000).callback(onAnim);
}
}
)
.requestAll()
;
}
void draw() {
//Emit 200 particles
if(i++<200) {
swarm.addTarget(
canvas.add(
new HRect(random(3,mySize))
//with size(int,int) or scale(int) size can be adjusted here
.rounding(4)
.anchorAt( H.CENTER )
.noStroke()
.fill(colors.getColor())
)
);
}
H.drawStage();
for(Iterator<HLocatable> it=swarm.goals().iterator();it.hasNext();) {
it.remove();
it.next();
}
for(HDrawable d : pool) {
swarm.addGoal(d.x(),d.y());
}
}
//controlP5 slider 1
void speed(int theSpeed) {
//This one is easy:
swarm.speed(theSpeed);
}
//controlP5 slider 2
void mySize(int mySize) {
//But where is the size of a single object?!
for(int i = 0; i < swarm.targets().size(); i++) {
//swarm.WHERE?
}
}
Thanks a lot