<< Chapter < Page Chapter >> Page >

Darken the background of the snow scene

Listing 4 calls the method named darkenBackground to make all of the pixels darker in the snow scene except for those in thelocation of the ellipse as shown in Figure 4 . The pixels at the location of the ellipse are given a red tint.

Listing 4 - Darken the background of the snow scene.
darkenBackground(hole,snowScene);

Put the run method on temporary hold

I will put the explanation of the run method on hold at this point and explain the method named darkenBackground .

The method named darkenBackground

The method named darkenBackground receives references to two Picture objects as parameters. It uses the first picture as a pattern from which it determines which pixels in the second picture (destination) should be darkened.

The pattern and destination images

In this case, a cropped version of the image of the black ellipse shown in Figure 2 is the pattern. The cropped image of the snow scene shown in Figure 6 is the destination image whose pixels will be darkened.

Assumptions

The darkenBackground method assumes that the pattern image has a pure green background as shown in Figure 2 . It also assumes that the pattern and the destination have the same dimensions.

Behavior of the method

The darkenBackground method darkens every pixel in the destination that is at the location of a green pixel in the pattern.

The method applies a red tint to every pixel in the destination that is at the location of a non-green pixel in the pattern

Beginning of the darkenBackground method

The darkenBackground method begins in Listing 5 .

Listing 5 - Beginning of the darkenBackground method.
private void darkenBackground(Picture pattern, Picture dest){Pixel[] patternPixels = pattern.getPixels();Pixel[] destPixels = dest.getPixels();Color color = null; int red = 0;int green = 0; int blue = 0;

Get two arrays of pixel data

The darkenBackground method begins by calling the getPixels method on each of the picture objects to create a pair of array objects containing pixel data.

You learned how to use the getPixels method in an earlier module. Recall that this approach is useful when you don't need to be concerned aboutthe locations of the pixels in an x-y coordinate system.

Arrays have the same length

Because the two pictures have the same dimensions, the two arrays have the same length.

A given array index specifies pixel data from the same location in both pictures.

Beginning of the processing loop

The method uses a for loop to traverse the two arrays of pixel data in parallel, using information from the pattern picture to make the color changes to the destination picture described above. The for loop begins in Listing 6 .

Listing 6 - Beginning of the processing loop.
for(int cnt = 0;cnt<patternPixels.length;cnt++){ color = patternPixels[cnt].getColor(); if(color.equals(Color.GREEN)){//Darken corresponding pixel in the destination. color = destPixels[cnt].getColor(); destPixels[cnt].setColor(color.darker());

Behavior of the processing loop

Questions & Answers

I'm interested in biological psychology and cognitive psychology
Tanya Reply
what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
What would be the best educational aid(s) for gifted kids/savants?
Heidi Reply
treat them normal, if they want help then give them. that will make everyone happy
Saurabh
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask