<< Chapter < Page Chapter >> Page >

The drawOffScreen method

The drawOffScreen method that is called by the Animation thread in Listing 13 is very similar to the method having the same name that I explained in conjunction with Listing 3 through Listing 7 . Therefore, I won't repeat that explanation here.

The big difference in the use of that method in the two programs is that in the earlier program, the method was called only once to translate the geometricobject according to the values in the displacement vector in one giant step. In this program, the values in the displacement vector are divided by 100 and the drawOffScreen method is called 100 times with ten-millisecond pauses between each call to the method. Each time the drawOffScreen method is called, the geometric object ends up closer to its final position and each ofthe 100 intermediate positions are displayed on the canvas for ten milliseconds.

End of discussion

That ends the discussion of the program named VectorAdd06 .

The program named StringArt01

You may be old enough to remember when people who liked to do handicraft projects created pictures using strings and nails. If not, I'm sure thatif you Google the topic of string art , you will find more about the topic than you ever wanted to know.

This program was inspired by some programs that I saw at the Son of String Art page. I will be the first to admit that the output from this program isn'tnearly as elaborate or interesting as the output from some of the projects at that web site. Those programs are truly impressive, particularly considering that they were written using a programming language that was "designed to help young people (ages 8 and up) develop 21st century learning skills. (See About Scratch .)

In future modules, however, I will show you how to improve this string art program including the addition of animated translation and rotation of thestring-art images in 3D.

Behavior of the program

This program produces a 2D string art image by drawing lines to connect various points that are equally spaced around the circumference of a circle. Atstartup, the program constructs and draws a multi-colored hexagon centered on the origin as shown in Figure 9 . The six points that define the vertices of the hexagon lie on a circle with a radius of 100 units. The points at the verticesare not drawn, but the lines that connect the vertices are drawn.

A GUI is provided that allows the user to specify the following items and click a Replot button to cause the drawing to change:

  • Number Points
  • Number Loops

As in earlier programs in this module, changing the number of points causes the number of vertices that describe the geometric object to change. Changingthe number of loops causes the number of lines that are drawn to connect the vertices to change. For a Loop value of 1, each vertex is connected to the one next to it. For a value of 2, additional lines are drawn connectingevery other vertex. For a value of 3, additional lines are drawn connecting every third vertex, etc.

Making the number of points and loops large produces some interesting patterns.

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