Search in sources :

Example 1 with PushButton

use of spacegraph.space2d.widget.button.PushButton in project narchy by automenta.

the class AllOrNothingSlider method AllOrNothingSlider.

public static Gridding AllOrNothingSlider(FloatSlider f) {
    PushButton zeroButton = new PushButton("-").click((cb) -> f.valueRelative(0f));
    PushButton oneButton = new PushButton("+").click((cb) -> f.valueRelative(1f));
    return new Gridding(Gridding.HORIZONTAL, f, new Gridding(Gridding.VERTICAL, zeroButton, oneButton));
}
Also used : Gridding(spacegraph.space2d.container.Gridding) PushButton(spacegraph.space2d.widget.button.PushButton)

Example 2 with PushButton

use of spacegraph.space2d.widget.button.PushButton in project narchy by automenta.

the class NAgentX method chart.

public static void chart(NAgent a) {
    NAR nar = a.nar();
    nar.runLater(() -> {
        SpaceGraph.window(grid(new AutoSurface(a), Vis.beliefCharts(nar.dur() * 64, a.actions.keySet(), a.nar()), new EmotionPlot(64, a), grid(// concept query box
        new TextEdit() {

            @Override
            protected void onKeyEnter() {
                String s = text();
                text("");
                try {
                    nar.conceptualize(s);
                } catch (Narsese.NarseseException e) {
                    e.printStackTrace();
                }
                Vis.conceptWindow(s, nar);
            }
        }.surface(), // new WindowButton("log", () -> Vis.logConsole(nar, 80, 25, new FloatParam(0f))),
        new PushButton("dump", () -> {
            try {
                nar.output(Files.createTempFile(a.toString(), "" + System.currentTimeMillis()).toFile(), false);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }), new PushButton("clear", () -> {
            nar.runLater(NAR::clear);
        }), new PushButton("prune", () -> {
            nar.runLater(() -> {
                DoubleHistogram i = new DoubleHistogram(2);
                nar.tasks(true, false, false, false).forEach(t -> i.recordValue(t.conf()));
                float confThresh = (float) i.getValueAtPercentile(25);
                nar.tasks(true, false, false, false).filter(t -> t.conf() < confThresh).forEach(Task::delete);
            });
        }), new WindowToggleButton("top", () -> new ConsoleTerminal(new nars.TextUI(nar).session(10f))), new WindowToggleButton("concept graph", () -> {
            DynamicConceptSpace sg;
            SpaceGraphPhys3D s = new SpaceGraphPhys3D<>(sg = new DynamicConceptSpace(nar, () -> nar.exe.active().iterator(), 128, 16));
            EdgeDirected fd = new EdgeDirected();
            s.dyn.addBroadConstraint(fd);
            fd.attraction.set(fd.attraction.get() * 8);
            s.add(new SubOrtho(// window(
            grid(new AutoSurface<>(fd), new AutoSurface<>(sg.vis))) {
            }.posWindow(0, 0, 1f, 0.2f));
            // ,  400, 400);
            // .pos(0, 0, 0.5f, 0.5f)
            s.camPos(0, 0, 90);
            return s;
        }), a instanceof NAgentX ? new WindowToggleButton("vision", () -> grid(((NAgentX) a).sensorCam.stream().map(cs -> new AspectAlign(new CameraSensorView(cs, a).withControls(), AspectAlign.Align.Center, cs.width, cs.height)).toArray(Surface[]::new))) : grid())), // 
        900, 600);
    });
}
Also used : Bitmap2DSensor(nars.util.signal.Bitmap2DSensor) IntConsumer(java.util.function.IntConsumer) AspectAlign(spacegraph.space2d.container.AspectAlign) Auvent(net.beadsproject.beads.core.Auvent) AutoSurface(spacegraph.space2d.widget.meta.AutoSurface) RealTime(nars.time.RealTime) nars.$.$$(nars.$.$$) DoubleHistogram(org.HdrHistogram.DoubleHistogram) SpaceGraphPhys3D(spacegraph.space3d.SpaceGraphPhys3D) Vis(nars.gui.Vis) Bitmap2D(jcog.signal.Bitmap2D) XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom) Term(nars.term.Term) nars.video(nars.video) ConsoleTerminal(spacegraph.space2d.widget.console.ConsoleTerminal) Loop(jcog.exe.Loop) UGen(net.beadsproject.beads.core.UGen) BufferedImage(java.awt.image.BufferedImage) Util(jcog.Util) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) Nullable(org.jetbrains.annotations.Nullable) WaveFactory(net.beadsproject.beads.data.WaveFactory) WorkerMultiExec(nars.exe.WorkerMultiExec) SpaceGraph(spacegraph.SpaceGraph) EmotionPlot(nars.gui.EmotionPlot) Tense(nars.time.Tense) net.beadsproject.beads.ugens(net.beadsproject.beads.ugens) Focus(nars.exe.Focus) Surface(spacegraph.space2d.Surface) Function(java.util.function.Function) Supplier(java.util.function.Supplier) nars.$.$(nars.$.$) WindowToggleButton(spacegraph.space2d.widget.meta.WindowToggleButton) SubOrtho(spacegraph.space2d.hud.SubOrtho) Gridding.grid(spacegraph.space2d.container.Gridding.grid) EdgeDirected(spacegraph.space2d.container.EdgeDirected) FloatProcedure(org.eclipse.collections.api.block.procedure.primitive.FloatProcedure) Inperience(nars.op.mental.Inperience) Files(java.nio.file.Files) PushButton(spacegraph.space2d.widget.button.PushButton) DynamicConceptSpace(nars.gui.graph.DynamicConceptSpace) IOException(java.io.IOException) AudioContext(net.beadsproject.beads.core.AudioContext) IntObjectPair(org.eclipse.collections.api.tuple.primitive.IntObjectPair) java.awt(java.awt) TextEdit(spacegraph.space2d.widget.console.TextEdit) BELIEF(nars.Op.BELIEF) ConjClustering(nars.op.stm.ConjClustering) CaffeineIndex(nars.index.term.map.CaffeineIndex) DynamicConceptSpace(nars.gui.graph.DynamicConceptSpace) DoubleHistogram(org.HdrHistogram.DoubleHistogram) IOException(java.io.IOException) SpaceGraphPhys3D(spacegraph.space3d.SpaceGraphPhys3D) EdgeDirected(spacegraph.space2d.container.EdgeDirected) WindowToggleButton(spacegraph.space2d.widget.meta.WindowToggleButton) AspectAlign(spacegraph.space2d.container.AspectAlign) EmotionPlot(nars.gui.EmotionPlot) TextEdit(spacegraph.space2d.widget.console.TextEdit) AutoSurface(spacegraph.space2d.widget.meta.AutoSurface) ConsoleTerminal(spacegraph.space2d.widget.console.ConsoleTerminal) PushButton(spacegraph.space2d.widget.button.PushButton) SubOrtho(spacegraph.space2d.hud.SubOrtho)

Example 3 with PushButton

use of spacegraph.space2d.widget.button.PushButton in project narchy by automenta.

the class TasksView method layoutTimeline.

public void layoutTimeline() {
    final MapNodeGraph<Surface, String> graph = new MapNodeGraph();
    float tScale = 100;
    float tMin = tScale;
    for (Surface cc : children()) {
        // TODO make window content iteration method
        TaskIcon c = (TaskIcon) cc;
        Task t = c.task;
        NodeGraph.MutableNode<Surface, String> tn = graph.addNode(c);
        for (long e : t.stamp()) {
            NodeGraph.Node en = graph.node(evidences.getIfAbsentPutWithKey(e, (ee) -> {
                Surface s = new PushButton("_" + ee);
                // TODO make evidence buttons visibility toggleable
                // children.add(s);
                graph.addNode(s);
                return s;
            }));
            graph.addEdge((NodeGraph.MutableNode) en, "stamp", tn);
        }
        float minH = 30;
        float maxH = 200;
        float h = t.isQuestOrQuestion() ? Util.lerp(t.originality() / 2f, minH, maxH) : Util.lerp(t.originality() * t.conf(), minH, maxH);
        long start, end;
        if (!t.isEternal()) {
            start = t.start();
            end = t.end();
        } else {
            start = t.creation();
            // TODO max time
            end = 10;
        }
        float x1 = start * tScale;
        float x2 = end * tScale;
        if (x2 - x1 < tMin) {
            float x = (x1 + x2) / 2f;
            x1 = x - tMin / 2;
            x2 = x + tMin / 2;
        }
        float y = (float) (Math.random() * 500);
        c.pos(x1, y, x2, y + h);
    }
    graph.print();
    new Thread(() -> {
        int iterations = 300;
        for (int i = 0; i < iterations; i++) {
            layoutForceDirect(graph);
            layout();
            Util.sleep(5);
        }
    }).start();
}
Also used : NodeGraph(jcog.data.graph.NodeGraph) MutableContainer(spacegraph.space2d.container.MutableContainer) PushButton(spacegraph.space2d.widget.button.PushButton) Surface(spacegraph.space2d.Surface) IOException(java.io.IOException) MapNodeGraph(jcog.data.graph.MapNodeGraph) Util(jcog.Util) spacegraph.util.math.v2(spacegraph.util.math.v2) File(java.io.File) Task(nars.Task) TODO(jcog.TODO) Op(nars.Op) LongObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap) SpaceGraph(spacegraph.SpaceGraph) Task(nars.Task) MapNodeGraph(jcog.data.graph.MapNodeGraph) NodeGraph(jcog.data.graph.NodeGraph) MapNodeGraph(jcog.data.graph.MapNodeGraph) Surface(spacegraph.space2d.Surface) PushButton(spacegraph.space2d.widget.button.PushButton)

Example 4 with PushButton

use of spacegraph.space2d.widget.button.PushButton in project narchy by automenta.

the class DynamicConceptSpace method get.

@Override
protected List<ConceptWidget> get() {
    if (updated.get()) {
        List<ConceptWidget> w;
        w = next.write();
        w.clear();
        concepts.forEach((clink) -> {
            // ConceptWidget cw = space.getOrAdd(clink.get().id, ConceptWidget::new);
            Concept cc = clink.get().id;
            ConceptWidget cw = cc.meta(spaceID, (sid) -> new ConceptWidget(cc) {

                @Override
                protected void onClicked(PushButton b) {
                    SpaceGraph.window(new ConceptSurface(id.term(), nar), 800, 700);
                }
            });
            if (cw != null) {
                cw.activate();
                cw.pri = clink.priElseZero();
                w.add(cw);
            }
        // space.getOrAdd(concept.term(), materializer).setConcept(concept, now)
        });
        vis.accept(next.write());
        next.commit();
        updated.set(false);
    }
    return next.read();
}
Also used : Concept(nars.concept.Concept) ConceptSurface(nars.gui.ConceptSurface) PushButton(spacegraph.space2d.widget.button.PushButton)

Example 5 with PushButton

use of spacegraph.space2d.widget.button.PushButton 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;
}
Also used : RayCastInput(spacegraph.space2d.phys.collision.RayCastInput) Random(java.util.Random) ParticleColor(spacegraph.space2d.phys.particle.ParticleColor) ButtonSet(spacegraph.space2d.widget.tab.ButtonSet) TabPane(spacegraph.space2d.widget.tab.TabPane) ParticleSystem(spacegraph.space2d.phys.particle.ParticleSystem) spacegraph.space2d.phys.dynamics.joints(spacegraph.space2d.phys.dynamics.joints) ToggleButton(spacegraph.space2d.widget.button.ToggleButton) Map(java.util.Map) Finger(spacegraph.input.finger.Finger) XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom) PolygonShape(spacegraph.space2d.phys.collision.shapes.PolygonShape) NodeGraph(jcog.data.graph.NodeGraph) CircleShape(spacegraph.space2d.phys.collision.shapes.CircleShape) MapNodeGraph(jcog.data.graph.MapNodeGraph) Util(jcog.Util) Animated(spacegraph.util.animate.Animated) List(java.util.List) ImmutableDirectedEdge(jcog.data.graph.ImmutableDirectedEdge) GL2(com.jogamp.opengl.GL2) WizardFrame(spacegraph.space2d.widget.meta.WizardFrame) ObjectLongProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectLongProcedure) Shape(spacegraph.space2d.phys.collision.shapes.Shape) PolygonFixture(spacegraph.space2d.phys.fracture.PolygonFixture) spacegraph.space2d.phys.dynamics(spacegraph.space2d.phys.dynamics) Surface(spacegraph.space2d.Surface) Draw(spacegraph.video.Draw) Supplier(java.util.function.Supplier) Tuple2f(spacegraph.util.math.Tuple2f) EdgeShape(spacegraph.space2d.phys.collision.shapes.EdgeShape) Tuples.pair(org.eclipse.collections.impl.tuple.Tuples.pair) DoubleClicking(spacegraph.input.finger.DoubleClicking) Gridding(spacegraph.space2d.container.Gridding) On(jcog.event.On) AABB(spacegraph.space2d.phys.collision.AABB) RayCastOutput(spacegraph.space2d.phys.collision.RayCastOutput) Pair(org.eclipse.collections.api.tuple.Pair) Ortho(spacegraph.space2d.hud.Ortho) PushButton(spacegraph.space2d.widget.button.PushButton) FasterList(jcog.list.FasterList) Transform(spacegraph.space2d.phys.common.Transform) spacegraph.util.math.v2(spacegraph.util.math.v2) RectFloat2D(jcog.tree.rtree.rect.RectFloat2D) CheckBox(spacegraph.space2d.widget.button.CheckBox) Consumer(java.util.function.Consumer) ArrayIterator(jcog.util.ArrayIterator) FingerDragging(spacegraph.input.finger.FingerDragging) SurfaceBase(spacegraph.space2d.SurfaceBase) ProtoWidget(spacegraph.space2d.widget.meta.ProtoWidget) Collections(java.util.Collections) Label(spacegraph.space2d.widget.text.Label) TabPane(spacegraph.space2d.widget.tab.TabPane) ToggleButton(spacegraph.space2d.widget.button.ToggleButton) Label(spacegraph.space2d.widget.text.Label) GL2(com.jogamp.opengl.GL2) Surface(spacegraph.space2d.Surface) Gridding(spacegraph.space2d.container.Gridding) spacegraph.space2d.phys.dynamics.joints(spacegraph.space2d.phys.dynamics.joints) spacegraph.space2d.phys.dynamics(spacegraph.space2d.phys.dynamics) Collections(java.util.Collections) CheckBox(spacegraph.space2d.widget.button.CheckBox) PushButton(spacegraph.space2d.widget.button.PushButton)

Aggregations

PushButton (spacegraph.space2d.widget.button.PushButton)5 Util (jcog.Util)3 Surface (spacegraph.space2d.Surface)3 IOException (java.io.IOException)2 Supplier (java.util.function.Supplier)2 MapNodeGraph (jcog.data.graph.MapNodeGraph)2 NodeGraph (jcog.data.graph.NodeGraph)2 XoRoShiRo128PlusRandom (jcog.math.random.XoRoShiRo128PlusRandom)2 SpaceGraph (spacegraph.SpaceGraph)2 spacegraph.util.math.v2 (spacegraph.util.math.v2)2 GL2 (com.jogamp.opengl.GL2)1 java.awt (java.awt)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 Files (java.nio.file.Files)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 Consumer (java.util.function.Consumer)1