Put the work for this lab into a new folder
public_html\cs1109\lab15.
In a file called nested.php, write a PHP script that
uses nested for-loops to output each of the following:
Square
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
Triangle 1
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Triangle 2
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Write christmas.php, which outputs the
lyrics of The Twelve Days of Christmas, but with Call of Duty gifts
(from WilzoHD's post to the
Call of Duty forum). The gifts are as follows:
Each verse introduces the next gift, but all the previously introduced gifts are repeated — in reverse order! For example, here are the first three verses:
On the first day of Christmas, Call of Duty sent to me a Spas-12 Hitmarker x3. On the second day of Christmas, Call of Duty sent to me two Juggernauts, and a Spas-12 Hitmarker x3. On the third day of Christmas, Call of Duty sent to me three Moroccan Hens, two Juggernauts, and a Spas-12 Hitmarker x3.
You will need one or two arrays and a nested loop.
It may be better to use for-loops, rather than
foreach-loops.
If you want to increase the challenge of the exercise a little, then try to get the commas and the word "and" to come out in exactly the right places (see above).
In this exercise, you will take a colour image and convert it to greyscale. The idea is simple: visit each pixel and set its colour to some shade of grey. You may have realised that in RGB colours, if the amount of red, green and blue are the same, then the colour is some of shade of grey. So, for each pixel, we will calculate its luminescence or intensity, which is simply the average of its amount of red, green and blue, i.e. L = (R + G + B) /3. And we will set the pixel so that the amount of red is L, and similarly the amount of green and blue.
Save copies of these files:
photo.jpggreyscale.phpComplete the program. Here are the built-in functions that you may need:
imagecolorat:
this returns the colour of a pixel in the image. The parameters are the image and the co-ordinates.
Note that the colour is returned as an integer.
imagecolorsforindex:
this converts a colour from an integer (see previous function) into an associative array, with keys
that include "red", "green", "blue".
imagecolorallocate:
you encountered this one last week.
imagesetpixel:
this sets a pixel to a colour. The parameters are the image, the co-ordinates and the new colour.
Important: You must not use the
imagefilter function!
In this exercise, you will take an image and blur it. How? Take a pixel. Add together its R value and the R values of all of its neighbours. (There may be up to 8 of them.) Then divide by how ever many things you added together. In other words, you've calculated the average R value. Do the same for G and B values. Set this pixel's colour using the three averages. Do this to all the pixels.
Take a copy of blur.phps. Save it as blur.php.
Complete the program using the same built-in functions that you used in Part 3. Again, you
must not use the
imagefilter function!
Deadline: 1pm, Tuesday 14th February.
If you have named your files and folders correctly, your work will be collected automatically at that time by my software.
Remember that challenge exercises are always optional. They do not form part of your year's work and they are not worth any marks. They are designed for those students who finish the main exercise quickly and easily, and wish to explore further.
Write a photo editing program, like PhotoShop! For example, here's mine. It allows a user to upload a photo, and request a greyscale version, or a blurred version, etc. The real fun is in offering a wider range of editing operations. Mine, for example, allows edge detection, which finds the outline of the object in the photo and produces a kind of pencil sketch.
Some ideas (which I can discuss with you):
All of this becomes easier if you think about developing a library of helpful functions.
Call the files pshop.html, pshop.php, etc. I'll take a look at any
files whose name begins "pshop".