Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="./assets/css/app.css">
    <title>JS Lab - Joseph AZAR</title>
</head>
<body>
    <!-- <canvas id="canvas" height="600" hidpi="off"></canvas> 
     -->
    <div class="infos">
      <h1>Day 124 - 2 - Poisson</h1>
    </div>
</body>
</html>

              
            
!

CSS

              
                h1, h2 {
  font-family: Arial;
  font-size: 20px;    
  top:16px;
  left:20px;
  color: white;
  margin : 0;
}
p {
    color:white;
    font-size:16px;
}
a {
    text-decoration:none;
    color:white;
    text-decoration: underline;
}
/*************************/
// couleurs été
@vert: #2fa398;
@bleu: #0067ca;
@gris:#9881ab;
@rose:#d276a5;
@rouge:#8f1840;
@mauve:#b4387e;
@purple:#826bb1;
@sombre:#211b27;
// dégradés
@dark-radiant: linear-gradient(45deg, #171b26 0%,#283144 99%);
/** CANVAS **/
canvas {
    // background-color: #211b27;
    position: absolute;
    left: 0px;
    right: 0;
    margin: 0px;
    top:0px;
    z-index: 0;
    background-color: @sombre;
}
body {
  padding: 0;
  margin:0;
  position: relative;
  background-color: @sombre;
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: white;
}
.infos {
    position: absolute;
    z-index: 10;
    padding : 20px;
}
              
            
!

JS

              
                //creation du contexte 2D
w = window.innerWidth;
h = window.innerHeight;
var ctx = getContext(w, h);
var canvas = ctx.canvas;
document.body.appendChild(canvas);
canvas.width = w;
canvas.height = h;

let cx = w / 2;
let cy = h / 2;
let G = new Graphics(ctx);
let mousePoint = new Point(0, 0);
ctx.strokeStyle = "#9881ab";

/**
TUTOS de Nicolas BARRADEAU : 
YOUPI.IO
Exos dit du poisson
Ou comment placer des points de façon aléatoire, mais d'une façon plus 'aggloméré/Organique/Naturel"
Voir la page http://devmag.org.za/2009/05/03/poisson-disk-sampling/

   the points are tightly packed together; but
    no closer to each other than a specified minimum distance.



**/
var distribution // Tableau de Coordonnées (Point(x,y))

window.onload = function(){
  //computes a Poisson disc distribution
  distribution = getDistrib();
  draw();
} 


function draw() {
  requestAnimationFrame(draw)
  ctx.restore();
  ctx.save();
  ctx.clearRect(0, 0, w, h);
  ctx.fillStyle = "white";
  // on se met au centre de la page
 // ctx.translate(cx, cy);
  var count = (Math.sin(performance.now() * 0.003) * .5 + .5) * distribution.length;
  //G.text(count, 24,20,100)
  
  for (i = 0; i < count; i++) {
    ctx.globalAlpha = 1 - i / count;
    var p = distribution[i];
    G.disc(p, 1);
  }
  if(count < 1 ) {
    distribution = getDistrib();
  }
}
canvas.addEventListener('mousedown', function () { distribution = getDistrib(); });

function getDistrib() {
  return Poisson.distribute(30000, 4, w, h)
}
document.addEventListener("mousemove", e => {
  mousePoint.x = e.clientX;
  mousePoint.y = e.clientY;
});
              
            
!
999px

Console