<< Chapter < Page Chapter >> Page >

Recall also that if you plan to export your sketch in JavaScript mode or to export your sketch as a stand-alone application, you must use literal values asthe parameters to the size method.

You should set the height of the display window to be at least 70 pixels greater than the height of the image to allow roomto display the width, height, and pixel information below the image as shown in Image 4 . Otherwise, the black text will be printed on the image and may not be visible, depending on the color of theimage.

If you don't know the size of your image, simply make a guess. You will either get an output that displays the size of the image, as in Image 2 and Image 3 , or you will get an output that shows the image as in Image 1 and Image 4 . In either case, the width and height of the image will be displayed and you can use this information to update the call tothe size method and recompile the sketch.

Set the font

The only other thing that is new in Listing 2 is the call to the createFont method.

This statement is required to prepare the sketch to draw the text characters on the display window as shown in Image 1 . I will leave it as an exercise for the student to study the documentation for the createFont method in whatever depth is necessary to understand it.

The draw method

The draw method is shown in its entirety in Listing 3 . As you can see, all the duties of the draw method were delegated to the run method belonging to an object of the class named Pr0120aRunner .

Listing 3. the draw method.

void draw(){ obj.run();}//end draw
Listing 3. The draw method.

You might be wondering why I didn't simply write that code in the draw method. The reason is that I frequently provide my students with input and output images (such as Image 1 and Image 4 ) along with the driver code in Listing 10 . It is then the students responsibility to design and write the code in Listing 11 .

In other words, I provide a driver class along with the input and output images. It is the student's responsibility todesign and write a class that will run in conjunction with the driver class to transform the input image into the output image.

The class named Pr0120aRunner

Beginning of the class

The class named Pr0120aRunner begins in Listing 4 .

Listing 4 also shows the beginning of the method named run that is called by the draw method in Listing 3 .

Listing 4. beginning of the class named pr0120arunner.

class Pr0120aRunner{void run(){ background(255);//whitetextFont(font,16);//Set the font size, and colorfill(0);//black textloadPixels();//required img.loadPixels();//requiredfloat reD,greeN,bluE;//store color values hereint ctr = 0;//output pixel array counter
Listing 4. Beginning of the class named Pr0120aRunner.

The run method begins by setting the background of the display window to white, and then takes care of some more housekeeping details regarding fonts.

Daniel Shiffman tells us about the requirement to use the loadPixels method and the updatePixels method in his tutorial titled Images and Pixels . I will leave it as an exercise for the student to study and understand that material.

Finally, Listing 4 declares some local variables that will be used later.

Check for size problems

The code in Listing 5 checks to confirm that the image will fit in the display window. If not, one of the messages shown in Image 2 and Image 3 is displayed in place of the image.

Questions & Answers

what is defense mechanism
Chinaza Reply
what is defense mechanisms
Chinaza
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
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, The processing programming environment. OpenStax CNX. Feb 26, 2013 Download for free at http://cnx.org/content/col11492/1.5
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'The processing programming environment' conversation and receive update notifications?

Ask