JAVA CODE
Module 4 Labs
DR. CATHERINE ANDERSON MCNEESE STATE UNIVERSITY
CSCI 282 OBJECT ORIENTED PROGRAMMING
CHAPTER 1
Graphic design with rotation
Using rotation with graphics to create a bit of art
GRAPHICS CONCEPTS
1. Progressive design
2. Rotation about a spot
3. creating a spiral
SECTION 1
Progressive design This lab will be asking you to write a method that uses graph- ics to create a lovely display of art. First we will introduce you to a few concepts.
Progressive design:
The code-along for this lab will demonstrate the process of making a design by repeatedly drawing the same shape or group of shapes. We will be using iteration and rotation to re- peatedly draw a circle to create a ring type design. ‘
The parameters to the method that will be written in this code-along are as follows:
1. g -the Graphic 2. xCenter -x position of the center of the design 3. yCenter -y position of the center of the design 4. radius - the distance from the central position (pivot
point) where the shape will be drawn. 5. angle - angle from the horizontal starting position 6. maxAngle - the full angle that will be rotated through to
create the design.
2
The end result for our methods call is the design shown below.
After this code-along you should experiment with various fac- tors that can change the design, such as scaling the size of the oval used or using multiple calls to the method. Try to dupli- cate the designs that follow:
You should be able to form composite designs by making mul- tiple calls to your method. Try to generate the designs below.
3
1. Create a class called DrawingPanel2 that extends JPanel
2. Create a method to form a graphic shape or pattern based on the draw polygon method of the Graphics.
3. Add custom colors that change in increments
SECTION 2
Method to create a graph- ics design
For this exercise, you will be practicing writing a method to create a design that uses the draw polygon method of the Graphics class..
This is a single file solution, meaning the JFrame that will frame the drawingPanel2 will be created in the main method.
This exercise has a code-along to introduce the draw polygon method and some techniques for using it in progressive de- signs (progressive in that the design is form in progressive steps).
The first shape that we will be creating with the polygon method is shown in the image below:
This diagram gives you an explanation of the variables that will be used in the code-along.
Once again, you will have to write a method to create a design, with the first three parameters being the Graphics, and the X
4
and Y coordination for the location of the center of the design. Feel free to add more parameters or to write more than one method.
The results of the code-along is shown below.
Remember, if you want to base you submission on the code from this code-along, you must make sure that there are no numeric literal in your code that are not being used to initial- ize a variable. Also you must add addition features to the de- sign
If you increase the maximum angle in you method to 90 de- grees, you will get the design below.
You should try to varying the color through each iteration of the loop. IF you start with a nice strong color and eventually lighten it you get the design on the next page. this creates a much more interest- ing design which even appears to have depth.
5
The fact that you have made a methods you can call it multiple times with different arguments to create a compound design.
The design on the next page was created by 5 method calls.
6
LOREM IPSUM
1. Must have a rotation factor
2. Must have variation in color
3. Cannot be any of the designs covered in the code-along.
SECTION 3
Evaluated exercise You are to create you own design. This must be DIFFERENT than what has been covered in the code along. And don’t de- spair, that is so much potential that you should be able to come up with something very easily.
For example, rotating a triangle will generate the following
So as I said, make a design, but be sure you can explain the base shape.
You are expected to submit the source code file for both Draw- ingPanel ad DrawingPanel2, one of which should have the methods you created to produce your original design. You should take a screen shot of the final result and paste it in your lab sheet, and then submit your lab sheet!
So you zipped file should contain three files: two .java and one word document.
7
CHAPTER 2
Spawning shapes
Animation with randomly generated shapes.
CHAPTER 3
Animation
Continuous Animation using rotation of a group of 5 blocks