Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
📝 Simplify README code and link to GIF code
Browse files Browse the repository at this point in the history
  • Loading branch information
hhenrichsen committed Nov 29, 2023
1 parent 07d3855 commit f321348
Showing 1 changed file with 26 additions and 40 deletions.
66 changes: 26 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,65 +17,47 @@ donate on [Ko-fi](https://ko-fi.com/hhenrichsen).

![](https://github.com/hhenrichsen/motion-canvas-graphing/releases/download/latest/output-big.gif)

Code for this GIF can be found
[here](https://github.com/hhenrichsen/motion-canvas-graphing/blob/main/test/src/scenes/test.tsx)

### Simple Example

```tsx
import {Plot, LinePlot, ScatterPlot} from '@hhenrichsen/motion-canvas-graphing';
import {makeScene2D} from '@motion-canvas/2d';
import {
createRef,
linear,
range,
useRandom,
waitFor,
} from '@motion-canvas/core';
import {createRef, linear, waitFor} from '@motion-canvas/core';

export default makeScene2D(function* (view) {
const random = useRandom();

const plot = createRef<Plot>();
const plot = createRef<LinePlot>();
view.add(
<LinePlot
clip
size={500}
ref={plot}
xAxisLabel="Time"
yAxisLabel="Beans"
labelSize={10}
graphWidth={4}
graphColor={'red'}
data={range(0, 26).map(i => [i * 4, random.nextInt(0, 100)])}
/>,
);

yield* plot().ticks(20, 3);
yield* plot().size(1000, 2);
yield* plot().labelSize(30, 2);
yield* plot().min(-100, 2);
yield* plot().opacity(0, 2);
plot().remove();

const plot2 = createRef<LinePlot>();
view.add(
<LinePlot
size={500}
ref={plot2}
ref={plot4}
labelSize={0}
graphWidth={4}
graphColor={'red'}
min={[-Math.PI * 2, -2]}
minX={-10}
maxX={10}
minY={-2}
maxY={50}
end={0}
max={[Math.PI * 2, 2]}
xLabelFormatter={x => `${Math.round(x / Math.PI)}π`}
opacity={0}
ticks={[4, 4]}
/>,
);

plot2().data(plot2().makeGraphData(0.1, x => Math.sin(x)));

yield* plot2().end(1, 1);
yield* waitFor(3);
yield* plot().opacity(1, 2);
plot().data(plot().makeGraphData(0.1, x => Math.pow(x, 2)));
yield* plot().end(1, 3, linear);
yield* waitFor(2);
yield* plot().opacity(0, 2);

yield* plot2().opacity(0, 2);
plot().remove();

const plot3 = createRef<ScatterPlot>();
const plot2 = createRef<ScatterPlot>();
view.add(
<ScatterPlot
size={500}
Expand All @@ -86,11 +68,15 @@ export default makeScene2D(function* (view) {
pointRadius={5}
pointColor={'red'}
end={0}
opacity={0}
data={range(0, 26).map(i => [i * 4, random.nextInt(0, 100)])}
/>,
);

yield* plot3().end(1, 3, linear);
yield* plot2().opacity(1, 2);
yield* plot2().end(1, 3, linear);
yield* waitFor(2);
yield* plot2().opacity(0, 2);

yield* waitFor(5);
});
Expand Down

0 comments on commit f321348

Please sign in to comment.