Comments (3)
Thank you @akariinc . You can use Pts' geometric functions without canvas, since they are mostly static functions that accept number arrays as parameters. So you can use your favorite canvas/dom library along with Pts if you like.
For example, if you want to check if the mouse pointer is within a rectangular area, you can do:
// passing numeric array
Rectangle.withinBound( [[boxX, boxY], [boxW, boxH]], [mouseX, mouseY] );
// same as using Pts' Pt and Group instances:
Rectangle.withinBound( group, pt );
( documentation )
Pts also provide svg and dom support (experimental) if you need it. See the SVG section in this guide for more: http://ptsjs.org/guide/space-0500
Thanks for trying out Pts!
from pts.
Thank you very much @williamngan !
Tried with the advise and it worked.
I tried with the circle.intersectCircle2D demo as below.
// Source code licensed under Apache License 2.0.
// Copyright © 2017 William Ngan. (https://github.com/williamngan/pts)
window.demoDescription = "A circle and a donut meets. Indicate their points of intersections.";
//// Demo code starts (anonymous function wrapper is optional) ---
(function() {
// Pts quick start mode.
var run = Pts.quickStart( "#pt", "#fe3" );
run( (time, ftime) => {
let c1 = Circle.fromCenter( space.pointer, space.size.y/4 );
let c2 = Circle.fromCenter( space.pointer, space.size.y/8 );
let ct = Circle.fromCenter( space.center, space.size.y/4 );
let ins1 = Circle.intersectCircle2D( c1, ct );
let ins2 = Circle.intersectCircle2D( c2, ct );
form.fillOnly( "#0c6" ).circle( c1 );
form.fill( "#fe3" ).circle( c2 );
form.fill( "rgba(70,30,240,.2)" ).circle( ct );
form.fill( "rgba(70,30,240, .3)" ).points( ins1, 10, "circle" );
form.fill( "#f06" ).points( ins2, 5, "circle" );
});
const html = document.querySelector("html");
document.addEventListener("mousemove", (event) => {
let c1 = Circle.fromCenter( [event.x, event.y], html.clientHeight/4 );
let c2 = Circle.fromCenter( [event.x, event.y], html.clientHeight/8 );
let ct = Circle.fromCenter( [html.clientWidth/2, html.clientHeight/2], html.clientHeight/4 );
let ins1 = Circle.intersectCircle2D( c1, ct );
let ins2 = Circle.intersectCircle2D( c2, ct );
// Returning correct result!
// console.log(ins1, ins2);
})
})();
Maybe in the future, isn't it great if it works without any changes to code whether target is canvas or other DOM or no-DOM?
var run = Pts.quickStartWithDOM(document, null);
// var run = Pts.quickStartWithoutDOM("#menu" ); // #menu is the target element for geometry
Anyway, thank you so much for the advise for now !! I will give it a try more.
from pts.
Good to know. Thanks 😃
Yes, once the DOMSpace
is more stable we should consider having quickStart option. Also take a look at the source code in these 2 demos if you want to try manipulating DOM elements with Pts directly (experimental):
http://ptsjs.org/demo/?name=svgform.scope
http://ptsjs.org/demo/?name=htmlform.scope
Right now there are a few features missing in svg/dom. But for simple sketch you can switch between svg and canvas with just one extra line form.scope( this );
Hope this helps. Would love to see what you make with Pts!
from pts.
Related Issues (20)
- sound demos HOT 1
- source-map file missing when importing pts
- Canvas size issue when html attribute and css style width & height differs. HOT 4
- Fix parameter types HOT 1
- CanvasForm(ctx) methods error. HOT 3
- Implement oklab color
- will pts provide an api to render in existing canvas provided by the user? HOT 2
- 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
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.