8

#codeVember #1/2021: pure CSS 3D morph cube ➜ cubocta ➜ octa

 2 years ago
source link: https://codepen.io/thebabydino/pen/bGroQOb
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

HTML (Pug)

HTML (Pug)

0 unsaved changes
xxxxxxxxxx
- let n6hedron = 6, n8hedron = 8;
- let m6hedron = .5*n6hedron;
- let m8hedron = .5*n8hedron;
- let dirs = ['i', 'j', 'k'];
.a3d
  .s3d.s6hedron(style=`--m: ${m6hedron}`)
    while m6hedron--
      .s2d.s4gon(style=`--${dirs[m6hedron]}: 1`)
  .s3d.s8hedron(style=`--m: ${m8hedron}`)
    while m8hedron--
      .s2d.s3gon(style=`--j: ${m8hedron - .5}`)

CSS (SCSS)

CSS (SCSS)

xxxxxxxxxx
@use 'sass:math';
@function b-angle($n) { @return 360deg/$n }
@function v-angle($n) { @return ($n - 2)*180deg/$n }
@function c-radius($l, $ba) { @return .5*$l/math.sin(.5*$ba) }
@function i-radius($l, $ba) { @return .5*$l/math.tan(.5*$ba) }
@function shape-2d($n: 3, $p: 0) {
  $q: calc(1 - #{$p});
  $ba: 360deg/$n;
  $oa: .5*(($n - 1)%2)*$ba - 90deg;
  $vx: ();
  $pl: ();
  @for $i from 0 to $n {
    $ca: $i*$ba + $oa;
    $vx: append($vx, 50%*(1 + math.cos($ca)) 50%*(1 + math.sin($ca)), comma)

JS (Babel)

JS (Babel)

xxxxxxxxxx

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK