<< Chapter < Page Chapter >> Page >

Turn counter clockwise

Then Listing 7 calls the turn method causing the turtle to rotate its body by 135 degrees counter-clockwise. (A positive parameter causes a clockwise rotation and a negative parameter causes a counter clockwise rotation.)

Change the pen color and move forward again

Finally Listing 7 calls methods to change the pen color to blue and to cause the turtle to move forward by 150 pixels.

The final location

After making the turn, the turtle is facing southwest. Therefore, the forward movement causes a diagonal blue line to be drawn from theposition at the top of the yellow line down toward the southwest. As you can see in Figure 1 , the turtle comes to rest at the end of that line.

A few words about color

I have published extensively on the concept of color in Java. The best way to find that information is probably to go to Google and search for the keywords:

richard baldwin "color class" site:http://cnx.org/contents/

Google is also probably your best bet for finding information on other topics that I have published on various websites. For example, if you go to Google Images and search for the following keywords, you will find a lot of the work that I havepublished using Ericson's media library.

richard baldwin java ericson

Manipulate the turtle named sue

Listing 8 calls several methods on the object whose reference is stored in the variable named sue .

Listing 8 . Manipulate the turtle named sue.
sue.setName("sue");sue.setPenWidth(2); sue.setPenColor(Color.RED);sue.moveTo(183,170);sue.setPenDown(false);sue.moveTo(216,203); sue.setPenDown(true);sue.moveTo(250,237);}//end run method }//end class Prob01Runner

The end result

These method calls result in the turtle named sue facing north in the lower right corner of the window, having drawn the broken red line shown in Figure 1 in getting there.

The moveTo method

Listing 8 calls the moveTo method to cause the turtle to move to a new location on the basis of coordinate values instead of on the basis of a distance value.

Pen control

Listing 8 also calls the setPenDown method twice passing false and then true as the parameter to first raise and then lower the pen. This produced the gap in the red line shown in Figure 1 .

The Turtle class also provides methods named penUp and penDown that can be used to raise and lower the pen.

The end of the program

Listing 8 also signals the end of the method named run and the end of the class named Prob01Runner . As such, Listing 8 signals the end of the program.

Run the program

II encourage you to copy the code from Listing 9 , compile it and execute it. Experiment with the code, making changes, and observing the results of your changes. Make certain that you can explain why your changes behave as they do.

Summary

II explained a program that uses Java and Ericson's media library to:

  • Add a picture and two turtles to a world.
  • Manipulate the turtles, their color, and their pens.

Stated in more detail, the program:

  • Creates a Picture object and replaces the default white Picture in a World object with the new Picture object.
  • Places two Turtle objects in a World object.
  • Applies a series of operations to manipulate the two turtle objects so as to produce a specific graphic output.
  • Provides accessor methods to get references to two Turtle objects and the World object.
  • Gets information from the World and Turtle objects and displays the information on the command-line screen.
  • Displays text on a Picture in a World object.

Questions & Answers

summarize halerambos & holbon
David Reply
the Three stages of Auguste Comte
Clementina Reply
what are agents of socialization
Antonio Reply
sociology of education
Nuhu Reply
definition of sociology of education
Nuhu
what is culture
Abdulrahim Reply
shared beliefs, values, and practices
AI-Robot
What are the two type of scientific method
ogunniran Reply
I'm willing to join you
Aceng Reply
what are the scientific method of sociology
Man
what is socialization
ogunniran Reply
the process wherein people come to understand societal norms and expectations, to accept society's beliefs, and to be aware of societal values
AI-Robot
scientific method in doing research
ogunniran
defimition of sickness in afica
Anita
Cosmology
ogunniran
Hmmm
ogunniran
list and explain the terms that found in society
REMMY Reply
list and explain the terms that found in society
Mukhtar
what are the agents of socialization
Antonio
Family Peer group Institution
Abdulwajud
I mean the definition
Antonio
ways of perceived deviance indifferent society
Naomi Reply
reasons of joining groups
SAM
to bring development to the nation at large
Hyellafiya
entails of consultative and consensus building from others
Gadama
World first Sociologist?
Abu
What is evolutionary model
Muhammad Reply
Evolution models refer to mathematical and computational representations of the processes involved in biological evolution. These models aim to simulate and understand how species change over time through mechanisms such as natural selection, genetic drift, and mutation. Evolutionary models can be u
faruk
what are the modern trends in religious behaviours
Selekeye Reply
what are social norms
Daniel Reply
shared standards of acceptable behavior by the group or appropriate behavior in a particular institution or those behaviors that are acceptable in a society
Lucius
that is how i understood it
Lucius
examples of societal norms
Diamond
Discuss the characteristics of the research located within positivist and the interpretivist paradigm
Tariro Reply
what is Industrialisation
Selekeye Reply
industrialization
Angelo
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