<< Chapter < Page Chapter >> Page >

Some output from the program

Before getting into the technical details of the program, I am going to show you some sample screen output from the program. Figure 6 shows the result of drawing lines to connect the points in the pattern described above among fifteenpoints that are equally spaced around the circumference of the circle.

Figure 6 String art with 15 vertices and 7 loops.

Missing image.

Figure 7 shows the result of drawing lines in a more complex pattern among 25 points that are equally spaced around the circumference of the circle.

Figure 7 String art with 25 vertices and 11 loops.

Missing image.

Figure 8 shows the result of drawing lines in an extremely complex pattern among 100 points that are equally spaced around the circumference of the circle.

Figure 8 String art with 100 vertices and 100 loops.

Missing image.

As you can see, there were so many lines and they were so close together in Figure 8 that the visual distinction between lines almost completely disappeared.

Finally, Figure 9 shows the program output at startup, with six vertices and one loop.

Figure 9 Output from StringArt01 at startup.

Missing image.

Will discuss in fragments

As is my custom, I will discuss and explain this program in fragments. Much of the code in this program is very similar to code that I have explainedearlier, so I won't repeat those explanations. Rather, I will concentrate on the code that is new and different in this program. A complete listing of theprogram is provided in Listing 21 near the end of the module.

Most of the code that is new to this program is in the method named drawOffScreen , which begins in Listing 14 .

Listing 14 . Beginning of the drawOffScreen method in StringArt01.
void drawOffScreen(Graphics2D g2D){ //Erase the off-screen image and draw new axes, but// don't move the origin.setCoordinateFrame(g2D,false);//Create a set of Point objects that specify // locations on the circumference of a circle and// save references to the Point objects in an array. for(int cnt = 0;cnt<numberPoints;cnt++){ points[cnt]= new GM2D04.Point( new GM2D04.ColMatrix(100*Math.cos((cnt*360/numberPoints) *Math.PI/180),100*Math.sin((cnt*360/numberPoints) *Math.PI/180)));}//end for loop

Even some of the code in the method named drawOffScreen was explained earlier, and that is the case for the code in Listing 14 .

Implement the algorithm that draws the lines

Listing 15 begins the outer loop in a pair of nested loops that implement the algorithm to draw the lines shown in Figure 6 through Figure 9 .

Listing 15 . Implement the algorithm that draws the lines.
GM2D04.Line line;//Begin the outer loop. for(int loop = 1;loop<loopLim;loop++){ //The following variable specifies the array// element containing a point on which a line will // start.int start = -1;//The following variable specifies the number of // points that will be skipped between the starting// point and the ending point for a line. int skip = loop;//The following logic causes the element number to // wrap around when it reaches the end of the// array. while(skip>= 2*numberPoints-1){ skip -= numberPoints;}//end while loop//The following variable specifies the array // element containing a point on which a line will// end. int end = start + skip;

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Game 2302 - mathematical applications for game development. OpenStax CNX. Jan 09, 2016 Download for free at https://legacy.cnx.org/content/col11450/1.33
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?

Ask