cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              body{
  margin:0;
  padding: 0;
  position: absolute;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
            
          
!
            
              /* global SPF, TweenLite */

/*
===========
  Globals
===========
*/

// Graphics
var waveBar;
var bg;
var maskBG;
// var beatCircle;
var nameSplash;
var nameSmall;
var hey;
var waveLetters1 = [];
var waveLetters2 = [];

// Misc.
var newColor;
var maskActive = false;
var waveTxtCount1 = 0;
var waveTxtCount2 = 0;
var wave1BaseLine = 0;
var wave2Baseline = 0;
var mouseClickX = 0;
var mouseIsDown = false;
var oldSection = 'intro';
var heyColorLock = false;


// Config
var palettes = {
  15: [1, 3, 5, 6, 9, 11],
  13: [14, 11, 3, 16, 10, 12],
  10: [7, 8, 12, 13, 14, 15],
  1:  [5, 13, 14, 11, 15, 10],
  8:  [16, 17, 13, 6, 5, 10],
  7:  [8, 12, 15, 2, 5, 3],
};
var paletteNumbers = Object.keys(palettes);
var bgInt = Math.floor(Math.random() * paletteNumbers.length);
var bgColor = paletteNumbers[bgInt];

var heys = [59.7, 68.2, 128.2, 136.7, 179.5, 188.0, 196.8];
var heysModified = heys.map(function(h) {
  var newTime = h - 0.3;
  return Math.round(newTime * 10) / 10;
});
console.log(heysModified);

// Vælg random farve fra valgt palette
function pickColor(paletteID) {
  var palette = palettes[paletteID];
  var length = palette.length;
  var randomInt = Math.floor(Math.random() * length);
  return palette[randomInt];
}

function centerItem(item, input) {
  var itemW = item.width;
  var itemH = item.height;
  var conW  = input.width;
  var conH  = input.height;
  return [(conW / 2) - (itemW / 2), (conH / 2) - (itemH / 2)];
}

function splitFontWidth(fontArray, spacing) {
  var totalWidth = 0;
  for (var i = 0; i < fontArray.length; i += 1) {
    // lettter width
    totalWidth += fontArray[i].width;
    // spacing
    totalWidth += spacing - (fontArray[i].width / 2 );
  }

  return totalWidth;
}

/*
===========
  Baggrund
===========
*/

SPF.set({
  at: 'back',

  init: function(PIXI, input) {
    // BG fill
    bg = new PIXI.Graphics();
    bg.beginFill(input.colors[bgColor]);
    bg.drawRect(0,0, input.width, input.height);
    bg.endFill();
    input.container.addChild(bg);

    // HEY!
    hey = new PIXI.Text(
      'HEY!', {
        fontWeight: 'bold',
        fontSize: input.width / 3,
        fill: 'white',
      }
    );
    hey.alpha = 0;
    hey.anchor.set(0.5, 0.5);
    hey.position.set(input.width / 2, hey.height + input.height);
    hey.rotation = 75;
    input.container.addChild(hey);

  },
  render: function (PIXI, input) {
    if (mouseIsDown) {
      var currentX = input.mouseTouchPosition.x;
      var delta = mouseClickX - currentX;
      var divided = delta / (input.width * 0.05);

      if (divided <= -1 || divided >= 1) {
        var randomInt = Math.floor(Math.random() * paletteNumbers.length);
        bgColor = paletteNumbers[randomInt];
        bg.clear();
        bg.beginFill(input.colors[bgColor]);
        bg.drawRect(0,0, input.width, input.height);
        bg.endFill();
        mouseClickX = currentX;
      }
    }

    if (oldSection != input.currentSection.id) {
      oldSection = input.currentSection.id;
      var newInt = Math.floor(Math.random() * paletteNumbers.length);
      bgColor = paletteNumbers[newInt];
      bg.clear();
      bg.beginFill(input.colors[bgColor]);
      bg.drawRect(0,0, input.width, input.height);
      bg.endFill();
    }

    // HEY! show
    var currentTime1Decimal = Math.round(input.currentTime * 10) / 10;
    if (heysModified.includes(currentTime1Decimal)) {
      if (!heyColorLock) {
        heyColorLock = true;
        hey.style.fill = input.colors[pickColor(bgColor)];
      }
      TweenLite.to(hey, 0.3, {
        alpha: 1,
        y: input.height / 2,
      });
      var yHidden = hey.height + input.height;
      setTimeout(function() {
        TweenLite.to(hey, 0.85, {
          y: yHidden,
          ease: Power2.easeIn,
          alpha: 0,
        });
        heyColorLock = false;
      }, 500);
    }

  },

  resize: function(PIXI, input) {
    bg.clear();
    bg.beginFill(input.colors[bgColor]);
    bg.drawRect(0,0, input.width, input.height);
    bg.endFill();

    hey.style.fontSize = input.width / 3;
    hey.x = input.width / 2;
  },

  mouseDownTouchStart: function(PIXI, input) {
    mouseIsDown =  true;
    mouseClickX =  input.mouseTouchPosition.x;
  },
  mouseUpTouchEnd: function(PIXI, input) {
    mouseIsDown = false;
  }
});

/*
===========
  Forgrund
===========
*/

SPF.set({
  at: 'fore',

  init: function(PIXI, input) {
    // Color list
    // var squares = new PIXI.Graphics();
    // for (var i = 0; i < input.colors.length; i += 1) {
    //   squares.beginFill(input.colors[i]);
    //   squares.drawRect(0,(input.height - 35 * i), 35, 35);
    //   squares.endFill();
    // }
    // input.container.addChild(squares);

    nameSplash = new PIXI.Text(
      'SCARLET\nPLEASURE', {
        // fontFamily: 'Oswald',
        fontWeight: 'bold',
        fontSize: input.width * 0.1,
        fill: 'white',
        align: 'center',
      }
    );
    var xy = centerItem(nameSplash, input);
    nameSplash.anchor.set(0.5, 0.5);
    nameSplash.position.set(xy[0], xy[1]);
    input.container.addChild(nameSplash);

    nameSmall = new PIXI.Text(
      'SCARLET PLEASURE', {
        fontWeight: 'bold',
        fontSize: 30,
        fill: 'white',
        align: 'center',
      }
    );
    nameSmall.alpha = 0;
    nameSmall.anchor.set(0.5, 1);
    nameSmall.position.set(input.width / 2, input.height - 125);
    input.container.addChild(nameSmall);


    // RIDE THE WAVE - wAvE
    // Linje 1
    var line1 = 'RIDE THE';
    var line1Split = line1.split('');
    var txtSettings = {
      fontSize: 100,
      fontWeight: 'bold',
      fill: 'white',
      // align: 'center',
    };
    for (var l = 0; l < line1Split.length; l += 1) {
      var letter = new PIXI.Text(line1Split[l], txtSettings);
      letter.anchor.set(0.5,0.5);
      letter.position.y = input.height / 2;
      letter.alpha = 0;
      waveLetters1.push(letter);
      input.container.addChild(letter);
    }

    // Linje 2
    var line2 = 'WAVE';
    var line2Split = line2.split('');

    for (var l2 = 0; l2 < line2Split.length; l2 += 1) {
      var letter = new PIXI.Text(line2Split[l2], txtSettings);
      letter.anchor.set(0.5,0.5);
      letter.position.y = input.height / 2;
      letter.alpha = 0;
      waveLetters2.push(letter);
      input.container.addChild(letter);
    }
  },

  render: function(PIXI, input) {
    // Fjern nameSplash
    if (input.currentTime > 5.4) {
      if (nameSplash.alpha == 1) {
        TweenLite.to(nameSplash, 0.75, {alpha: 0});
      }
    // Tilføj nameSplash (...tilbage)
    } else {
      if (nameSplash.alpha == 0) {
        TweenLite.to(nameSplash, 0.25, {alpha: 1});
      }
    }

    // Tilføj Ride the wave hvis det er et i omkvæd
    // console.log(input.currentSection.id);
    if (input.currentSection.id.slice(0,6) == 'chorus' || input.percentagePlayed == 100)  {
      for (var i = 0; i < waveLetters1.length; i += 1) {
        waveLetters1[i].alpha = 1;
      }
      for (var i2 = 0; i2 < waveLetters2.length; i2 += 1) {
        waveLetters2[i2].alpha = 1;
      }
    } else {
      for (var i = 0; i < waveLetters1.length; i += 1) {
        waveLetters1[i].alpha = 0;
      }
      for (var i2 = 0; i2 < waveLetters2.length; i2 += 1) {
        waveLetters2[i2].alpha = 0;
      }
    }

    // The end Scene
    if (input.percentagePlayed == 100) {
      nameSmall.alpha = 1;
    } else {
      nameSmall.alpha = 0;
    }

    // Ride the Wave - line 1
    for (var i = 0; i < waveLetters1.length; i += 1) {
      // Speed
      waveTxtCount1 += 0.15 / waveLetters1.length;
      var yPos = (Math.sin((i * 2) + waveTxtCount1) * 15) + wave1BaseLine;
      // var yPos = 300;
      waveLetters1[i].y = yPos;
    }

    // Ride the Wave - line 2
    for (var i2 = 0; i2 < waveLetters2.length; i2 += 1) {
      // Speed
      waveTxtCount2 += 0.15 / waveLetters2.length;
      var yPos = (Math.sin((i2 * 2) + waveTxtCount2) * 15) + wave2Baseline;
      // var yPos = 300;
      waveLetters2[i2].y = yPos;
    }
  },

  resize: function(PIXI, input) {

    nameSmall.position.set(input.width / 2, input.height - 125);

    nameSplash.style.fontSize = input.width * 0.1;
    nameSplash.position.set(input.width / 2, input.height / 2);

    var fontSize = input.width / 15;
    var fontSpacing = fontSize * 1;

    var letters1Width = splitFontWidth(waveLetters1, fontSpacing);
    var firstLetter1X = (input.width / 2) - (letters1Width / 2);
    wave1BaseLine = (input.height / 2) - ((waveLetters2[0].height) - 50);
    // console.log(letters1Width, firstLetterX);
    for (var i = 0; i < waveLetters1.length; i += 1) {
      waveLetters1[i].style.fontSize = fontSize;
      // var xPos = (fontSpacing * i) + (waveLetters1[i].width / 2) + firstLetterX;
      waveLetters1[i].x = (fontSpacing * i) + firstLetter1X;
    }

    var letters2Width = splitFontWidth(waveLetters2, fontSpacing);
    var firstLetter2X = (input.width / 2) - (letters2Width / 2);
    wave2Baseline = wave1BaseLine + 50 + waveLetters1[0].height;
    // console.log(letters1Width, firstLetterX);
    for (var i = 0; i < waveLetters2.length; i += 1) {
      waveLetters2[i].style.fontSize = fontSize;
      // var xPos = (fontSpacing * i) + (waveLetters1[i].width / 2) + firstLetterX;
      waveLetters2[i].x = (fontSpacing * i) + firstLetter2X;
    }
  }
});

/*
===========
  Mellemgrund
===========
*/

SPF.set({
  at: 'mid',

  init: function(PIXI, input) {
    setInterval(function() {
      newColor = pickColor(bgColor);
    }, 2000);


    //Mask BG
    maskBG = new PIXI.Graphics();
    maskBG.beginFill(input.colors[pickColor(bgColor)]);
    maskBG.drawRect(0,0, input.width, input.height);
    maskBG.endFill();
    maskBG.alpha = 0;
    input.container.addChild(maskBG);

    // Wave bar
    waveBar = new PIXI.Graphics();
    input.container.addChild(waveBar);

  },

  render: function(PIXI, input) {

    // Wave Bar
    // var fq = input.audio.waveform();

    var fq = input.audio.frequencies();
    waveBar.clear();
    for (var i = 0; i < fq.length; i += 3) {
      waveBar.beginFill(input.colors[newColor]);
      waveBar.drawRect(i * 10, 0, 15, fq[i] * 3.25);

    }
    waveBar.endFill();

    // Masking
    if (input.editing.id == 'close' || input.editing.id == 'medium') {
      if (!maskActive) {
        maskActive = true;
        maskBG.clear();
        maskBG.beginFill(input.colors[pickColor(bgColor)]);
        maskBG.drawRect(0,0, input.width, input.height);
        maskBG.endFill();
      }
      maskBG.alpha = 1;
      SPF.midgroundMask(true);
    } else {
      maskActive = false;
      SPF.midgroundMask(false);
      maskBG.alpha = 0;
    }


  }
});


// Author info
SPF.info({
  debug: false,
  title: 'Drag the mouse to change color',
  tip: 'Jakob Lange - Scarlet Pleasure interactive video',
  firstName: 'Jakob',
  lastName: 'Lange',
  email: 'jblange@mail.dmjx.dk'
});

SPF.start();
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console