use of spacegraph.space2d.widget.text.Label in project narchy by automenta.
the class TensorGlow method main.
public static void main(String[] args) {
PhyWall p = SpaceGraph.wall(1200, 1000);
p.W.setGravity(new v2(0, -2.8f));
staticBox(p.W, -5, -8, +5, 2f, false, true, true, true);
for (int j = 0; j < 3; j++) {
BodyDef bodyDef2 = new BodyDef();
bodyDef2.type = BodyType.DYNAMIC;
// otocenie
bodyDef2.angle = -0.6f;
// smer pohybu
bodyDef2.linearVelocity = new v2(0.0f, 0.0f);
// rotacia (rychlost rotacie)
bodyDef2.angularVelocity = 0.0f;
Body2D newBody = p.W.addBody(bodyDef2);
PolygonShape shape2 = new PolygonShape();
shape2.setAsBox(0.25f, 0.25f);
Fixture f = newBody.addFixture(shape2, 1.0f);
// trenie
f.friction = 0.5f;
// odrazivost
f.restitution = 0.0f;
f.material = new Uniform();
f.material.m_rigidity = 1.0f;
}
// //ceiling rack
// addBox(p.W, -1, +0.4f, 0, +0.65f, false, true, true, true);
// new Pacman(p.W);
{
p.W.setContactListener(new Explosives.ExplosionContacts());
TheoJansen t = new TheoJansen(p.W, 0.35f);
PhyWall.PhyWindow pw = p.put(new Gridding(0.5f, new Port((float[] v) -> {
// System.out.println(v);
t.motorJoint.setMotorSpeed(v[0] * 2 - v[1] * 2);
t.motorJoint.setMaxMotorTorque(v[2]);
t.motorJoint.enableLimit(true);
t.motorJoint.setLimits((float) (-v[3] * Math.PI), (float) (+v[4] * Math.PI));
if (v[5] > 0.5f) {
t.gun.fire();
}
t.turretJoint.setLimits((float) (+Math.PI / 2 + v[6] * Math.PI - 0.1f), (float) (+Math.PI / 2 + v[6] * Math.PI + 0.1f));
})), 0.8f, 0.4f);
p.W.addJoint(new RevoluteJoint(p.W, new RevoluteJointDef(pw.body, t.chassis)));
}
{
p.W.setParticleRadius(0.05f);
p.W.setParticleDamping(0.1f);
CircleShape shape = new CircleShape();
shape.center.set(0, 10);
shape.radius = 2f;
ParticleGroupDef pd = new ParticleGroupDef();
pd.flags = ParticleType.b2_waterParticle;
// b2_viscousParticle;
// b2_elasticParticle;
// b2_springParticle;
// b2_powderParticle;
pd.color = new ParticleColor(0.7f, 0.1f, 0.1f, 0.8f);
pd.shape = shape;
p.W.addParticles(pd);
}
HaiQae q = new HaiQae(8, 2);
float[] in = new float[q.ae.inputs()];
final Tensor randomVector = Tensor.randomVectorGauss(in.length, 0, 1, rng);
final FloatRange lerpRate = new FloatRange(0.01f, 0, 1f);
final TensorLERP lerpVector = new TensorLERP(randomVector, lerpRate);
PhyWall.PhyWindow w = p.put(new Gridding(0.25f, new AutoUpdateMatrixView(lerpVector.data), new LabeledPane("lerp", new XYSlider().on((x, y) -> {
lerpRate.set(x);
})), new LabeledPane("out", new Port((x) -> {
}) {
@Override
public void prePaint(int dtMS) {
super.prePaint(dtMS);
out(lerpVector.data);
}
})), 0.5f, 0.5f);
p.put(new TogglePort(), 0.25f, 0.25f);
PhyWall.PhyWindow qw = p.put(new Gridding(new Label("HaiQ"), new AutoSurface<>(q), new LabeledPane("input", new Port((float[] i) -> {
System.arraycopy(i, 0, in, 0, i.length);
})), new Gridding(VERTICAL, new AutoUpdateMatrixView(in), new AutoUpdateMatrixView(q.ae.x), new AutoUpdateMatrixView(q.ae.W), new AutoUpdateMatrixView(q.ae.y)), new Gridding(VERTICAL, new AutoUpdateMatrixView(q.q), new AutoUpdateMatrixView(q.et))), 1, 1);
Loop.of(() -> {
lerpVector.update();
q.act((((float) Math.random()) - 0.5f) * 2, in);
}).runFPS(25);
}
use of spacegraph.space2d.widget.text.Label in project narchy by automenta.
the class ExeCharts method runPanel.
public static Surface runPanel(NAR n) {
Label nameLabel;
LoopPanel control = new LoopPanel(n.loop);
Surface p = new Gridding(nameLabel = new Label(n.self().toString()), control);
return DurSurface.get(p, n, () -> {
control.update();
});
}
use of spacegraph.space2d.widget.text.Label in project narchy by automenta.
the class PhyWall method snake.
protected Snake snake(Wire wire, Runnable onRemove) {
Surface source = wire.a;
Surface target = wire.b;
assert (source != target);
float sa = source.bounds.area();
float ta = target.bounds.area();
float areaDiff = Math.abs(sa - ta) / (sa + ta);
// heuristic estimate: larger area difference = shorter snake
int segments = Util.lerp(areaDiff, 8, 6);
float EXPAND_SCALE_FACTOR = 4;
PushButton deleteButton = new PushButton("x");
Surface menu = new TabPane(ButtonSet.Mode.Multi, Map.of("o", () -> new Gridding(new Label(source.toString()), new Label(target.toString()), deleteButton)), (l) -> new CheckBox(l) {
@Override
protected String label(String text, boolean on) {
// override just display the 'o'
return text;
}
@Override
public ToggleButton set(boolean expanded) {
super.set(expanded);
synchronized (wire) {
PhyWindow w = parent(PhyWindow.class);
if (w == null)
return this;
float cx = w.cx();
float cy = w.cy();
float ww, hh;
if (expanded) {
// grow
ww = w.w() * EXPAND_SCALE_FACTOR;
hh = w.h() * EXPAND_SCALE_FACTOR;
} else {
// shrink
ww = w.w() / EXPAND_SCALE_FACTOR;
hh = w.h() / EXPAND_SCALE_FACTOR;
}
w.pos(cx - ww / 2, cy - hh / 2, cx + ww / 2, cy + hh / 2);
}
return this;
}
});
PhyWindow menuBody = put(menu, RectFloat2D.mid(source.bounds, target.bounds, 0.1f));
float mw = menuBody.radius();
Snake s = new Snake(source, target, segments, 1.618f * 2 * mw, mw) {
@Override
public void remove() {
onRemove.run();
super.remove();
}
};
s.attach(menuBody.body, segments / 2 - 1);
deleteButton.click(s::remove);
int jj = 0;
for (Joint j : s.joints) {
float p = ((float) jj) / (segments - 1);
// custom joint renderer: color coded indicate activity and type of data
j.setData((ObjectLongProcedure<GL2>) (g, now) -> {
int TIME_DECAY_MS = 250;
boolean side = p < 0.5f;
float activity = wire.activity(side, now, TIME_DECAY_MS);
// Util.lerp(p, wire.activity(false, now, TIME_DECAY_MS), wire.activity(true, now, TIME_DECAY_MS));
int th = wire.typeHash(side);
if (th == 0) {
g.glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
} else {
Draw.colorHash(g, th, 0.9f, 0.5f + 0.5f * activity, 0.5f + 0.4f * activity);
}
g.glLineWidth(10f + activity * 10f);
// Draw.line(g, w.a.cx(), w.a.cy(), w.b.cx(), w.b.cy());
// return;
});
jj++;
}
return s;
}
Aggregations