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

              
                figure
  .figure-content
      
    .element-info
      .initials
        span.text-color [
        span Kr
        span.text-color ]
        
      .name Kripton
        sup.text-fade 36
        
      .latin.text-fade Krypton
  
    #Atom
      .nucleus
      .electrospheres
  

script.
  window.addEventListener('load', () => {
    kripton = new Atom(36)
    
    function renderElectronicLayers(selector, atom)
  {
    const element = document.querySelector(selector)
    const html = document.createElement('div')

    for(const index in atom.electronicDiagram)
    {
      const layer = atom.electronicDiagram[index]
      const layerLength = atom.shells[index]
      const electrosphere = document.createElement('div')

      electrosphere.classList.add('electrosphere', `layer-${index}`)

      if(layerLength)
        electrosphere.style.setProperty('--length', layerLength)
      else
        electrosphere.classList.add('empty-layer')

      for(let i = 0; i < layerLength; i++)
      {
        const electron = document.createElement('div')

        electron.classList.add('electron')
        electron.style.setProperty('--index', i)
        electrosphere.appendChild(electron)
      }

      html.appendChild(electrosphere)
    }

    element.innerHTML = html.innerHTML
  }
    
    renderElectronicLayers("#Atom .electrospheres", kripton)
  })


              
            
!

CSS

              
                .figure-content
  overflow: hidden
  background-color: #212121
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='49' viewBox='0 0 28 49'%3E%3Cg fill-rule='evenodd'%3E%3Cg fill='%23242424' fill-rule='nonzero'%3E%3Cpath d='M13.99 9.25l13 7.5v15l-13 7.5L1 31.75v-15l12.99-7.5zM3 17.9v12.7l10.99 6.34 11-6.35V17.9l-11-6.34L3 17.9zM0 15l12.98-7.5V0h-2v6.35L0 12.69v2.3zm0 18.5L12.98 41v8h-2v-6.85L0 35.81v-2.3zM15 0v7.5L27.99 15H28v-2.31h-.01L17 6.35V0h-2zm0 49v-8l12.99-7.5H28v2.31h-.01L17 42.15V49h-2z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E")

.element-info
  position: absolute
  margin: 15px 0 0 20px
  color: #FFF
  font-size: 24px

  .text-color
    color: #09F

  .text-fade
    color: #9E9E9E

  .initials
    font-size: 2em
    font-weight: bold

  .name
    margin-top: 5px
    font-size: 1em

  .latin
    font-size: .8em
    font-style: italic

#Atom
  width: 300px
  height: 300px
  margin: 25px 0 0 200px
  display: flex
  justify-content: center
  align-items: center

.electrospheres
  width: 300px
  height: 300px
  display: flex
  justify-content: center
  align-items: center


.electrosphere
  border: 2px solid #757575
  border-radius: 50%
  animation: 60s infinite linear

  &:nth-child(odd)
    animation-name: rotateA

  &:nth-child(even)
    animation-name: rotateB


  @keyframes rotateA
    from
      transform: rotate(360deg)

  @keyframes rotateB
    from
      transform: rotate(-360deg)

  @for $i from 0 through 6
    &.layer-#{$i}
      width: 90px + 35px * $i
      height: 90px + 35px * $i
      position: absolute

      &.empty-layer
        opacity: 1.9 - .3 * $i

.electron
  width: calc(100% + 2px)
  height: calc(100% + 2px)
  margin: -1px
  position: absolute
  text-align: center
  transform: rotate(calc(360deg * var(--index) / var(--length)))

  &::after
    content: ''
    width: 10px
    height: 10px
    margin: -8px
    border-radius: 50%
    border: 3px solid #212121
    background-color: #09F
    position: absolute

.nucleus
  width: 40px
  height: 40px
  background-color: #09F
  border-radius: 50%
  box-shadow: 0 0 100px 50px #242424
  position: absolute


// Page layout 📰

body
  height: 100vh
  background: #111
  // font-family: 'Roboto', sans-serif
  overflow: hidden
  display: flex
  flex-direction: column
  justify-content: center
  align-items: center
  
.figure-content
  width: 600px
  height: 350px
  border: 1px solid #222
  border-radius: 2px
  user-select: none
  cursor: default

              
            
!

JS

              
                class Atom
{
  constructor (atomic)
  {
    this.atomic = atomic
    
    this.buildElectronicDiagram()
    this.distributeElectrons()
  }
    
  // Creates a non-linear 2D array as the Aufbau principle
  // to later distribute the values over the structure.
  // This generates an array with the following aspect:
  //          S  P  D  F
  //  1(K) - [0] :  :  :
  //  2(L) - [0, 0] :  :
  //  3(M) - [0, 0, 0] :
  //  4(N) - [0, 0, 0, 0]
  //  5(O) - [0, 0, 0, 0]
  //  6(P) - [0, 0, 0] :
  //  7(Q) - [0, 0] :  :
  buildElectronicDiagram ()
  {
    // Definition of the matrix with 7 lines,
    // followed by an compreension loop that will
    // define the number of columns of each line.
    this.electronicDiagram = new Array(7)
      .fill()
      .map((_, x) =>
      {
        // Variable that determines the number of columns of each row.
        // f(x) = 4.5 -|x - 3.5|
        // (0 <= x <= 6) {1, 2, 3, 4, 4, 3, 2}
        const length = 4.5 - Math.abs(x - 3.5)
        
        return new Array(length).fill(0)
      })
  }
  
  distributeElectrons ()
  {
    // Variable that records the count of electrons.
    let electrons = this.atomic
    
    // Variables that selects the row(layer) and column(sublevel)
    // from the starting point of each step.
    let layer = 0
    let sublevel = 0
    
    // Loop that performs the distribution process
    // until all electrons have been distributed.
    while(electrons > 0)
    {
      // Variables that select the row(x) and column(y) of the array.
      let x = layer
      let y = sublevel
      
      // Loop that shifts the iteration pointer from the array,
      // from the starting point and moving to the previous column
      // of the next line, as a diagonal move, until you reach column 0 or line 6.
      for(; y >= 0 && x <= 6; x++, y--)
      {
        // Variable that defines a limit of electrons
        // that can be iterated in certain point of the matrix,
        // influenced by the pointed column(y)...
        // f(x) = 4x + 2
        // (0 <= x <= 3) {2, 6, 10, 14}
        const maxDecay = 2 + 4 * y
        
        // If the number of electrons is lower than the column boundary,
        // the decay will be the total number of electrons.
        const decay = Math.min(electrons, maxDecay)
        
        this.electronicDiagram[x][y] = decay
        electrons -= decay
      }
      
      // It makes the offset of the starting point alternating in each step
      // between moving to the next line and moving to the next column.
      if(layer === sublevel) layer++
      else sublevel++
    }
  }
  
  // Returns the total number of electrons disposed in each layer.
  get shells ()
  {
    const result = []
    
    this.electronicDiagram.forEach((layer) =>
    {
      const total = layer.reduce((a, b) => a + b)
      
      result.push(total)
    })
    
    return result
  }
}

              
            
!
999px

Console