//adds 1 do $dotlocation $col = $col - 1; //subtracts 1 from $col print_r("\n"); //print line break } //begin outer loop again - note the new values of $col $dotlocation $i $j and $d print_r("\n"); } function UpsideDownTriangle() { $col = 5; //starts the columns at 5 for ($i = 0; $i <= 5; $i++) { //iteration for the "rows" loop - if $i <= 5 move to nested loop and add 1 to $i for ($j = 0; $j <= $col; $j++) { //iteration for the "columns" loop - if $j <= $col print "." and add 1 to $j. run loop until false. print_r("."); } $col = $col - 1; //subtracts one from $col when the nested loop is false. print_r("\n"); //prints line break & returns to original loop, note new values for variables. } } } $printShape = new ShapeMaker(4); //creates a variable calling class $printShape->Triangle(); $printShape->BackwardsTriangle(); $printShape->UpsideDownTriangle();
} $counter++; echo "\n"; } echo "\n"; } function RegularTriangle() { for ($x = 0; $x < $this->input + 1; $x++) { for ($y = 0; $y < $x + 1; $y++) { echo $this->ParentArray[$x][$y]; } echo "\n"; } } function UpsideDownTriangle() { for ($x = 0; $x < $this->input + 1; $x++) { for ($y = $this->input; $y > $x - 1; $y--) { echo $this->ParentArray[$x][$y]; } echo "\n"; } } } $regular = new ShapeMaker(4); $regular->RegularTriangle(); $backwards = new ShapeMaker(4); $backwards->BackwardsTriangle(); $upsidedown = new ShapeMaker(4); $upsidedown->UpsideDownTriangle();
} } function upsidedowntriangle() { $rowLimit1 = 4; for ($i = 0; $i < $this->size; $i++) { for ($t = 0; $t < $rowLimit1; $t++) { echo $this->stars[$i][$t]; } echo "\n"; $rowLimit1--; // changed variable to -- to decrease by 1 * } } } $maker = new ShapeMaker(4); //print_r ($maker->stars);// using maker var cause outside of class, oppose to using $this which is inside $maker->backwardstriangle(); $maker->upsidedowntriangle(); $maker->triangle(); //calling the function, creating it is only declaring it ?>
$col = 3; $starcount = 0; for ($i = 0; $i <= 3; $i++) { for ($c = 0; $c <= $col; $c++) { print_r(" "); } for ($j = 0; $j <= $starcount; $j++) { print_r("*"); } $starcount = $starcount + 1; $col = $col - 1; print_r("\n"); } } function UpsideDownTriangle() { $col = 3; for ($i = 0; $i <= 3; $i++) { for ($c = 0; $c <= $col; $c++) { print_r("*"); } $col = $col - 1; print_r("\n"); } } } $mySC = new ShapeMaker(4); // calls function $mySC->Triangle(); $mySC->BackwardsTriangle(); $mySC->UpsideDownTriangle();