Giter Club home page Giter Club logo

Comments (3)

williamngan avatar williamngan commented on May 11, 2024

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.

akariinc avatar akariinc commented on May 11, 2024

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.

williamngan avatar williamngan commented on May 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.