Membuat Piramida dengan Bintang dengan PHP
SCRIPTnya:
<html>
<head>
<title>
PHP > perulangan piramida
</title>
</head>
<style>
body{
margin: 0;
background-image: url("321.png");
background-attachment: fixed;
}
td,th{
padding: 15px;
}
#f_megacont{
height: 100%;
margin: 0;
}
#f_cont{
background-image: url("321.png");
position: relative;
text-align: center;
padding:40px;
width: 80%;
margin:auto;
top:10%;
border-radius: 20px;
border: #000 double 4px;
box-shadow: 0 0 10px #333;
}
</style>
<body>
<div id="f_megacont">
<div id="f_cont">
<?php
//piramid 1
echo "<table align='center' border=1><tr><th>
Piramid 1<br>(size font dan color berubah mengecil)
</th><td>";
$teks = "hello Bustomi Arifin Ganteng";
$warna = "";
for($a=1;$a<=5;$a++){
switch ($a){
case 1:$warna = "red";break;
case 2:$warna = "green";break;
case 3:$warna = "blue";break;
case 4:$warna = "cyan";break;
case 5:$warna = "magenta";break;
default :break;
}
echo "<h$a><font color=$warna>$teks</font></h$a>";
}
echo "</td><th>Piramid 2</br>(size font, warna dan bintang berubah membesar)</br>
<form method='post' action='".$_SERVER['PHP_SELF']."'>
<label for='jumlah'>inputkan tinggi piramid2 (max 10)</label></br>
<input id='jumlah' name='jumlah'/><input type='submit' value='oke'>
</form></th><td align=center>";
//piramid 2
if(isset($_POST['jumlah'])){
if($_POST['jumlah']<=10){
$jumlah = $_POST['jumlah'];
}
else{
echo '<script>alert("tampaknya jumlah terlalu tinggi")</script>';
$jumlah=5;
}
}
else{
$jumlah=5;
}
for($f=1;$f<=$jumlah;$f++){
switch ($f){
case 1:$warna = "blue";break;
case 2:$warna = "green";break;
case 3:$warna = "cyan";break;
case 4:$warna = "green";break;
case 5:$warna = "magenta";break;
default :$warna = "rgb(".($f*10).",".($f*$f).",".($f).")";
}
echo "<font style=font-size:".($f*10)."px;color:$warna>";
for($f2=1;$f2<=$f;$f2++){
echo "*";
}
echo "</font></br>";
}
?>
</div></div>
</body>
</html>
Output :
24-09-24
1 bulan yang lalu
0 komentar:
Posting Komentar