Question
Point Tracer Lab In Java, write the program with the following instructions: 1. The Display Class The Display class is a small little class. Its
Point Tracer Lab
In Java, write the program with the following instructions:
1. The Display Class
The Display class is a small little class. Its only function is to display points. The window keeps track of the last n points that were displayed and draws them as a trace of fading color.
When creating the display window object, we will specify the number of trailing points and the size in pixels of each point.
For example, to create a Display object that will display a trace of fifty points, each five pixels wide, and assign it to a variable named window, you would write following line of code. Display window = new Display (50 , 5);
To draw a point at a particular position, you will use the drawPointAt method. The coordinate system we use has (0, 0) at the upper left corner, with x increasing as we go to the right and y increasing as we go down. For example, if we were using the Display variable above, we could draw a point at (25, 40) with the following line of code. window . drawPointAt (25 , 40);
Again using the Display variable above, we can query the display size and assign the values to variables, like so. int width = window . getWidth (); int height = window . getHeight ();
2. Now, create the PointTracer class
1. Create a class named PointTracer.
2. Create a Display object in the main method. You should only create one Display object for the entire program.
3. Call the drawPointAt method with a coordinate of (200, 200) and run your program. A point should be drawn at the center of the screen. Try calling drawPointAt with other coordinates to see what happens. What happens if you put the method call inside a loop?
4. Now that youve started your program, change it to draw the following in succession.
Box Make the display window draw a point that moves around the screen to create a square. This means that you will have to modify the indices of the point to move right, then down, then left, and then up. You will need to use several loops for this. You may draw the box wherever you like and of whatever size you choose as long as it fits on the window and the point is shown moving around the perimeter of the square in a continuous path.
Spiral I gave you an example of code that drew points on the circumference of a circle, where the angle was changing each iteration of the loop, but the radius was fixed. Consider what happens if you also change the radius. Youll draw a spiral. Write a single loop that will draw a spiral shape on the same display that you used for the box. It is up to you whether it is drawn from the outside in or the center out, but either way, you do need to stop spiralling at some point. See the mathematical explanations in section 3, if you are feeling rusty on your trig functions and need a little help understanding the math in my circle demo code.
Something Fancy Come up with your own fancy version of a moving point. The idea should be more complex than the movement on the circle Can you come up with some nifty pattern?1 Again, draw this third part on the same display as the first two parts. Make sure that the loops for your box and spiral designs eventually terminate so the graders will be able to see all three parts of your program.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started