Comments (4)
Hi @tcper , yes, cycle
is a continuous function so you may hit values within "0.001" multiple times. One way is to pass the value to interpolate linearly, and then split the results into the number of edges you require. Perhaps something like this? (rough code):
var run = Pts.quickStart( "pt", "#000" );
run( ( time, ftime ) => {
let n = Num.cycle( (time%5000)/5000 );
let ln = Num.lerp( 0, 1, n );
form.text( [20, 20], "n "+n ).text( [20, 40], "ln "+n );
form.text( [20, 60], "edge "+Math.floor(ln/0.25) );
});
(Try pasting the code above in the demo editor for a quick test)
If you must get to 1 in cycle within a threshold, you can try limiting a value at one end, and reseting it on the other end. Maybe something like this (feels a bit hacky though).
let n = Math.min(1, Num.cycle( (time%5000)/5000 ) / 0.99);
if (n === 1 && reset) {
edge++;
reset = false;
} else if (n < 0.1) {
reset = true;
}
So depending on what you're trying to do, you can probably find a better approach 😉 Thanks for trying out Pts!
from pts.
Thank you, I'm researching some good way to do this.
from pts.
Finally, I generate all the points on the edge to animate the circle.
from pts.
Good to hear. If you have other questions, please file a new issue. Thanks for trying out Pts.
from pts.
Related Issues (20)
- pts.js, pts.min.js added to .npmignore and are not served by cdns any longer HOT 2
- Documentation is unclear on how to "unmount" a canvas. HOT 2
- Radial gradients can't use negative coordinates HOT 2
- Safari 15 // Group.moveTo not reflected HOT 5
- Crisp 1px lines on HiDPI devices. HOT 1
- Canvas mouse events coord is wrong on layout change HOT 1
- Add support for roundRect method. HOT 1
- randomPt overwrites input value
- error on form methods when using with an existing canvas HOT 2
- Drawing tools
- Drawing tools
- Add brush like this one https://p5-brush.cargo.site/? HOT 1
- Built-in SVG interactions HOT 2
- Request: Variable thickness lines/curves
- Bound's bottom right pt isn't updated after calling e.g. `add`
- `Group.toBound`'s return type wrongly marked as `Group`
- CanvasForm static drawing functions should accept OffscreenCanvas context
- Incorrect docs in Rectangle.toCircle
- UIDragger.onDrag() not triggering in Firefox and Safari
- Add support for polygons with holes HOT 2
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 pts.