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

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

              
                 
              
            
!

CSS

              
                html {
  overflow: hidden;
}
body {
  width: 100vw;
  height: 100vh;
  padding: 0;
  margin: 0;
  position: relative;
}
#defaultCanvas0 {
  transform: translate(-50%, -50%);
  position: absolute;
  top: 50%;
  left: 50%;
}
              
            
!

JS

              
                // --- SETTINGS ------------------------------------
const BACKGROUND_COLOR = '#faf6ed'
const STROKE_WEIGHT = 2.5

const ANIMATE = false
// CHANGE is triggered once per animation cycle
// flips between true and false to trigger the grid display function
let CHANGE = false

const OFFSET = 50
const SPACING = 50
// -------------------------------------------------

function makeGrid(w, h, spacing, offset) {
  this.w = w;
  this.h = h;
  this.spacing = spacing;
  this.offset = offset;
  // Array of 'spaces' that could be filled
  this.grid = [];
  // Array based off grid that contains circles data
  this.circleArray = [];
  
  this.initGrid = function () {
    const rows = (this.w - (this.offset)) / this.spacing
    const columns = (this.h - (this.offset)) / this.spacing
    for (let x = 1; x < rows; x++) {
      row = []
      for (let y = 1; y < columns; y++) {
        row.push(1);
      }
      this.grid.push(row);
    }
    this.circleArray = [...this.grid]
  };

  this.generateCircles = function () {
    var SCHEME = new ColorScheme;
    SCHEME.from_hue(Math.floor(Math.random() * 360))
      .distance(0.1)
      .scheme('analogic')
      .variation('soft')
    const COLORS = SCHEME.colors()
    let currentColor = COLORS[Math.floor(random(COLORS.length - 1))]
    for (let i = 0; i < this.grid.length; i++) {
      for (let j = 0; j < this.grid[0].length; j++) {
        if (this.grid[i][j]) {
          let x, y, diameter, isFilled, color, rings, planet, planetOffset, itemRandom;

          x = i * this.spacing + this.offset;
          y = j * this.spacing + this.offset;

          const rando = Math.random();
          
          itemRandom = random(1)
          
          // Set Color
          // if (rando >= 0.95) {
          //   let newCol = COLORS[Math.floor(random(COLORS.length - 1))];
          //   if (currentColor) {
          //     while (newCol === currentColor) {
          //       newCol = COLORS[Math.floor(random(COLORS.length - 1))];
          //     }
          //   }
          //   currentColor = newCol
          // }
          // color = currentColor
          color = '000'
          
          // Set Fill
          if (rando <= 0.4) {
            isFilled = true
          } else {
            isFilled = false
          }
          
          diameter = Math.floor(rando * (SPACING - 3))
          
          // Set inner rings or dot
          rings = 0
          if (diameter > 15 && rando > 0.95) {
            rings = 3
          } else if (diameter > 10 && rando > 0.75) {
            rings = 2
          } else if (rando > 0.85) {
            rings = 1
          }
          
          planet = rando > 0.5
          planetOffset = rando * 360
         

          // Push to array of data points
          this.circleArray[i][j] = {x,y,diameter,isFilled,color,rings,increment: 0, planet, planetOffset, itemRandom}
        }
      }
    }
  }
}

function setup() {
  const wW = document.querySelector('body').clientWidth
  const wH = document.querySelector('body').clientHeight
  wx = wW;
  wy = wH;
  
  pixelDensity(1)
  createCanvas(wx, wy);
  
  g = new makeGrid(wx, wy, SPACING, OFFSET);
  g.initGrid();
  g.generateCircles();
  strokeWeight(STROKE_WEIGHT)
  
  if (ANIMATE) animate(g)
  else {
    g.circleArray.forEach((k) => {
      k.forEach((e) => {
        gsap.set(e, { increment: 1 })    
      })
    })
  }
}

function animate(g) {
  // ANIMATION
  const tl = gsap.timeline({ paused: true, repeat: -1, yoyo: true, onRepeat: () => CHANGE = true })
  .fromTo(g.circleArray,
          { increment: 0 },
          {
    increment: 1,
    duration: 0.5,
    stagger: {
      grid: [g.circleArray.length, g.circleArray[0].length],
      from: "center",
      amount: 1.5
    }
  })
  .to(g.circleArray,
      {
    increment: 0,
    duration: 0.5,
    stagger: {
      grid: [g.circleArray.length, g.circleArray[0].length],
      from: "center",
      amount: 1.5
    },
    delay: 1
  })
  // TODO: Make opacity fade between the regeneration
  // currently has ugly flash
  
  // .to(g.circleArray,
  //   {
  //     opacity: 0,
  //     duration: 0.5,
  //     stagger: {
  //       grid: [g.circleArray.length, g.circleArray[0].length],
  //       from: "center",
  //       amount: 1.5
  //     }
  //   }, '-=0.5')
  tl.play()
}

function draw() {
  background(BACKGROUND_COLOR);
  
  if (CHANGE && ANIMATE) {
     g.generateCircles();
     animate(g)
     CHANGE = false
  }
  // Generate circles based on generated data
  // Very ugly code!
  g.circleArray.forEach((k) => {
    k.forEach((e) => {
      if (e.isFilled) {
        fill('#' + e.color)
      } else {
        fill(BACKGROUND_COLOR)
      }
      stroke('#' + e.color)
      circle(e.x, e.y, e.diameter * e.increment)
      if (e.rings === 3) {
        circle(e.x, e.y, e.diameter * 0.666 * e.increment)
        circle(e.x, e.y, e.diameter * 0.333 * e.increment)
        fill('#' + e.color)
        circle(e.x, e.y, 2 * e.increment)  
        
        if (e.planet) {
          if(e.itemRandom <= 0.3) {
            circle(
              e.x + (e.diameter * 0.333 / 2) * Math.sin(e.planetOffset),
              e.y + (e.diameter * 0.333 / 2) * Math.cos(e.planetOffset),
              Math.round(5 - e.itemRandom) * e.increment
            )  
            e.planetOffset < 360 ? e.planetOffset += 0.01 : e.planetOffset = 0
          } else if (e.itemRandom < 0.6) {
             circle(
              e.x + (e.diameter * 0.666 / 2) * Math.sin(e.planetOffset),
              e.y + (e.diameter * 0.666 / 2) * Math.cos(e.planetOffset),
              Math.round(5 - e.itemRandom) * e.increment
            )  
            e.planetOffset < 360 ? e.planetOffset += 0.01 : e.planetOffset = 0           
          } else if (e.itemRandom < 0.9) {
             circle(
              e.x + (e.diameter / 2) * Math.sin(e.planetOffset),
              e.y + (e.diameter / 2) * Math.cos(e.planetOffset),
              Math.round(5 - e.itemRandom) * e.increment
            )  
            e.planetOffset < 360 ? e.planetOffset += 0.01 : e.planetOffset = 0           
          } else {
            circle(
              e.x + (e.diameter * 0.333 / 2) * Math.sin(e.planetOffset + e.itemRandom),
              e.y + (e.diameter * 0.333 / 2) * Math.cos(e.planetOffset + e.itemRandom),
              Math.round(5 - e.itemRandom) * e.increment
            )  
            circle(
              e.x + (e.diameter * 0.666 / 2) * Math.sin(e.planetOffset - e.itemRandom),
              e.y + (e.diameter * 0.666 / 2) * Math.cos(e.planetOffset - e.itemRandom),
              Math.round(5 - e.itemRandom) * e.increment
            )  
            circle(
              e.x + (e.diameter / 2) * Math.sin(e.planetOffset),
              e.y + (e.diameter / 2) * Math.cos(e.planetOffset),
              Math.round(5 - e.itemRandom) * e.increment
            )  
            e.planetOffset < 360 ? e.planetOffset += 0.01 : e.planetOffset = 0 
          }
        }
      }
      if (e.rings === 2) {
        circle(e.x, e.y, e.diameter * 0.5 * e.increment)
        fill('#' + e.color)
        circle(e.x, e.y, 2 * e.increment)  
        circle(
          e.x + (e.diameter / 2) * Math.sin(e.planetOffset),
          e.y + (e.diameter / 2) * Math.cos(e.planetOffset),
          Math.round(5 - e.itemRandom) * e.increment
        )  
        e.planetOffset < 360 ? e.planetOffset += 0.01 : e.planetOffset = 0 
      }
      if (e.rings === 1) {
        fill('#' + e.color)
        circle(e.x, e.y, 2 * e.increment)          
      }
    })
  })
 
  loadPixels();
  let noiseAmount = 100;

  for(var y = 0; y < height; y++) {
    for(var x = 0; x < width; x++) {
      var index = (x + y * width)*4;
      // pixels[index+0] = noise(x/100.0, y/100.0) * 255;
      // pixels[index+1] = 0;
      // pixels[index+2] = 180;
      // pixels[index+3] = 255;
      const thisNoise = (noise(x/10.0, y/10.0) - 0.5) * 255

      pixels[index] += Math.max(0, Math.min(noiseAmount - thisNoise, 255))
      pixels[index+1] += Math.max(0, Math.min(noiseAmount - thisNoise, 255))
      pixels[index+2] += Math.max(0, Math.min(noiseAmount - thisNoise, 255))
    }
  }
  updatePixels()
}

  
              
            
!
999px

Console