Advertisement
dannsbass

Empat Segitiga Warna Warni

Apr 17th, 2021
1,459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.54 KB | None | 0 0
  1. <?php
  2. if(PHP_SAPI != 'cli') exit('File ini hanya bisa diakses melalui PHP-CLI');
  3. $merah="\033[0;31m";
  4. $hijau="\033[0;32m";
  5. $putih="\033[0;37m";
  6. $birumuda="\033[0;36m";
  7. $ungu="\033[0;35m";
  8. $biru="\033[0;34m";
  9. $kuning="\033[0;33m";
  10. $a=1;
  11. $b=20;
  12. while ($a <= $b) {
  13.  t($hijau,1);
  14.  t($kuning,0);
  15.  s($ungu,1);
  16.  s($birumuda,0);
  17.  echo "\n";
  18.  $a++;
  19. }
  20. function s($warna,$arah=1){
  21.  global $a,$merah,$putih,$biru,$ungu,$birumuda,$kuning;
  22.  $x = '■';
  23.  if($arah == 1){
  24.   for ($c=1;$c<=$a;$c++) {
  25.    if($c%2==0){
  26.     if($a%2==0){
  27.      echo $warna.$x;
  28.     }else{
  29.      echo $biru.$x;
  30.     }
  31.    }else{
  32.     if($a%2==0){
  33.      echo $merah.$x;
  34.     }else{
  35.      echo $birumuda.$x;
  36.     }
  37.    }
  38.   }
  39.  }else{
  40.   for ($d=20;$d>=$a;$d--){
  41.    if($d%2==0){
  42.     if($a%2==0){
  43.      echo $warna.$x;
  44.     }else{
  45.      echo $kuning.$x;
  46.     }
  47.    }else{
  48.     if($a%2==0){
  49.      echo $putih.$x;
  50.     }else {
  51.      echo $ungu.$x;
  52.     }
  53.    }
  54.   }
  55.  }
  56.  echo ' ';
  57. }
  58. function t($warna,$arah=1){
  59.  global $a,$merah,$putih,$biru,$ungu,$birumuda,$kuning;
  60.  $x = '■';
  61.  if($arah == 1){
  62.   for ($c=20;$c>=$a;$c--) {
  63.    if($c%2==0){
  64.     if($a%2==0){
  65.      echo $warna.$x;
  66.     }else{
  67.      echo $biru.$x;
  68.     }
  69.    }else{
  70.     if($a%2==0){
  71.      echo $merah.$x;
  72.     }else{
  73.      echo $birumuda.$x;
  74.     }
  75.    }
  76.   }
  77.  }else{
  78.   for ($d=1;$d<=$a;$d++){
  79.    if($d%2==0){
  80.     if($a%2==0){
  81.      echo $warna.$x;
  82.     }else{
  83.      echo $kuning.$x;
  84.     }
  85.    }else{
  86.     if($a%2==0){
  87.      echo $putih.$x;
  88.     }else {
  89.      echo $ungu.$x;
  90.     }
  91.    }
  92.   }
  93.  }
  94.  echo ' ';
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement