<< Chapter < Page Chapter >> Page >
y = x*x
Listing 6 . The method named function for Parabola01. double function(double xVal){ double yVal = xVal*xVal;return yVal; }//end function

A plot of the output of the method named function would look like the curve shown in Figure 7 with no offsets if the x and y scaling values were set to one-half the width and height of the world respectively.

Figure 7. Parabola with zero offsets.

Missing image

It will be instructive to see how this program uses offsets and scaling values to transform the image shown in Figure 7 into the image shown in Figure 6 .

Drawing parameters for Parabola01

The code fragment shown in Listing 7 shows the drawing parameters that were used to produce the output shown in Figure 6 .

Listing 7 . Drawing parameters for Parabola01. double xOff = 0.25;//offset relative to 1.0 double yOff = -0.25;double xScale = 0.75*world.getWidth()/2; double yScale = 1.25*world.getHeight()/2;

Drawing parameters with zero offsets

The parameters that were used to produce the output shown in Figure 7 are shown below:

double xOff = 0.0;//offset relative to 1.0 double yOff = -0.0;double xScale = 1.0*world.getWidth()/2; double yScale = 1.0*world.getHeight()/2;

Note in particular that the offsets given by xOff and yOff are set to zero and the scale factors given by xScale and yScale are one-half the width and height of the world respectively.

Changing the offset values

Increasing the offsets for xOff and yOff to 0.25 and -0.25 respectively as shown in Figure 7 and making no other changes produces the output shown in Figure 8

Figure 8. A parabola with offsets.

Missing image

In comparison with Figure 7 , changing the value of xOff to 0.25 caused the peak to move to the right (positive direction) one-fourth of the way from the center origin to the right edge of the world. (That change also caused a portion of the curve to fall outside the right boundary of the world.)

Similarly, changing the value of yOff to -0.25 caused the peak to move up (negative direction) one-fourth of the way from the center origin to the top edge of the world.

Changing the scale factors

Following that, changing the values of xScale and yScale to the values shown in Listing 7 produces the graphic output shown in Figure 6 . The change in xScale decreased the total width of the curve and prevented it from exceeding the rightmost boundary of theworld. The change in yScale increased the overall height of the curve causing it to almost touch the lower boundary of the world.

Draw the parabolic function in BLUE

The code in Listing 8 draws the blue parabolic function shown in Figure 6 .

Listing 8 . Draw the parabolic function in BLUE. double yVal = 0; int row = 0;int col = 0; double xVal = -1;turtle.setPenColor(Color.BLUE); for(int cnt=0; cnt<=100;cnt++,xVal += 0.02){ //Get a y-value for the given x-value.yVal = function(xVal); //Apply the offsets and scale the resultscol = (int)((xOff+xVal)*xScale); row = (int)((yOff+yVal)*yScale);//Move to the first point without drawing a line because the// pen is not down. Translate the origin to the center in the // process.turtle.moveTo(col + world.getWidth()/2, row + world.getHeight()/2);//Lower the pen in order to draw a line from each point to the // next point.turtle.penDown(); }//end for loop}//end run method

Questions & Answers

what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
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.
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, 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?