<< 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 fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Do you know which machine is used to that process?
how to fabricate graphene ink ?
for screen printed electrodes ?
What is lattice structure?
s. Reply
of graphene you mean?
or in general
in general
Graphene has a hexagonal structure
On having this app for quite a bit time, Haven't realised there's a chat room in it.
what is biological synthesis of nanoparticles
Sanket Reply
what's the easiest and fastest way to the synthesize AgNP?
Damian Reply
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

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?