The function swaps the red and green values of the pixel Write the function and test it to make sure it works the same as the two functions it replaces, so you can generate pictures with borders that have different thicknesses for the vertical borders vs. Now modify the program one more time to replace the two functions pixelOnVerticalEdge and pixelOnHorizontalEdge with one function to do the same thing called pixelOnEdgeDifferentThicknesses( ). This function returns true if the pixel's location is within borderWidth of any of the two horizontal borders, and thus on the border. b) function pixelOnHorizontalEdge(pixel, image, borderWidth) - This function has three parameters where pixel is a single pixel, image is the complete image, and borderWidth is an integer specifying the thickness of the horizontal borders. This function returns true if the pixel's location is within borderWidth of any of the two vertical borders, and thus on the border. a) function pixelOnVerticalEdge(pixel, image, borderWidth) - This function has three parameters where pixel is a single pixel, image is the complete image, and borderWidth is an integer specifying the thickness of the vertical borders. Be sure to print the image and run your program with different border values for the horizontal and vertical edges. You should write the two boolean functions shown below. Now modify the border program to specify two thicknesses, one for the vertical borders and one for the horizontal borders. This function returns true if the pixel's location is within borderWidth of any of the four borders, and thus on the border. b) function pixelOnEdge(pixel, image, borderWidth) - This function has three parameters where pixel is a single pixel, image is the complete image, and borderWidth is an integer specifying the thickness of the borders. a) function setBlack(pixel) - This function has a parameter pixel that represents a single pixel, and returns a pixel that has been changed to be the color black. Be sure to print the image so you can see it and run the program with different border values. You should be able to write these functions without looking at the code from the lesson. Write the complete JavaScript program to put the border around a picture, and include the following functions that are included from the lesson. Run your program on an image to see it get redder. Your program should have a function called moreRed with two parameters, a pixel and a value to increase the red by. Write a JavaScript program to make an image have more red in it, by adding a given value to the red, making sure it doesn't go over 255. Think about what type of image you should use for testing your function. For some images you may not notice any change. Pick an image, print the image, then apply swapRedGreen to every pixel in the image, and print the new image. This function should swap the red and green values of the pixel. What you likely want to do here is call setBlack(pixel) instead, which will call the function you've defined with the argument pixel provided by your for loop.Write a JavaScript program that has a function named swapRedGreen with one parameter pixel. In this case, by calling img.setBlack(), your code is basically going to go look for a definition of a function called setBlack() as defined by SimpleImage, which doesn't exist (thus throwing your error). This means that, instead of looking at previously declared stand-alone functions, like your declaration of setBlack(), your code will instead look for a method defined by the prototype of the object you're invoking it on. You're invoking what's known as a prototype function. In JavaScript, when you call a function like this. Assuming your function is accessible to your for loop code, you need to use setBlack() as a standalone function, rather than calling it like a SimpleImage prototype function.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |