ANN: Stars
Jim Hurley
jhurley0305 at sbcglobal.net
Fri Jun 22 12:30:31 EDT 2012
As LiveCode announcements go, this one is pretty low key. All "Stars" does is provide the code for drawing a star.
But there is a lesson for LiveCode to learn from the lowly five-pointed star, the one on the US flag.
A star may be viewed in two ways:
1) Analytical Cartesian Geometry: A collection of 10 connected points (5 outside points, and 5 inside) in a Cartesian coordinate system.
2) Euclidian Geometry: A collection of lines and angles without reference to place or orientation.
The first is the Cartesian picture where the computation to draw the star is executed using algebra, trigonometry, and/or analytic geometry.
The other picture is that of a figure in Euclidean space and the construction is carried out geometrically, drawing lines with a given angular relation to one another.
LiveCode favors the Cartesian picture employing its analytic tools to generate a list of 10 points and presenting the list as a graphic by setting the graphic to these points.
Here is how that code might look using those tools to draw a star in a Cartesian coordinate system:
> --FIrst, define the angles and lengths in the figure to be drawn
> put 36 into gamma
> put 18 into alpha
> put 200 into L
> --Next some trig. Not trivial.
>
> --Let r1 be the distance from the center of the star to the inner vertices.
> put L*sine(alpha) /sine(gamma) into r1
>
> --Let r2 be the distance from the center to the outer vertices
> put L*cosine(alpha) + r1 * cosine(gamma) into r2
>
> --Start at the top of the star at a polar angle of 90 degrees
> put 90 into a
> --Circle around the ten verticies of the star
> --in increments of 360/10 = 36 degree, the polar angle between vertices.
> put 36 into da
> repeat with i = 1 to 10
> if i mod 2 = 1 then
> put r2* cosine(a) into x
> put r2* sine(a) into y
> put round(x+ x0) into x
> put round(-y+y0) into y
> put x,y & cr after tPoints--outer points
> else
> put r1* cosine(a) into x
> put r1* sine(a) into y
> put round(x+ x0) into x
> put round(-y+y0) into y
> put x,y & cr after tPoints--inner points
> end if
> add da to a -- next vertex
> --If you want to see the star form line by line.
> set the points of grc "Star" to tPoints
> end repeat
> --Close the loop
> put results & line 1 of results into tPoints
> set the points of grc "Star" to tPoints
And here is what the loop might look like if the star were expressed as a geometrical figure:
> put 2*360/5 into tAngle -- Pretty simple geometry here.
> put 200 into L
> repeat with i = 1 to 5
> forward L
> right tAngle --at an exterior point
> forward L
> left tAngle/2 --at an interior point
> end repeat
(After LC has been taught how to execute "forward", "right", and "left".)
There has been talk for some time of promoting LC in education, even in K-12. Great idea.
There has also been talk, more broadly, of rejuvenating the teaching of mathematics --See the TED talk by Conrad Wolfram at:
http://www.ted.com/talks/lang/en/conrad_wolfram_teaching_kids_real_math_with_computers.htmlConrad Wolfram
(Ken Ray will enjoy the stick figures at the end of the talk.)
From Wolfram's talk: "I believe that correctly using computers is the silver bullet for making math education work." He cites particularly the use of the computer in modeling and simulation. He anticipates scientists (geologist, biologists, engineers) programing these simulations.
LiveCode has all the necessary analytical tools for such modeling and simulation, but it lacks the geometric tools, specifically Sprite Geometry (aka Turtle Graphics.)
For some years I have been promoting (spoken to Kevin on several occasions) the addition of Sprite geometry into LC. I believe it would add significantly to LC's penetration into the education market. It would allow kids to tackle problems that are much too difficult using Cartesian analytical tools, but quite straight forward when presented as problems in geometry--witness the "Star" above.
It would also allow them easy access to game programming. The loop to set a Fox graphic (control) chasing a Rabbit graphic (control) would look like this:
> repeat until the mouseClick
> tell "hare"
> --Move Hare in a circle.
> forward 2
> left 1
> put theLocation() into theHareLocation
> tell "fox"
> setheading direction(theHareLocation)
> forward 1
> end repeat
The Fox and Hare and treated as Sprites and Sprite geometry can talk to any LC control, a drawing sprite with penDown or not drawing with penUp.
Many are put off by Turtle Graphics. There is a perception that it is just for kids. But it goes well beyond simple ways to draw polygons. (See the book by Professor Harold Ableson of MIT titled: Turtle Geometry: The Computer as a Medium for Exploring Mathematics (Artificial Intelligence, at Amazon: http://www.amazon.com/Turtle-Geometry-Mathematics-Artificial-Intelligence/dp/0262510375/ref=sr_1_1?s=books&ie=UTF8&qid=1340373015&sr=1-1&keywords=Turtle+geometry . )
TG is also useful in graphically solving trajectory equations (differential equations) for the path of a projectile, or the motion of the Earth around the Sun. Or the surprising physics behind the rainbow--TG is quite straight forward in representing light rays in general, for they are quite simply lines that turn through angles.
Sprite geometry is wonderfully suited to doing calculus, differential and integral, both in formulating the problems geometrically and in coming up with quantitative solutions. As such it is a valuable educational tool.
As a trivial example of the advantage of Geometry over Analytics, I have illustrated these two approaches (Euclidian geometry vs. analytic geometry) in drawing the star at:
go url "http://jamesphurley.com/RunRev/Stars.livecode"
The scripts there demonstrate the handicap that LiveCode faces in this very simple problem in geometry. LC has a problem. The fault, dear Brutus, may lie in our stars after all.
More information about the Use-livecode
mailing list