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

              
                <link href="https://fonts.googleapis.com/css?family=Baloo+Bhai&display=swap" rel="stylesheet">
              
            
!

CSS

              
                // basic--------------------
$bg-color: #222;
$text-font: Georgia, "Times New Roman", Times, serif;
$text-color: #fff;

* {
  padding: 0;
  margin: 0;
}

body {
  background: $bg-color;
  width:100vw;
  height:100vh;
  min-width: 200px;
  min-height: 200px;
  overflow: hidden;
  font-family: $text-font;
  color: $text-color;
}
// ----------------------------
canvas {
  display: block;
  width: 100%;
  height: 100%;
  margin: auto;
}
              
            
!

JS

              
                let isDash = false

// set param
const param = {
  text: 'Ho!Ho!Ho!',
  speed: 10,
  grayscale: false,
  effect: 'Hop',
  dash: () => {
    isDash = true
  }
}

// set canvas
const TEXT_SPACE = 60
const JUMP_HEIGHT = 50
let center_x
let text_posX
let text_posY
let theta = 0
let dash = 0
let dashcount = 0
let opacity = 0

function setup() {
  createCanvas(windowWidth, windowHeight);
  frameRate(30)
  noStroke()
  textFont("Baloo Bhai")
}

function draw() {
  background(255)
  const textList = param.text.split('')
  center_x = (windowWidth - 50 * textList.length) / 2
  
  // dash animation
  if(isDash) {
    // dash animation
    text_posX += 0.0001
    dashcount += 1
    
    if(text_posX > windowWidth) {
      text_posX = 0
    }
    // reset frag
    if(dashcount > 10) {
      dashcount = 0
      isDash = false
    }
  } else {
    text_posX = center_x
  }
  
  // animation
  if(param.effect === 'Hop') {
    for (let i = 0; i < textList.length; i++) {
      theta += 0.05 * param.speed * 0.05
      text_posY = (windowHeight + 50) / 2 - abs(sin(theta) * JUMP_HEIGHT)
      text(textList[i], text_posX, text_posY);
      text_posX = text_posX + TEXT_SPACE
    }
    text_pos = 0
    
    // text color
    if(param.grayscale) {
      // Luminance(ref : https://ofo.jp/osakana/cgtips/hsb.phtml)
      let r = 0.298912 * 255
      let g = 0.586611 * 0
      let b = 0.586611 * 100
      fill(r, g, b);
    } else {
      fill(255, 0, 100);
    }
  } else if(param.effect === 'Appear') {
    text_posY = (windowHeight + 50) / 2
    for (let i = 0; i < textList.length; i++) {
      text(textList[i], text_posX, text_posY);
      text_posX = text_posX + TEXT_SPACE
    }
  
    // text color
    opacity += 0.1 * param.speed * 0.1
    if(param.grayscale) {
      // Luminance(ref : https://ofo.jp/osakana/cgtips/hsb.phtml)
      let r = 0.298912 * 255
      let g = 0.586611 * 0
      let b = 0.586611 * 100
      fill(r, g, b, abs(sin(opacity) * 100));
    } else {
      fill(255, 0, 100, abs(sin(opacity) * 100));
    }
  }
  
  textSize(100);
  textAlign(CENTER);
}

function windowResized() {
  resizeCanvas(windowWidth, windowHeight)
}

// set gui
const gui = new dat.GUI()
// 文字列で初期値を設定した場合、文字入力のGUIができる
gui.add(param, 'text')
// 数値で初期値を指定し、かつ最大値と最小値を指定した場合、スライダー付きの数値入力のGUIができる
gui.add(param, 'speed', 0, 20)
// Booleanで初期値を設定した場合、チェックボックスのGUIができる
gui.add(param, 'grayscale')
// 文字列で初期値を設定し、かつ配列を変数で指定した場合、セレクトボックスのGUIができる
gui.add(param, 'effect', ['Hop', 'Appear'])
// 関数入りオブジェクトを初期値に設定した場合、イベントを発生させるボタンのGUIができる
gui.add(param, 'dash')
              
            
!
999px

Console