Coder Social home page Coder Social logo

caomw / euclid Goto Github PK

View Code? Open in Web Editor NEW

This project forked from anandthakker/euclid

0.0 1.0 0.0 835 KB

:pencil2: Euclidean geometry in javascript

Home Page: http://euclid.js.org

License: MIT License

HTML 32.15% CSS 18.56% CoffeeScript 4.03% JavaScript 45.26%

euclid's Introduction

Euclid Build Status JS.ORG

Euclidean geometry in javascript. Here's a demo; here's another one.

NOTE: Still very preliminary / experimental.

git clone https://github.com/anandthakker/euclid.git
cd euclid
npm install
gulp

Usage

Load It:

Add dist/geometry.css for the basic SVG styles.

<link rel="stylesheet" href="geometry.css">

Put an <svg> element somewhere.

<svg class="geometry-scene" viewbox="0 0 800 800"></svg>

Pull in the javascript, either as a node module...

var geom = require('euclid');

or a browser standalone(ish) script (depends on d3 to be loaded already).

<script src="js/vendor/d3.min.js"></script>
<script src="js/geometry.js"></script> <!-- exposes geom as a global -->

Use It:

And then

var scene = new geom.Scene({
  left: 0,
  top: 0,
  right: 1000,
  bottom: 1000
});
  
scene
  .point('A', width/7*3, height/3) // add a couple of free points.
  .poinnt('B', width/7*5, height/3)
  .segment('S', 'A', 'B')

  // add circle centered at point 'A', with point 'B' on its circumference.
  .circle('M', 'A', 'B')
  .circle('N', 'B', 'A')

  // tag subsequent objects with string 'layer2', used by renderer to add
  // arbitrary CSS classes to svg objects.
  .group('layer2')
  
  // let C and D be the two intersections of circles M and N
  .intersection('C', 'M', 'N', 0)
  .intersection('D', 'M', 'N', 1)
  .line('T', 'A', 'C')
  .segment('U', 'A', 'D')
  
  // let E be the intersection of line T and circle M that *isn't* equivalent to point C.
  .intersection('E', 'T', 'M', scene.isnt('C') )
  .segment('V', 'E', 'B')
  .intersection('F', 'V', 'U')
  .segment('W', 'F', 'C')
  .intersection('W', 'S')
  

// render using d3.
var render = geom.renderer(scene, document.querySelector('svg'));
render();

euclid's People

Contributors

anandthakker avatar indus avatar mathisonian avatar

Watchers

 avatar

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.