LoginSignup
14
2

More than 5 years have passed since last update.

CSS(SCSS)だけでPPAP✏️🍍🍎✏️

Last updated at Posted at 2016-12-01

散々擦られているネタですが, 昨日PPAPが流行語にも選ばれましたのでCSS(SCSS)のみで実装してみました。

参考
http://qiita.com/hmhmsh/items/a9c1848437b765e538d3
http://qiita.com/on0z/items/ef32f79bde5452a2ccec

仕様

Pen: ✏️
Pineapple: 🍍
Apple: 🍎

Pen, Pineapple, Apple, Penをランダムに出力して ✏️🍍🍎✏️ の並びが来たら"Pen Pineapple Apple Pen !!"と出力して終了します。

デモ

PPAP SCSS on Codepen

キャプチャ
Screen Shot 2016-12-01 at 23.06.49.png

処理部分

$content: "";
$pen: "✏️";
$pineaple: "🍍";
$apple: "🍎";
$array: $pen, $apple, $pineaple;
$init: "";
$p: $pen;
$pp: $pen + $pineaple;
$ppa: $pen + $pineaple + $apple;
$ppap: $pen + $pineaple + $apple + $pen;
$state: $init;

@function createState($nextState, $t, $c){
    @if $c == $t {
      @return $nextState;
    } @else {
      @return $init; 
   }
}

@while $state != $ppap {
    $c: nth($array, random(3));

    $content: append($content,  $c);    

    @if $state == $init{
      $state: createState($p, $pen, $c);
    } @elseif $state == $p {
      $state: createState($pp, $pineaple, $c);
    } @elseif $state == $pp {
      $state: createState($ppa, $apple, $c);
    } @elseif $state == $ppa {
      $state: createState($ppap, $pen, $c);
    } @else {
      $state: $init; 
    }
}

ランダム関数について

SCSSって言っても結局静的なCSSを吐き出すだけなのでRandom関数はコンパイル時にランダムな値を出力するだけです。
そのためCodepen上ではリロード時にコンパイルが走るため擬似的にうまいこと毎回の表示で異なる出力が再現できます。

まとめ

while, if, random があれば割となんでもできる!!

14
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
2