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 variables
var instructtext
var rect
var circle
var rects = [];
var background
var rectSize = 100;
var rectDist = 20;
var rect_bottom

//set-start
SPF.set({
  at: 'back',
  
//load function start:
  load: function(PIXI, input) {
    return [];
  },

//init function start  
  init: function(PIXI, input) {
   
//draw background
    background = new PIXI.Graphics();
    background.beginFill(0xffffff);
    background.drawRect(0, 0, input.width, input.height);
    background.endFill();
    input.container.addChild(background);
   
//draw squares on background
    var i = 0;
    for(var y = 0; y<input.height; y+= rectSize + rectDist){
      for(var x = 0; x<input.width; x+= rectSize + rectDist){  
        rect = new PIXI.Graphics();
        rect.beginFill(input.colors[9]);
        rect.beginFill(input.colors[i % input.colors.length]);
        rect.drawRect(-rectSize/2, -rectSize/2, rectSize, rectSize);   
        rect.x = x + rectSize/2;
        rect.y = y + rectSize/2;
        rect.endFill();
        input.container.addChild(rect);
        i += 1;
        rects.push(rect);        
      }
    }    
  },
   
//resizing background
    resize: function (PIXI, input) {
      background.clear();
      background.beginFill(0xffffff);
      background.drawRect(0, 0, input.width, input.height);
      background.endFill();
  },
    
//random colors for squares by mouse touch 
    mouseDownTouchStart: function(PIXI, input) {
    
//variables for background square colors 
   var myRect;
   var w;
   var h;
   var color;
      
//draw new colors to squares when mouse touch down      
    for (var i = 0; i < rects.length; i++) {
      color = input.colors[Math.floor(Math.random() * input.colors.length)];
      myRect = rects[i];
      w = myRect.width;
      h = myRect.height;
      myRect.clear();
      myRect.beginFill(color);
      myRect.drawRect(-w/2, -h/2, w, h);
      myRect.endFill();
    }
  },

//render function start
  render: function(PIXI, input) {
     
//rotating rectangles with mouse
    var r 
    var myRect;
    for (var i = 0; i < rects.length; i++) {
      myRect = rects[i];
      r = input.mouseTouchPosition.x/500
      myRect.rotation = r
      myRect.scale.x = myRect.scale.y = 0.3 + input.mouseTouchPosition.y/700
          
//audio reactive rectangles
      var v = input.audio.frequencies()[600];
        myRect.alpha = v / 180;   
    }  
  }  
});

//variables for foreground
var text
var imageSprite

SPF.set({   
  at: 'fore',
  
//init function start  
  init: function(PIXI, input) {
    
    
//adding bottom sprite    
    var texture = PIXI.Texture.fromImage('https://lh3.googleusercontent.com/p55pQyUZeR9JKYp-AocXlTC5n0djOWJ9UJonNme_wvvasVyGM0eiK02oQCp0I-idyfR1fVOWifiCygY=w2560-h1316-rw');
    imageSprite = new PIXI.Sprite(texture);  
    input.container.addChild(imageSprite);
    //imageSprite.y = 400;
    console.log(input.height - imageSprite.height);
    imageSprite.y = (input.height / 2) - imageSprite.height;
    
//adding text    
    text = new PIXI.Text('move and click your\n mouse to interact', {fontFamily : 'Arial Black', fontSize: 10, fill: input.colors[10], align : 'center'});
    text.anchor.set(0.5);
    backgroundColor = input.colors[15];
    input.container.addChild(text);
   },
  
//remove text when mouse click  
   mouseDownTouchStart: function(PIXI, input) {
     text.visible = false
   },
  
//resize bottom sprite with canvas  
   resize: function(PIXI, input) {
     imageSprite.y = (input.height) - imageSprite.height;
     console.log(imageSprite.height);
     
//resize ntext with canvas
     text.position.set(input.width/2, input.height/2);
     text.style.fontSize = input.width/50;
   },

//render function start  
   render: function(PIXI, input) {
  }  
});

//information
SPF.info({
    debug: false,
    title: "Mathias Jørgensen",
    firstName: "Mathias",
    lastName: "Jørgensen",
    email: "mkmathiasj@gmail.com",
    section: "s4, s7, s9"
});

SPF.start();

//END
            
          
!
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