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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <input type="range" min="1" max="7" step="1" id="step" value="1">
<section>
  <p>Draw a circle</p>
  <p>Pick 6 evenly spaced points along the circle</p>
  <p>Draw circles from each point with the same radius</p>
  <p>Animate the radius of the inner circle</p>
  <p>Increase the amount of petals and hide the inner circle</p>
  <p>Use a different color for each petal</p>
  <p>Add even more petals and use a blend mode of type 'screen'</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);
  font-family: 'Montserrat', sans-serif;
  p {
    margin: 0;
  }
  @media (max-width: 500px) {
    font-size: 24px;
  }
}

code {
  white-space: nowrap;
}
              
            
!

JS

              
                let canvas;
let anim = { petalRadius: 0.5 };
console.clear();

/* ====== STEP 1 ====== */
function goToStep1 () {
  blendMode(SCREEN);
  noLoop();
  strokeWeight(2);
}

function step1 () {
  clear();
  noFill();
  stroke(255);
  const r = min(width, height) * 0.4;
  circle(width/2, height/2, r);
}

/* ====== STEP 2 ====== */
function goToStep2 () {
  blendMode(SCREEN);
  noLoop();
  strokeWeight(2);
}

function step2 () {
  clear();
  noFill();
  stroke(255);
  const r = min(width, height) * 0.4;
  circle(width/2, height/2, r);
  const petals = 6;
  for (let i = 0; i < petals; i++) {
    const x = sin(i / petals * TWO_PI) * (r * 0.5) + width / 2;
    const y = cos(i / petals * TWO_PI) * (r * 0.5) + height / 2;
    fill(255);
    circle(x, y, 10);
  }
}

/* ====== STEP 3 ====== */
let step3Index = 0;
function goToStep3 () {
  blendMode(SCREEN);
  loop();
  frameRate(1.5);
  step3Index = 0;
  strokeWeight(2);
}

function step3 () {
  clear();
  noFill();
  stroke(255);
  const r = min(width, height) * 0.4;
  circle(width/2, height/2, r);
  const petals = 6;
  for (let i = 0; i < petals; i++) {
    const x = sin(i / petals * TWO_PI) * (r * 0.5) + width / 2;
    const y = cos(i / petals * TWO_PI) * (r * 0.5) + height / 2;
    fill(255);
    circle(x, y, 10);
  }
  step3Index++;
  for (let i = 0; i < step3Index % (petals + 1); i++) {
    const x = sin(i / petals * TWO_PI) * (r * 0.5) + width / 2;
    const y = cos(i / petals * TWO_PI) * (r * 0.5) + height / 2;
    noFill();
    circle(x, y, r);
  }
}

/* ====== STEP 4 ====== */
function goToStep4 () {
  blendMode(SCREEN);
  loop();
  frameRate(60);
  gsap.killTweensOf(anim);
  anim.petalRadius = 0.5;
  gsap.to(anim, {
    duration: 3,
    petalRadius: 0,
    repeat: -1,
    yoyo: true,
    ease: 'power2.inOut'
  });
  strokeWeight(2);
}

function step4 () {
  clear();
  noFill();
  stroke(255);
  const r = min(width, height) * 0.4;
  const petals = 6;
  circle(width/2, height/2, r * anim.petalRadius * 2);
  for (let i = 0; i < petals; i++) {
    const x = sin(i / petals * TWO_PI) * (r * anim.petalRadius) + width / 2;
    const y = cos(i / petals * TWO_PI) * (r * anim.petalRadius) + height / 2;
    noFill();
    circle(x, y, r);
    fill(255);
    circle(x, y, 10);
  }
}

/* ====== STEP 5 ====== */
function goToStep5 () {
  blendMode(SCREEN);
  loop();
  frameRate(60);
  strokeWeight(2);
  gsap.killTweensOf(anim);
  anim.petalRadius = 0.5;
  gsap.to(anim, {
    duration: 3,
    petalRadius: 0,
    repeat: -1,
    yoyo: true,
    ease: 'power2.inOut'
  });
}

function step5 () {
  clear();
  noFill();
  stroke(255);
  const r = min(width, height) * 0.4;
  const petals = 16;
  for (let i = 0; i < petals; i++) {
    const x = sin(i / petals * TWO_PI) * (r * anim.petalRadius) + width / 2;
    const y = cos(i / petals * TWO_PI) * (r * anim.petalRadius) + height / 2;
    noFill();
    circle(x, y, r);
  }
}

/* ====== STEP 6 ====== */
function goToStep6 () {
  blendMode(BLEND);
  loop();
  frameRate(60);
  strokeWeight(2);
  colorMode(HSL);
}

function step6 () {
  clear();
  noFill();
  stroke(255);
  const r = min(width, height) * 0.4;
  const petals = 12;
  for (let i = 0; i < petals; i++) {
    const x = sin(i / petals * TWO_PI) * (r * anim.petalRadius) + width / 2;
    const y = cos(i / petals * TWO_PI) * (r * anim.petalRadius) + height / 2;
    noFill();
    stroke(i / petals * 360, 90, 50);
    circle(x, y, r);
  }
}

/* ====== STEP 7 ====== */
function goToStep7 () {
  loop();
  frameRate(60);
  strokeWeight(4);
  colorMode(HSL);
  blendMode(SCREEN);
  noFill();
}

function step7 () {
  clear();
  const r = min(width, height) * 0.4;
  const petals = 40;
  for (let i = 0; i < petals; i++) {
    const x = sin(i / petals * TWO_PI) * (r * anim.petalRadius) + width / 2;
    const y = cos(i / petals * TWO_PI) * (r * anim.petalRadius) + height / 2;
    noFill();
    stroke(i / petals * 360, 90, 50);
    circle(x, y, r);
  }
}

function setup () {
  canvas = createCanvas(windowWidth, windowHeight);
  
  windowResized();
  document.querySelector('#step').addEventListener('input', () => {
    if (window['goToStep' + step.value]) {
      window['goToStep' + step.value]();
    }
    draw();
  });
}

function windowResized () {
  resizeCanvas(windowWidth, windowHeight);
  
  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