Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Trigonometría Bella

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
Lupo Montero
September 25, 2020

Trigonometría Bella

LimaJS 25 Sep 2020

Lupo Montero

September 25, 2020

Transcript

22 slides
  1. const createCanvas = (width = 500) => { const canvas

    = Object.assign( document.createElement('canvas'), { width, height: width }, ); // ... return canvas; };
  2. const createCanvas = (width = 500) => { const canvas

    = document.createElement('canvas'); canvas.width = width; canvas.height = width; // ... return canvas; };
  3. const createCanvas = (width = 500) => { const canvas

    = Object.assign( document.createElement('canvas'), { width, height: width }, ); const update = (angle = 0) => { // Dibujar frame!! window.requestAnimationFrame(() => update(angle < 359 ? angle + 1 : 0)); }; update(); return canvas; };
  4. const createCanvas = (width = 500) => { const canvas

    = Object.assign( document.createElement('canvas'), { width, height: width }, ); const radius = width / 2; const center = { x: radius, y: radius }; const update = (angle = 0) => { // Dibujar frame!! window.requestAnimationFrame(() => update(angle < 359 ? angle + 1 : 0)); }; update(); return canvas; };
  5. const update = (angle = 0) => { const radians

    = angle * Math.PI / 180; const pointOnCircle = { x: center.x + Math.cos(radians) * radius, y: center.y + Math.sin(radians) * radius, }; // Dibujar frame!! window.requestAnimationFrame(() => update(angle < 359 ? angle + 1 : 0)); };
  6. const drawLine = (ctx, fromX, fromY, toX, toY) => {

    ctx.beginPath(); ctx.moveTo(fromX, fromY); ctx.lineTo(toX, toY); ctx.stroke(); };
  7. const drawCircle = (ctx, x, y, radius, color, stroke =

    true) => { ctx.beginPath(); ctx.arc(x, y, radius, 0, 2 * Math.PI); if (stroke) { ctx.stroke(); } if (color) { ctx.fillStyle = color; ctx.fill(); } };
  8. Links / Bibliografía • Demo • Código fuente • Beautiful

    Trigonometry - Numberphile • https://www.geogebra.org/m/S2W46Thv • https://en.wikipedia.org/wiki/Trammel_of_Archimedes • https://ee.stanford.edu/~hellman/playground/hyperspheres/radians.html • https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API
  9. Fin

More Decks by Lupo Montero

Other Decks in Programming