Comments (10)
Oh, I see we're rendering on canvases for the shapes! Gradient
should be perfect for this, but I can't figure out how to make it work :/
from motion-canvas.
Hahah!
const filled = createSignal(0);
const myRect = createRef<Rect>();
view.add(<Rect ref={myRect} width={420} height={20} x={0} fill={() => new Gradient({
from: myRect().cacheRect().topLeft,
to: myRect().cacheRect().topRight,
stops: [{ color: "blue", offset: filled() }, { color: "white", offset: filled() }]
})}/>);
yield* filled(1, 2, linear);
That's lovely, pretty much what I wanted :) I'll leave it here in case you want to pop it on the docs for Gradient
?
from motion-canvas.
(Related feature request: It'd be rlly awesome to be able to use absolute positions with Gradient
so I can use it across multiple nodes)
from motion-canvas.
That would be to simplify this:
const filled = createSignal(0);
const space = createSignal<Bounds>();
const layout = <Layout layout direction="column" gap={40} alignItems="center">
{[[300, 100], [420, 20]].map(([w, h]) => {
const rect = <Rect width={w} height={h}/> as Rect;
rect.fill(() => {
const bounds = space();
return new Gradient({
from: bounds.center.transformAsPoint(rect.worldToLocal()),
to: bounds.center.transformAsPoint(rect.worldToLocal()),
type: "radial",
toRadius: Math.sqrt(bounds.width**2 + bounds.height**2) / 2,
stops: [{ color: "blue", offset: filled() }, { color: "white", offset: filled() }]
})
})
return rect;
})}
</Layout>;
space(() => layout.cacheRect().transform(layout.localToWorld()));
view.add(layout);
yield* filled(1, 2, linear);
too um 🤔
const filled = createSignal(0);
const space = createSignal<Bounds>();
const gradient = createSignal(() => new Gradient({
from: space().center,
to: space().center,
type: "absolute-radial",
toRadius: Math.sqrt(space().width**2 + space().height**2) / 2,
stops: [{ color: "blue", offset: filled() }, { color: "white", offset: filled() }]
}))
const layout = <Layout layout direction="column" gap={40} alignItems="center">
{[[300, 100], [420, 20]].map(([w, h]) => <Rect width={w} height={h} fill={gradient}/>)}
</Layout>;
space(() => layout.cacheRect().transform(layout.localToWorld()));
view.add(layout);
yield* filled(1, 2, linear);
from motion-canvas.
I think the best solution would be to turn Gradient
into a node so that it could be placed in the scene:
const gradient = createRef<Gradient>();
view.add(
<>
<Gradient ref={gradient} />
<Rect fill={gradient()} />
</>
);
It wouldn't render anything, but moving it around would move the gradient from/to points. This way you could not only have absolute gradients but also parent them to other nodes.
from motion-canvas.
One possible solution to this might be something like...
<Rect radius={10} width={200} height={20} clip >
<Rect fill={gradient} {/* Other props */} />
</Rect>
So the outer Rect is the actual line being filled, specified with clip properties so that none of the child Rect is drawn outside. Meanwhile the child Rect can be resized or style animated in order to get the style to animate within that line. Would this work? Agreed having a nicer integration with Gradient would be nice.
from motion-canvas.
Hmm could the sizes be specified as percentages of the parent? I don't want to have to manually scale filled
from motion-canvas.
If by "percentages of the parent" you mean its scale, then yes. After turning Gradient
into a Node
, putting it inside of another node would make it scale together with it:
const gradient = createRef<Gradient>();
view.add(
<Rect fill={gradient()}>
<Gradient ref={gradient} />
</Rect>
);
But if you mean the size, then no. It's difficult to imagine how something like this would work since the gradient doesn't have to be aligned with the node - it could be diagonal, for example.
from motion-canvas.
Oh, that was confusing of me! :D I'd only seen @brandonpelfrey's comment when I sent that.
As for Gradient
as a Node
, I don't really understand what you're proposing. Gradients have N stops, they need colour information; and what I'm looking for is being able to build a gradient relative to the Node we're drawing it in, which I can't see the Gradient
nodes' solution for. What do you imagine we'd write to render progress bar?
from motion-canvas.
Regarding progress along a Line, it'd be nice if a line had start% and end% props, as then we could render a line with start% = filled() and a clone with end% = filled(). Same for splines when we get them.
from motion-canvas.
Related Issues (20)
- Documentation pages sometimes failed to load on mobile device
- DestinationUV uniform doesn't scale with scene on render HOT 5
- Preview-only Background Color HOT 1
- TXT does not move with parent Line when tweening HOT 5
- Example scene for Code node HOT 1
- Incorrect Code node width when final line is longest
- Switch code node to use treesitter HOT 3
- tsc command fails with .md files HOT 3
- Make fill and stroke options accept shaders
- gap prop in LayoutProps has the wrong type
- Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0.
- Allow specifying origin for Grid
- Allow matching substrings instead of patterns HOT 3
- Handle invalid offset values in the meta file HOT 2
- Introduce smoothstep interpolation function to chain animations with different interpolation functions smoothly
- How to use themes with the new Code node HOT 5
- Polygon side tweening moves the 0 point on the middle of the created edge HOT 1
- Stack overflow error when attempting to restore a saved state of a `Code` node. HOT 1
- How to place an animation in an existing web project HOT 3
- add tweening for layout properties HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from motion-canvas.