Code Monkey home page Code Monkey logo

interactive-canvas's Introduction

Interactive Editor for canvas

This is the starting point of a project inspired by this talk https://www.youtube.com/watch?v=EGqwXt90ZqA

What's done

  • This is a prototype that doesn't currently work
  • currently we have a createSession function that creates a drawing session with a fake canvas context.
  • You write some canvas drawing code in code.js.txt and press run you'll have your frame recorded to play in a real canvas
  • Currently we record 1 frame
  • We could give user a real context and use drawImage on every frame and record that. But we want more inside info like which line of code draws what.

TODO

  • fake Date when running user script and record given ms of canvas
  • experiment, refactor, experiment, refactor...
  • add items to this todo :D

Some notes

We have ctx state on all function calls so we can alter canvas ctx while executing those calls on real canvas. An example code would look like this:

var drawFrame = function (frame, realContext) {
  _.each(frame.calls, function (call) {
    // currently call.ctx has methods but we'll change that to only store non-function fields

    // set ctx state to the exact state when that method called
    _.extend(realContext, call.ctx);

    // call given method on realContext with given arguments
    realContext[call.name].apply(realContext, call.args);
  });
};

We can observe user's custom code scope with this hack:

exports.___debug = function (code) {
  return new Function(code)();
};

We can add this function to any function's string and dive into that scope.

about hot swap

So far i could access and manipulate any variable i want from outside that scope using eval. So in theory if we parse and get a list of all variables in a scope we should be able to save their values and hot swap code and reassign those variables. This could work with 1 level of function but i think we can do anything if we analyze user's code and inject debug function's in appropriate places we can manipulate inner scopes too.

interactive-canvas's People

Contributors

yasinuslu avatar

Watchers

 avatar  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.