<< Chapter < Page Chapter >> Page >


In this lesson, I will explain programs that use a Turtle object to graph the following mathematical functions:

  • A straight line
  • A parabola
  • A cubic
  • A circle (two approaches)
  • A cosine

I will also show you how to graph a circle without using a Turtle object and compare the two approaches.

General background information

You learned about the World class, the Turtle class, and the Picture class in an earlier lesson titled Java3002: Creating and Manipulating Turtles and Pictures in a World Object . You learned the fundamentals of causing the turtle to move and to draw a linewith different colors and different line widths in the process. For review, Figure 1 shows an image that you learned to create in that earlier lesson.

Figure 1. Two turtles in a World object.

Missing image

In comparison, Figure 2 shows the sort of thing that you will learn to do in this lesson.

Figure 2. Graph of a cubic function.

Missing image

The blue line in Figure 2 shows a graph of the following cubic function in a Cartesian coordinate system:

y = x*x*x

The red lines in Figure 2 show the x and y axes.

The graph in Figure 2 was created by computing the x and y coordinate values (points) for a set of x values uniformly spaced along the x axis and causing the Turtle object to move and connect those points with a blue line. The Turtle object was made invisible.

As a practical matter, computing the coordinate values is relatively simple. The more complex problem is to get everything scaled properly to produce avisually pleasing graph in the space provided by the World object.

Discussion and sample code

I will explain six different programs in this lesson. Complete listings of those programs are provided in Listing 15 through Listing 20 in the section titled Complete program listings .

As is my custom, I will break the programs down and explain them in fragments. However, I will explain only those portions of the programsthat are new to this lesson. I will let the comments in the listings speak to those portions of the code that you should already understand.

Much of the code repeats from one program to the next. I will explain new code the first time that it appears in a program and won't explain that code in theexplanation of programs that follow.

A straight line

In this section, I will present and explain a program named Line01 that can be used to draw a straight line using the standard formula for a straight line given below:

y = slope*x + yIntercept

A complete listing of the program is provided in Listing 15 near the end of the lesson.

Program output for Line01

Before getting into the code, Figure 3 shows the program output.

Figure 3. Program output for Line01.

Missing image

As you can see, in addition to the red axes, this program graphs three different lines in different colors with different slopes and differenty-intercept values. I will touch on the slopes and the y-intercept values as I explain the code.

May need multiple points

At this point, I will explain a practical issue before it becomes a concern to you. As we all know, only two points are required to define a line.However the program that I will explain uses multiple points to define and draw a line. This requirement results from the behavior of a Turtle object when moving from one point to another point.

Questions & Answers

How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
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
How can I make nanorobot?
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
how can I make nanorobot?
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
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?