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)
- Feature | Media control buttons for "go to start" and "go to end" HOT 2
- Why do some emojis come up and others dont ? HOT 2
- npm init -- "no prompting" not working HOT 1
- Naming an event 'constructor' causes Firefox to freeze
- Reset to the start of animation in disable loop option HOT 1
- Revamp keyboard bindings and controls, with a global key bindings map and per-module shortcuts HOT 2
- Add an HTML overlay on top of the canvas to potentially add controls and extra info even in presentation mode
- Cannot give Parent Node attributes to Child Node HOT 2
- Can you assign a reference to an already created shape? HOT 8
- Opacity should be at max 1 (or error when higher values are provided) HOT 2
- docs: adding a `troubleshooting` section HOT 2
- Adding light theme to the editor
- Video Playback is extremely slow in Firefox
- Audio from video keeps playing after exiting Presentation or moving back slides
- Add Vector constants for all origins HOT 1
- Scene Hierarchy Examples
- Issue with rendering in Firefox HOT 2
- Rename lib to runtime in 2d package
- SVG Rendering Discrepancy with props like `fill="url(#paint4_linear_10_58)"`
- Directly select timeline range HOT 7
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.