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

              
                <input type="range" min="1" max="9" step="1" id="step" value="1">
<section>
  <p>Divide your canvas into a grid of squares</p>
  <p>For every square, get a noise value from its coordinates</p>
  <p>Use that noise value to define the brightness of the square</p>
  <p>Draw a line in the center of every square</p>
  <p>Hide the squares and rotate the lines based on the noise value</p>
  <p>Fade out each line from its angle</p>
  <p>Reduce the scale of your grid</p>
  <p>Update the noise values from the frame count to animate your scene</p>
  <p>Be creative</p>
</section>

              
            
!

CSS

              
                body {
  margin: 0;
  overflow: hidden;
  display: flex;
  height: 100vh;
  background: black;
}
canvas {
  margin: auto;
  touch-action: none;
}

@mixin track {
  box-sizing: border-box;
  height: 6px;
	background: #fff;
  -webkit-appearance: none;
  appearance: none;
}

@mixin thumb {
  box-sizing: border-box;
	width: 30px;
  height: 30px;
	border-radius: 50%;
	background: #fff;
  border: 2px solid black;
  -webkit-appearance: none;
  appearance: none;
  cursor: grab;
}

input {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  width: 80%;
  height: 34px;
  max-width: 400px;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  &:active {
    cursor: grabbing;
  }
  &::-webkit-slider-runnable-track {@include track }
	&::-moz-range-track { @include track }
	&::-ms-track { @include track }
  
  &::-webkit-slider-thumb {margin-top: -12px;@include thumb}
	&::-moz-range-thumb { @include thumb }
  &::-ms-thumb {margin-top:0px;@include thumb}
}

section {
  box-sizing: border-box;
  font-size: 30px;
  color: white;
  position: fixed;
  left: 0;
  top: 20px;
  width: 100%;
  text-align: center;
  padding: 10px 10%;
  z-index: 10;
  pointer-events: none;
  text-shadow: 0 0 3px black, 0 0 4px black, 0 0 5px black;
  background: rgba(0, 0, 0, 0.7);
  p {
    margin: 0;
  }
  @media (max-width: 500px) {
    font-size: 24px;
  }
}
              
            
!

JS

              
                // Overwrite P5 native noise function with an external one
const _noise = noise;

let detail = 20;
let lineLength = 30;
let ctx;
let lines = [];

/* ====== STEP 1 ====== */
function step1 () {
  clear();
  noLoop();
  fill(0);
  stroke(150);
  detail = 42;
  for (let y = 0; y < height; y+=detail) {
    for (let x = 0; x < width; x+=detail) {
      rect(x + 0.5, y + 0.5, detail, detail);
    }
  }
}

/* ====== STEP 2 ====== */
function step2 () {
  clear();
  noLoop();
  stroke(150);
  textAlign(CENTER, CENTER);
  textSize(12);
  textFont('Courier New')
  detail = 42;
  for (let y = 0; y < height; y+=detail) {
    for (let x = 0; x < width; x+=detail) {
      fill(0);
      rect(x + 0.5, y + 0.5, detail, detail);
      const noiseValue = _noise.simplex2(x * 0.002, y * 0.002);
      fill(255);
      text(round(noiseValue * 100) / 100, x + (detail / 2), y + (detail / 2));
    }
  }
}

/* ====== STEP 3 ====== */
function step3 () {
  clear();
  noLoop();
  fill(0);
  stroke(150);
  detail = 42;
  for (let y = 0; y < height; y+=detail) {
    for (let x = 0; x < width; x+=detail) {
      const noiseValue = _noise.simplex2(x * 0.002, y * 0.002);
      fill(map(noiseValue, -1, 1, 0, 255));
      rect(x + 0.5, y + 0.5, detail, detail);
    }
  }
}

/* ====== STEP 4 ====== */
function step4 () {
  clear();
  noLoop();
  fill(0);
  detail = 42;
  for (let y = 0; y < height; y+=detail) {
    for (let x = 0; x < width; x+=detail) {
      const noiseValue = _noise.simplex2(x * 0.002, y * 0.002);
      fill(map(noiseValue, -1, 1, 0, 255));
      translate(x, y);
      stroke(150);
      rect(0.5, 0.5, detail, detail);
      translate(detail / 2, detail / 2);
      stroke(255);
      line(-lineLength * 0.5, 0, lineLength * 0.5, 0);
      resetMatrix();
    }
  }
}

/* ====== STEP 5 ====== */
function step5 () {
  clear();
  noLoop();
  stroke(255);
  detail = 42;
  for (let y = 0; y < height; y+=detail) {
    for (let x = 0; x < width; x+=detail) {
      const noiseValue = _noise.simplex2(x * 0.002, y * 0.002);
      translate(x + detail / 2, y + detail / 2);
      rotate(map(noiseValue, -1, 1, 0, TWO_PI));
      line(-lineLength * 0.5, 0, lineLength * 0.5, 0);
      resetMatrix();
    }
  }
}

/* ====== STEP 6 ====== */
function step6 () {
  clear();
  noLoop();
  stroke(255);
  detail = 42;
  for (let y = 0; y < height; y+=detail) {
    for (let x = 0; x < width; x+=detail) {
      const noiseValue = _noise.simplex2(x * 0.002, y * 0.002);
      translate(x + detail / 2, y + detail / 2);
      rotate(map(noiseValue, -1, 1, 0, TWO_PI));
      stroke(map(noiseValue, -1, 1, 0, 255));
      line(-lineLength * 0.5, 0, lineLength * 0.5, 0);
      resetMatrix();
    }
  }
}

/* ====== STEP 7 ====== */
function step7 () {
  noLoop();
  clear();
  detail = 20;
  ctx.globalAlpha = 1;
  for (let y = 0; y < height; y+=detail) {
    for (let x = 0; x < width; x+=detail) {
      const noiseValue = _noise.simplex2(x * 0.002, y * 0.002);
      translate(x + detail / 2, y + detail / 2);
      rotate(map(noiseValue, -1, 1, 0, TWO_PI));
      stroke(map(noiseValue, -1, 1, 0, 255));
      line(-lineLength * 0.5, 0, lineLength * 0.5, 0);
      resetMatrix();
    }
  }
}

/* ====== STEP 8 ====== */
function goToStep8 () {
  loop();
  stroke(255);
  detail = 24;
  lineLength = 36;
  lines = [];
  strokeWeight(2);
  blendMode(BLEND);
  ctx.strokeStyle = 'white';
  
  for (let y = 0; y < height; y += detail) {
    for (let x = 0; x < width; x += detail) {
      lines.push(new Line(x, y));
    }
  }
}

function step8 () {
  clear();
  lines.forEach(l => l.draw());
}

/* ====== STEP 9 ====== */
function goToStep9 () {
  loop();
  stroke(255);
  detail = 24;
  lineLength = 120;
  lines = [];
  ctx.globalAlpha = 1;
  strokeWeight(4);
  blendMode(SCREEN);
  
  for (let y = 0; y < height; y += detail) {
    for (let x = 0; x < width; x += detail) {
      lines.push(new Line(x, y, true));
    }
  }
}

function step9 () {
  clear();
  lines.forEach(l => l.draw(true));
}

class Line {
  constructor (x, y, crazy) {
    this.x = x;
    this.y = y;
    this._x = this.x * 0.002;
    this._y = this.y * 0.002;
  }
  draw (crazy) {
    const noiseValue = _noise.simplex3(this._x, this._y, frameCount * 0.008);
    ctx.translate(this.x + detail / 2, this.y + detail / 2);
    ctx.rotate(map(noiseValue, -1, 1, 0, TWO_PI));
    if (crazy) {
      ctx.strokeStyle = `hsl(${map(noiseValue, -1, 1, 0, 360)}, 70%, 50%)`;
    } else{
      ctx.globalAlpha = map(noiseValue, -1, 1, 0, 1);
    }
    line(-lineLength * 0.5, 0, lineLength * 0.5, 0);
    ctx.setTransform(1, 0, 0, 1, 0, 0);
  }
}

function setup () {
  const canvas = createCanvas(windowWidth, windowHeight);
  ctx = canvas.canvas.getContext('2d');
  
  pixelDensity(1);
  strokeWeight(2);
  
  windowResized();
  document.querySelector('#step').addEventListener('input', () => {
    if (window['goToStep' + step.value]) {
      window['goToStep' + step.value]();
    }
    draw();
  });
}

function windowResized () {
  resizeCanvas(windowWidth, windowHeight);
  
  noiseSeed(random(100));
  if (window['goToStep' + step.value]) {
    window['goToStep' + step.value]();
  }
  draw();
}

const texts = document.querySelectorAll('section p');
function draw () {
  window['step' + step.value]();
  
  texts.forEach(text => text.style.display = 'none');
  texts[step.value - 1].style.display = 'block';
}

              
            
!
999px

Console