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 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

              
                <!-- 

You can also just go to:
http://evangelion.boodoo.co

-->

<div id="input-container">
  <div id="main-fields">
    <label for="topText">First Line</label>
      <input id="topText" type="text" value="neon">
    <br>
    <label for="midText">Second Line</label>
      <input id="midText" type="text" value="genesis">
    <br>
    <label for="botText">Third Line</label>
      <input id="botText" type="text" value="evangelion">
    <br>
    <label for="epText">"EPISODE"</label>
      <input id="epText" type="text" value="episode:12">
  </div>

  <div id="title-fields">
    <label for="titleText">Title Line</label>
      <textarea id="titleText" type="textarea">
She said,&quot;Don't make others suffer
for your personal hatred.&quot;</textarea>
    <br>
    <label for="titleStyle">Title Font</label>
      <select id="titleStyle">
        <option value="serif" selected>Serif</option>
        <option value="sans">Sans Serif</option>
      </select>
    <br>
    <label for="titleAlign">Title Aligned</label>
      <input id="titleAlign" type="text" value="left"
     list="alignments" />
      <datalist id="alignments">
        <option value="left">left</option>
        <option value="right">right</option>
        <option value="center">center</option>
      </datalist>
  </div>
  
  <button id="generate" onclick="event.preventDefault();draw(config(settings));">Generate!</button>
</div>
<canvas id="canvas" width="900" height="675"></canvas>
              
            
!

CSS

              
                body {
  font-family: Helvetica Neue, Helvetica, sans-serif;
  color: white;
  background-color: #111111;
}

input, textarea, select, button {
  font-weight: bold;
  color:white;
  background-color: black;
}

#input-container {
  padding-top: 1em;
  color: black;
  background-color: red;
  display: block;
  width: 900px;
  height: 7.5em;
}

#main-fields {
  display: inline-block;
  float: left;
  clear: all;
  padding-right:3em;
}

#title-fields {
  clear:all;
  float:left;
}

label {
  font-weight: bold;
  display: inline-block;
  width: 7em;
  vertical-align: top;
  padding-bottom:0.3em;
}

textarea {
  display: inline-block;
  width: 22em;
}

#generate {
  padding: 1em 2em;
  margin: 5em 1em 1em 1em;
  color: white;
  display:block;
  float:right;
}
              
            
!

JS

              
                let settings = {
  topText: `neon`,
  midText: `genesis`,
  botText: `evangelion`,
  epText: `EPISODE:12`,
  titleText:
`She said,"Don't make others suffer
for your personal hatred."`,
  titleStyle: `serif`, // sans
  titleAlign: 'left', // center, right, (or x value)
  aspectRatio: `standard` // wide
};

function config(settings) {

  // Read input fields:
  document.querySelectorAll('input,select,textarea').
  forEach(el=> {
    settings[el.id] = el.value || el.textContent; 
  });
  
  if (settings.aspectRatio == `wide`) {
    settings.canvasWidth = 1280;
    settings.canvasHeight = 720;
    settings.leftMargin = 115;
    settings.rightBoundary = 1150;
  } else {
    settings.canvasWidth = 900;
    settings.canvasHeight = 675;
    settings.leftMargin = 75;
    settings.rightBoundary = 815;
  }
  
  settings.smHeadSize = settings.canvasHeight * 0.184;
  settings.lgHeadSize = settings.canvasHeight * 0.308;
  settings.epSize = settings.canvasHeight * 0.095;
  settings.titleSize = settings.canvasHeight * 0.095;
  settings.maxWidth = settings.rightBoundary - settings.leftMargin;
  
  return settings;
}

function draw(config) {
  let can = document.getElementById('canvas'),
      ctx = can.getContext('2d');
  
  let topText = config.topText.toUpperCase(),
      midText = config.midText.toUpperCase(),
      botText = config.botText.toUpperCase(),
      epText = config.epText.toUpperCase(),
      titleText = config.titleText,
      titleStyle = config.titleStyle,
      titleAlign = config.titleAlign,
      leftMargin = config.leftMargin,
      rightBoundary = config.rightBoundary,
      smHeadSize = config.smHeadSize,
      lgHeadSize = config.lgHeadSize,
      epSize = config.epSize,
      titleSize = config.titleSize,
      // these all squash/condense the text horizontally
      topSquash = 0.62,
      midSquash = 0.62,
      botSquash = 0.57,
      epSquash = 0.76,
      titleSquash = 0.76;
  
  let addText = addFittedText.bind(null, ctx, config);

  // black background 
  // standard @ 900*675
  // wide @ 1280*720
  can.width = config.canvasWidth;
  can.height = config.canvasHeight;
  ctx.fillStyle = "#000000";
  ctx.fillRect(0, 0, can.width, can.height);

  // Drawing white text with white stroke
  ctx.fillStyle = "#FFFFFF";
  ctx.strokeStyle = "#FFFFFF";
  ctx.textBaseline = "top";
  // Top two lines
  ctx.font = `900 ${smHeadSize}px Times New Roman`;
  addText(topText, 50, topSquash);
  addText(midText, 150, midSquash);
  // Bigger third line
  ctx.font = `900 ${lgHeadSize}px Times New Roman`;
  addText(botText, 239, botSquash);

  // Change font for EPISODE: label
  ctx.font = `700 ${epSize}px Helvetica Neue,Helvetica,sans-serif`;
  addText(epText, 430, epSquash);
  
  // Change font for Title
  titleStyle = titleStyles[titleStyle];
  ctx.font = `${titleStyle.weight} ${titleSize}px ${titleStyle.family}`;
  addText(titleText, 530, titleStyle.squash, titleAlign); 
}

let titleStyles = {
  sans: {
    weight: 800,
    family: `Helvetica Neue,Helvetica,sans-serif`,
    squash: 0.8
  },
  serif: {
    weight: 600,
    family: `Times New Roman,serif`,
    squash: 0.76
  }
}

function addFittedText(ctx, config, text, y, squash=1, align='left', maxWidth=740) {
  let x; 
  
  if (align == "right") {
    ctx.textAlign = "right";
    x = config.rightBoundary;
  }
  else if (align == "left") {
    ctx.textAlign = "left";
    x = config.leftMargin
  }
  else if (align == "center") {
    ctx.textAlign = "center";
    x = (config.rightBoundary+config.leftMargin) / 2;
  }
  else {x = align}
  
  let toDraw = text.split('\n');
  if (toDraw.length > 1) {
    ctx.textBaseline = "middle";
  }
  for (let n in toDraw) {
    let mWidth = ctx.measureText('M').width;
    // Use maximum available space (if set)
    // or squashed width by ratio
    let widthCalc = ctx.measureText(toDraw[n]).width;
    if (widthCalc * squash >= maxWidth) {
      widthCalc = maxWidth;
    } else {
      widthCalc = widthCalc * squash;
    }
    // we're not stroking text for now, weird artifacts.
    // ctx.strokeText(toDraw[n], x, y+(n*mWidth), widthCalc);
    ctx.fillText(toDraw[n], x, y+(n*mWidth), widthCalc);
  }

  // reset to "reasonable" defaults
  ctx.textBaseline = "top";
  ctx.textAlign = "left";
}

draw(config(settings));
              
            
!
999px

Console