GithubHelp home page GithubHelp logo

two-ticks / p5.teach.js Goto Github PK

View Code? Open in Web Editor NEW
59.0 6.0 6.0 4.42 MB

A beginner friendly math animation library for p5.js

Home Page: https://two-ticks.github.io/p5.teach.js/

JavaScript 0.44% TypeScript 99.04% HTML 0.52%
education javascript typescript p5js

p5.teach.js's Introduction

p5.teach.js

astrik-logo

A beginner friendly math animation library for p5.js

p5.teach.js provides tools for teaching through p5.js, such as functions to animate text, TeX, and shapes.

Get Started

Documentation

Setting up the development environment

  1. Yarn should be preinstalled
  2. Run yarn install for installing the dependencies
  3. Run yarn dev for running the dev environment
  4. As the code is updated, the final js file is updated in dist/p5.teach.js dynamically
  5. The sketch in the index.html file is reflected with the changes

Generating documentation

  1. We use TypeDoc
  2. Run yarn typedoc src for generating docs

Tests

  1. We use jest for testing
  2. Run yarn test for running tests
  3. Tests are in src/test

Formatting the code

  1. Before submitting PR, run yarn prettier to format the code

Build

  1. Run yarn build to export the final js file
  2. Final js file is exported as dist/p5.teach.js

p5.teach.js's People

Contributors

two-ticks avatar nickmcintyre avatar jithinks97 avatar

Stargazers

 avatar Leonardo Mariscal avatar Val avatar  avatar Teba_eleven avatar Gilli Gillespie avatar Dania Rifki avatar Lucas Lima Rodrigues avatar weizhou avatar Victor L. avatar Z avatar RichMie avatar Arne Christian Schmidt avatar Vaibhav Blayer avatar  avatar Mehdi Nazari avatar HenDaSheng avatar  avatar  avatar thanos avatar Nate avatar Jiege avatar jexchan avatar Ünver Çiftçi avatar xam4lor avatar Paris Koloveas avatar Marcello Seri avatar  avatar  avatar Greg Graham avatar  avatar Eduardo Morais avatar  avatar Clément T. avatar frankfanslc avatar Vikram Dutt avatar Silvio Tisato avatar Luke Zehrung avatar ranjanprj avatar John Mitchell avatar Mark Nadal avatar Jason Altekruse avatar Varoon avatar Iñigo Alonso Fernandez avatar Maciej Sawicki avatar Nish avatar Catalin Stroe avatar henryscala avatar Lucas Martín avatar Tamir Shklaz avatar  avatar  avatar Nguyễn Việt Dũng avatar Gennaro Schiano avatar Corey Benson avatar Lin Liu avatar Rafael Bailo avatar  avatar Lobsang avatar

Watchers

 avatar GoToLoop avatar  avatar  avatar Milton Edwin Cobo Cortez avatar  avatar

p5.teach.js's Issues

instance mode

Currently p5.teach doesn't support p5 instance mode. How can we go forward to add support p5 instance mode?

I tried this but it is not working.

p5.prototype.creatText =  function createText(...args: any[])

image

What changes to environment should I make ?

branch : develop-instance

Color palette

@two-ticks I'm trying to use IBM's color blind safe palette for visualizations in my book whenever possible and find myself copying the hex colors to new sketches a lot. What do you think about exporting the following constants?

export const ULTRAMARINE40 = '#648fff';
export const MAGENTA50 = '#dc267f';
export const GOLD20 = '#ffb000';
export const INDIGO50 = '#785ef0';
export const ORANGE40 = '#fe6100';

Plotting API

I think we should make it simple to generate nice plots. @two-ticks just created a SVG grapher, @JithinKS97 previously wrote p5.2DGraph, and I tried to distill mainim's 2D and 3D primitives when I started planning p5.plot.

A few questions come to mind:

  • What are the right primitives?
  • Canvas, SVG, or both?
  • How do we facilitate interactivity?
  • What's the plan for 3D surface plots, vector fields, etc.?

Personally, I've wanted to implement the grammar of graphics for p5.js for awhile now but haven't had the occasion. Here is an introductory chapter for visualizing data in R with ggplot2.

writing function implementation

Which syntax we should use to call the animation functions?
We can avoid creating many functions for animations by implementing text animations in some what similar manner to manim

let text1 = addText(text, x, y); // adds text to the scene (not visible on screen)
text1.play(fadeOut, 1);          // play(‘animation-type’, duration)

In the proposal we have following (web-editor example writing)

fadeOut(object, duration) //every animation having unique function

manim has following syntax

        self.play(FadeOut(first_line)) #fadeOut animation 
        self.wait(1)

scene implementation

We can use event triggers for scenes. For example this sketch uses space bar for scene switching https://editor.p5js.org/radium.scientist/sketches/g7oDq0M87

we can use all these possibilities

  • event triggered animations (issue #1 )
  • event triggered scenes
  • can define a driving parameter like time for long scenes where event triggering can be tedious

we can decide how to implement scenes and how to add individual animations to the scene

Arrow function

A function that accepts the same parameters as line and draws an arrow is very useful. In math and physics, there are a lot of places where this can come handy.

arrow(x1, y1, x2, y2) will be the function

API for shapes and SVG effects

pull request #20

GObject can deal with 2D, polar and parametric plots, but lacks primary shapes such as lines, rectangles and ellipses. p5.js shapes are difficult to animate and would be slow. SVGs can be easily animated.

What should be the syntax to add rectangle, circle, lines and arrows to graphs (or outside the graph) ?

Do we even need SVG shapes?

  • one of the problem I noticed is SVG elements hide the canvas elements there for if you need to add some shape over the graph it would not be possible with p5.js shapes

Example APIs :

graph.rect(x, y, width, height) //this would work but how to remove this object or reference it

testing

I want to test whether add method is called or not. I have tried these ways but all are giving the same error.

it('add should be called', () => {
  const tex = createTeX('2^2');
  const spy = jest.spyOn(tex, 'add');
  tex.add();
  expect(spy).toHaveBeenCalled();
  //expect(tex.position()).toEqual([10, 20]);
});
it('add should be called', () => {
  const tex = createTeX('2^2');
  const element = createDiv();
  global.createDiv = function(html){return element}
  const spy = jest.spyOn(tex, 'add');
  tex.add();
  expect(spy).toHaveBeenCalled();
  //expect(tex.position()).toEqual([10, 20]);
});

image

other working tests in commit : 0ed4891

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.