Question
Introduction An array is a data structure that contains a group of elements. Typically these elements are all of the same data type, such as
Introduction
An array is a data structure that contains a group of elements. Typically these elements are all of the same data type, such as an integer or string. Arrays are commonly used in computer programs to organize data so that a related set of values can be easily sorted or searched. (Techterms.com)
We will create and fill 3 arrays with the color components R G and B, then write these to a file and view them with an online viewer.
*You will turn in the JAVA file and the output files.
Learning Objectives
Continue to use Methods in your programs to complete specific tasks.
Practice using logic to solve problems and create a visible design.
Get an introduction to writing output to a file.
Mac users:
You can view the output.ppm file by just double-clicking the file in finder where it opens with preview.
PC users:
You can find an online PPM viewer or use one of these:
Drag and drop file to this one: http://paulcuth.me.uk/netpbm-viewer/Links to an external site.
(This viewer also allows you to right-click the image and save it!)
(Both the below views require refreshing before uploading the file again)
http://www.cs.rhodes.edu/welshc/COMP141_F16/ppmReader.htmlLinks to an external site.
http://web.eecs.utk.edu/~smarz1/pgmview/Links to an external site.
Example output: Here is an example output you could create: (This is the first layer)
output.ppm Download output.ppm Download this file and view it in the above viewer.
Here is an example of 3 layers, the background, the pyramid, and the sun.
output2.ppm
Here is an example of turning an image from color to gray scale:
Process
Download the base code pic.javaDownload pic.java
Change the names of the file and class to YourNameEx7.java
Read all the comments in the file. Only add code to the main method, do not change the WriteFile method.
This will create the output.ppm file for you and you can view it as described above.
Create a square picture, anywhere from 500 x 500 to 700 x 700, but it must be square.
Create 3 parallel 2 dimensional arrays of integers, one for red, one for blue, one for green.
Generate numbers from 0 to 255 inclusive for each pixel. Look up RGB color values, but some common ones are :
White 255, 255, 255
Black 0, 0, 0
Red 255, 0, 0
Green 0, 255, 0
Blue 0, 0, 255
Maroon 88, 0, 0
you must use at least 4 colors and a pattern more complicated than half one color and half the other.
You must create at least 3 layers,
First, fill in a background color, colors or pattern.
Second, overwrite less than 50% of the background with some design or shape.
Third, overlap a small portion of the image with another design.
Make your mark. In the bottom right corner of your image, put a mark of some type, ||| for CSCE 111, a small square, circle, triangle, or some other unique signature for your artwork. In the comments in your code and when you turn in the project, tell us what the mark is. Using a contrasting color so we can see it.
Use equations or other means to fill the arrays, then send the arrays to WriteFile. The output will be outputC.ppm
View your output and iterate until you are happy with the results.
After you are satisfied with the output, convert your color image to greyscale.
Use the following equations to change the image:
For white, black, and all shades of gray, each pixel has the same value.
New grayscale pixel value = ( (0.3 * R) + (0.59 * G) + (0.11 * B) ). This equation is calculated and replaces each of the 3 RGB components of your color. All 3 will have the same value.
Send the converted array to WriteFile again to create a new output file. This one will be outputG.ppm
View your output and iterate until you are happy with the results.
Be creative and have fun!
Turn in your .java file, and your 2 output files.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started