Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <canvas id="canvas"></canvas>

              
            
!

CSS

              
                $body-bg :  #222;
$canvas-bg: #000;
$font1 : Arial, sans-serif;

body{
  background-color: $body-bg;
  font-family:$font1;
}
canvas{
  display:block;
  margin:0 auto;
  margin:calc(50vh - 150px) auto 0;
  background-color: $canvas-bg;
}
p{text-align:center;}
              
            
!

JS

              
                var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var c = {}
var cw = canvas.width = 300;
c.x = cw / 2;
var ch = canvas.height = 300;
c.y = ch / 2;

var rad = Math.PI / 180;

var frames = 0;

function Particula() {
  this.x = -this.r;
  this.y = -this.r;
  this.r = 15;

  this.historial = [];
  //define la longitud máxima del historial
  this.maxLongitudHistorial = this.r;

  this.dibujar = function() {
    ctx.fillStyle = "#6ab150";
   

    //Para cada posición del historial dibuja un nuevo circulo cuyo radio es 1+i
    for (var i = 0; i < this.historial.length; i++) {
      var pos = this.historial[i];
      ctx.beginPath();
      ctx.arc(pos.x, pos.y, 1 + i, 0, 2 * Math.PI);
      ctx.fill();
      //ctx.stroke();

    }
  }

  this.actualizar = function(momento, frames) { //53, 59, 61, 67 números primos!
    this.x = c.x + Math.cos(momento / 23 + Math.cos(momento / 29 + frames * rad)) * (c.x - 2 * this.r);
    this.y = c.y + Math.sin(momento / 31 + Math.cos(momento / 37 + frames * rad)) * (c.y - 2 * this.r);
// guarda la posición actual en un objeto
    var posicion = {
      x: this.x,
      y: this.y
    }
    // añade un nuevo objeto al final del array historial
    this.historial.push(posicion);
    // si el historial es más largo que this.maxLongitudHistorial tenemos que eliminar los elementos que sobran. 
    if (this.historial.length > this.maxLongitudHistorial) {
      // elimina un elemento situado al inicio del array
      this.historial.splice(0, 1)
    }
  }
}

particula = new Particula();
particula.dibujar();

function Animar() {
  elId = window.requestAnimationFrame(Animar);
  frames++;
  ctx.clearRect(0, 0, cw, ch);
  momento = new Date().getTime() / 30;
  particula.actualizar(momento, frames);
  particula.dibujar();
}

requestId = window.requestAnimationFrame(Animar);
              
            
!
999px

Console