JSFiddle - React, Tailwind, and code Playground

by kassiomaia

JavaScript

function times(min, max, step, fn) {
	const values = []
	for (var t = min; t <= max; t += step) {
  	values.push(fn(t))
  }
  return values
}

var Context = (function () {
	
  const canvas = document.createElement('canvas')
  canvas.width = 800
  canvas.height = 600
  
  document.body.appendChild(canvas)
  
  const context = canvas.getContext('2d')

	function circle(x, y, r) {
  	context.beginPath()
    context.ellipse(x, y, r, r, 0, 2 * Math.PI, false)
    context.fill()
    context.stroke()
    context.closePath()
  }
  
  return {
  	circle,
  }
}())

Context.circle(10, 10, 2)
Context.circle(100, 10, 2)
Context.circle(200, 10, 2)

console.log(times(-2, 2, 0.01, (t) => Math.cos(Math.PI * t)))