g9 Gallery | Robotically Interactive Graphics

2023-08-08 23:24:56


g9 Gallery | Robotically Interactive Graphics


Spoon me on GitHub

Welcome to the g9 gallery! Drag all of the graphics!

I’ve tried to prepare stuff from primary to superior, so you may scroll from the highest to get an intuitive really feel for g9. It is value mentioning, after all, that intuitive feeling isn’t any match for reading the docs.

Earlier than you dive in, here is a quick clarification of how g9 works (scroll all the way down to skip):

How It Works

g9.js exposes a single operate, g9(initialData, render[, onChange]). This represents the next circulate:

  1. You create some preliminary knowledge as key-value pairs with numeric values. For instance:

    var initialData = {
        foo: 10
    }

    initialData in the docs

  2. This knowledge and a drawing context are fed right into a operate that makes use of the information to determine what to attract.

    operate render(knowledge, ctx){
        ctx.level(knowledge.foo, 17)
    }

    render in the docs

  3. When somebody interacts with the graphics, for instance by attempting to pull a component to a brand new place, g9 optimizes over the area of potential values on your knowledge to discover a set of values that comes closest to creating the change. Should you tried to pull the circle to the left, g9 may give you the brand new knowledge {foo: 8 }.
  4. g9 rerenders your complete scene with the brand new knowledge, in order that all the pieces is constant. Should you’ve offered one, g9 calls your onChange callback with the brand new knowledge, so you may replace different components of your web page.

For an entire therapy of the g9 API, head to the Docs.

A minimal instance with solely two factors. Our render operate all the time attracts one level at (x, y), and the opposite level at (y, x), so while you drag one of many factors, the opposite sort of mirrors it. Attempt including a minus signal earlier than the primary argument of the primary level. What occurs?

Lets add a number of extra factors and use a bit or trigonometry to rearrange them into two circles. Only for enjoyable, we make the interior factors crimson. Attempt dragging the factors!

The entire default shapes in g9 settle for an impacts possibility, which tells them what components of the information they will change. Listed below are three traces with completely different values of impacts.

This is an interactive model of the quadratic bézier curve animation on the bézier curve wikipedia page.

Attempt uncommenting the animation block for further enjoyable!

Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top