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

              
                - const points = Array(361).fill(null).map(() => '50,50').join(' ')

svg(xmlns="http://www.w3.org/2000/svg", viewBox="0 0 100 100")
  polyline#inner(points=points, fill="none")
  polyline#outer(points=points, fill="none")


              
            
!

CSS

              
                :root,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background-color: var(--color-background);
  color: var(--color-line);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  margin: 0 auto;
  font-family: sans-serif;
}

svg {
  max-width: 90vmin;
  overflow: visible;
  shape-rendering: geometricprecision;
  stroke-linejoin: round;
}

#outer {
  stroke-width: var(--stroke-width-border, 0.4);
  stroke: var(--color-border);
}

#inner {
  stroke-width: var(--stroke-width-line, 0.2);
  stroke: var(--color-line);
}

              
            
!

JS

              
                const duration = 0.25;
const ease = "power2";

gsap.registerPlugin(MorphSVGPlugin);

const svg = document.querySelector("svg");

let n = 2;
let d = 29;

const knobSettings = {
  knobsToggle: false,
  visible: 0,
  CSSVarTarget: document.documentElement,
  knobs: [
    "Rose Parameters",
    {
      label: "Amigos íntimos",
      type: "number",
      value: n,
      min: 2,
      step: 1,
      onChange: (e) => (n = Number(e.target.value)) && morph()
    },
    {
      label: "Amigos",
      type: "number",
      value: d,
      min: 1,
      step: 0.1,
      onChange: (e) => (d = Number(e.target.value)) && morph()
    },
    "Styles",
    {
      label: "Constancia",
      type: "checkbox",
      checked: true,
      onChange: (e) => {
        let opacity = e.target.checked ? 1 : 0;
        gsap.to("#outer", { opacity, duration, ease });
      }
    },
    {
      cssVar: ["stroke-width-border"], // alias for the CSS variable
      label: "Constancia",
      type: "number",
      min: 0,
      max: 10,
      step: 0.01,
      value: 0.4
    },
    {
      cssVar: ["stroke-width-line"], // alias for the CSS variable
      label: "Tiempo social",
      type: "number",
      min: 0,
      max: 10,
      step: 0.01,
      value: 0.2
    },
    {
      cssVar: ["color-background"], // alias for the CSS variable
      label: "Color de fondo",
      type: "color",
      value: "#fbfbfb"
    },
    {
      cssVar: ["color-border"], // alias for the CSS variable
      label: "Color favorito",
      type: "color",
      value: "#2D3047"
    },
    {
      cssVar: ["color-line"], // alias for the CSS variable
      label: "Color favorito del amigo más cercano",
      type: "color",
      value: "#2D3047"
    }
  ]
};

const knobs = new Knobs(knobSettings);

function degToRad(deg) {
  return deg * (Math.PI / 180);
}

function generatePoint(i, factor) {
  let k = i * factor;
  let r = 50 * Math.sin(degToRad(k * n));
  let x = Math.sin(degToRad(k)) * r;
  let y = Math.cos(degToRad(k)) * r;

  return [x + 50, 50 - y];
}

function generatePoints() {
  const inner = [];
  const outer = [];

  for (let i = 0; i < 361; i++) {
    inner.push(generatePoint(i, d));
    outer.push(generatePoint(i, 1));
  }

  return { inner, outer };
}

function formatPoints(points = []) {
  return points.map((point) => point.join(",")).join(" ");
}

function morph() {
  const { inner, outer } = generatePoints();
  gsap.to("#inner", { morphSVG: formatPoints(inner), duration, ease });
  gsap.to("#outer", { morphSVG: formatPoints(outer), duration, ease });
}

morph();

setTimeout(knobs.toggle.bind(knobs), 500);

              
            
!
999px

Console