123

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.

            
              body{
  background: #1099bb;
  color: #3b4347;
  position: relative;
  display: block;
  height: 100%;
  width: 100%;
}

canvas{
  width: 100%;
  height: auto;
}
            
          
!
            
              // 表示するcanvasを用意
let app = new PIXI.Application(800,600,{backgroundColor : 0x1099bb});
document.body.appendChild(app.view);

//表示をする画像の数
let totalSprites = 100;

//パーティクルの設定
let sprites = new PIXI.particles.ParticleContainer(totalSprites, {
    scale: true,
    position: true
});

//ステージに反映
app.stage.addChild(sprites);

// 複数の画像を設定
let hayachi = [];

//画像分をtotalSprites回数分ループ
for (let i = 0; i < totalSprites; i++) {

    // 画像の設定
    let dude = PIXI.Sprite.fromImage('http://hayachi.github.io/images/hayachi-blue.png');
    
    // 画像の中心地をきめる
    dude.anchor.set(0.5);

    // 画像のサイズのランダムにきめる
    dude.scale.set(0.01 + Math.random() * 0.1);

    // ランダムに散らす
    dude.x = Math.random() * app.screen.width;
    dude.y = Math.random() * app.screen.height;

    // ランダムな速度を0〜2の間で作ります。
    dude.speed = (200 + Math.random() * 0.5) * 0.5;

    // 生成された画像の配列をpushして簡単にアクセスできるようにします
    hayachi.push(dude);

    // ループのデータを反映
    sprites.addChild(dude);
}

//アニメーションの初期値値
let tick = 0;
//ステージの高さ
const HEIGHT = 620;

app.ticker.add(function() {

    // 画像を繰り返し処理して位置を更新する
    for (let i = 0; i < hayachi.length; i++) {
        //配列を代入
        let dude = hayachi[i];
        //横の位置
        dude.x += (Math.random() - 0.5) * 1 * dude.scale.x;
        //縦の位置
        dude.y += dude.scale.y * dude.speed;
      
          //画面の一番下に行った時縦の位置をリセット、横の位置をランダムに配置
        if (dude.y > HEIGHT) {
             dude.y = -10;
             dude.x += (Math.random() - 0.5) * 1 * dude.scale.x;
         }
    }

    // ティッカーを増やす
    tick += 0.1;
});

//------テキストの描画-----//

// スタイルを指定
let styleBig = new PIXI.TextStyle({
    fontFamily: 'Comfortaa',
    fontSize: 70,
    fill: '#ffffff',
    lineJoin: 'round',
    stroke: '#1099bb',
    strokeThickness: 30,
    align: 'center',
    wordWrapWidth: 1000,
    wordWrap: true
});
let styleSmall =  new PIXI.TextStyle({
    fontFamily: 'Comfortaa',
    fontSize: 40,
    fill: '#ffffff',
    lineJoin: 'round',
    stroke: '#1099bb',
    strokeThickness: 30,
    align: 'center',
    wordWrapWidth: 1000,
    wordWrap: true
});

// スタイルを反映
let textBig = new PIXI.Text('Pixi.js', styleBig);
let textSmall = new PIXI.Text('Particle animation', styleSmall);

// テキストの位置を指定
textBig.x = 300;
textBig.y = 220;
textSmall.x = 200;
textSmall.y = 320;

// ステージに表示させる
app.stage.addChild(textBig);
app.stage.addChild(textSmall);
            
          
!
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.

Console