4 ms·
Show HN: A resource for drawing complex primitives in JavaScript
- tantalor 11y agoIs the author aware of https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D#Transformations https://developer.mozilla.org/en-US/docs/Web/API/CanvasRende...? Use rotate(), translate(), and scale() instead of doing your own math.
- MJSplot_author 11y agoYes, but this is as simple. It's not really my maths, it's quite standard stuff. I'm more excited about Path2D[0] becoming adopted by more browsers. [0] https://developer.mozilla.org/en-US/docs/Web/API/Path2D https://developer.mozilla.org/en-US/docs/Web/API/Path2D
- runemadsen 11y agoHere's a resource I made for Processing. Very similar. http://printingcode.runemadsen.com/lecture-form-2/ http://printingcode.runemadsen.com/lecture-form-2/
- tlb 11y agoIs it reliable to add methods to a built-in object like CanvasRenderingContext2D? I avoid it, but perhaps just out of superstition.
- makepanic 11y agoYou're right, extending the prototype of builtin objects is almost always a bad idea. See String.prototype.contains → String.prototype.includes because mootools extended the String prototype[1] [1] - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes#String.prototype.contains https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- MJSplot_author 11y agoIf you know what you are doing it's fine, but it might cause incompatibility issues from namespace collisions. You can rearrange the code to accept a context as the first argument if you are worried.
- aikah 11y agonice we need more lessons like this.
- artursapek 11y agoNice work. Very interesting. Canvas is such a fun API.
- Lerc 11y agoDo you mind if I add these to my own library? https://github.com/Lerc/whio https://github.com/Lerc/whio (MIT Licence) It's a library I use when I teach kids JavaScript. It provides simple global functions to let them get started before they have to deal with ideas such as canvas context objects. A Wiki page showing the functions they get to use is at http://fingswotidun.com/code/index.php/API http://fingswotidun.com/code/index.php/API The functions you show here are exactly the sort of thing that would be useful for beginners.
- MJSplot_author 11y agoGo for it!
- carterehsmith 11y agoNice, is that a LOGO programming language?