css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              .window
  // I know it's the macOS taskbar but I didn't bother changing it... consider it a linux skin :D
  .bar
    .buttons
      .button
      .button
      .button
    span.title root@kali: ~/Desktop
  .console
    .line root@kali:~$ gcc mandelbrot.c
    .mandelbrot
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Ubuntu+Mono');

html,
body {
  background: #141E30;  /* fallback for old browsers */
  background: -webkit-linear-gradient(to bottom, #243B55, #141E30);  /* Chrome 10-25, Safari 5.1-6 */
  background: linear-gradient(to bottom, #243B55, #141E30); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
  background: url(https://images.unsplash.com/photo-1520038569969-98da7959fcbd?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=92d803eff8b460c5a12d650db90e6149);
  background-size: cover;
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}

.window {
  display: block;
  overflow: auto;
  
  box-shadow: 0 .8em 1.5em rgba(51, 51, 51, .6),
    0 .5em 2em rgba(51, 51, 51, .6);
  
  width: 600px;
  height: 400px;
  background: rgba(#000, .75);
  
  // I know it's the macOS taskbar but I didn't bother changing it... consider it a linux skin :D
  .bar {
    padding: .5em;
    flex: 0 0 auto;
    display: flex;
    background: linear-gradient(to bottom, #eaeaea, #d2d2d2);
    border-bottom: 1px solid #7d7d7d;
    color: #4c4c4c;

    .title {
      margin: 0;
      display: inline-block;
      flex: 1 1 auto;
      line-height: 1;
      font-family: 'Helvetica Neue', 'Helvetica', 'Lucida Grande', 'Lucida', 'Arial';
      text-align: center;
    }

    .buttons {
      display: inline-block;
      flex: 0 0 auto;

      .button {
        margin: 0 .5em 0 0;
        height: 1em;
        width: 1em;
        display: inline-block;
        float: left;
        border-radius: 50%;
        box-shadow: inset 0 0 .1em rgba(51, 51, 51, .4);

        &:nth-child(1) {
          position: relative;
          background: #fe6058;
          &::after {
            width: .35em;
            height: .35em;
            display: block;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            border-radius: 50%;
            background: #4c0000;
            content: '';
          }
        }
        &:nth-child(2) {
          background: #fdbd34;
        }
        &:nth-child(3) {
          background: #23c944;
        }
      }
    }
  }
  .console {
    padding: 1em;
    box-sizing: border-box;
    color: #f9f9f9;
    font-size: 1.5em;
    font-family: 'Ubuntu Mono', monospace;
    line-height: 1;
    .line { display: block; }
    .mandelbrot {
      white-space: pre;
      line-height: .5;
    }
  }
}
            
          
!
            
              /**
 * Generate the mandelbrot set data
 */ 

let mandelbrot = [];

const maxiter = 100,
      radius = 2,
      xmin = -2,
      xmax = 1,
      ymin = -1,
      ymax = 1,
      res = 0.085;

let width = Math.round(Math.abs(xmax-xmin) / res),
    height = Math.round(Math.abs(ymax-ymin) / res);

let za, zb; // z_0 of the Mandelbrot set
let x, y; // x and y position on the complex plane

// _x and _y represent pixels on the canvas
for (_y=0; _y<height; _y++) {
  mandelbrot[_y] = [];
  for (_x=0; _x<width; _x++) {
    // Map _x between 0, c.width and xmin, xmax ; same for y
    x = (_x-0)/(width-0)*(xmax-xmin)+xmin;
    y = (_y-0)/(height-0)*(ymax-ymin)+ymin;
    za = 0;
    zb = 0;
    // Convergence test
    for (i=0; i<maxiter; i++) {
      // Temporary za
      _za = za*za - zb*zb + x;
      zb = 2*za*zb + y;
      za = _za;
      // Optimization
      if (za*za + zb*zb > radius*radius) break;
    }
    if (i === maxiter) {
      // Point belongs to set
      mandelbrot[_y][_x] = 1;
    } else {
      mandelbrot[_y][_x] = 0;
    }
  }
}

/**
 * So now our mandelbrot data is ready to rock, let's render it in text
 */

const charfull = '*', // <--- Change the "white pixel"
      charwhite = ' ', // <--- Change the "black pixel"
      asciiplot = document.getElementsByClassName('mandelbrot')[0],
      speed = 2; // <--- Change to adjust rendering effect

let line;
y=0, x=0;

// We simulate a double for loop
renderinterval = setInterval(function() {
  // End of line
  if (x === width) {
    // Reset loop
    x = 0;
    y++;
    if (y === height) {
      clearInterval(renderinterval);
      return;
    }
  }
  
  // New line
  if (x === 0) {
    // Create new line
    line = document.createElement('div');
    line.classList.add('line');
    line.innerHTML = '';
    asciiplot.appendChild(line);
  }
  
  // Draw character
  if (mandelbrot[y][x] === 1) line.innerHTML += charfull;
  else line.innerHTML += charwhite;
  
  x++;
}, speed);

// for (let y=0; y<height; y++) {
//   line = document.createElement('div');
//   line.classList.add('line');
//   line.innerHTML = '';
//   for (let x=0; x<width; x++) {
//     if (mandelbrot[y][x] === 1) line.innerHTML += char;
//     else line.innerHTML += ' ';
//   }
//   asciiplot.appendChild(line);
// }
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console