Difference between revisions of "Fractal Polygons"

From JSXGraph Wiki
Jump to navigationJump to search
 
(19 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
With turtle graphics it is quite easy to construct regular polygons in a recursive manner.
 +
 +
It is possible to play around with this example:
 +
In the last line of the input window there is the command
 +
<source lang="javascript">
 +
fracPolygon(5,100,0.4,5);
 +
</source>
 +
The meaning of the parameters is
 +
* 5: number of vertices of the regular polygon,
 +
* 100: length of a side of the initial polygon,
 +
* 0.4: shrink factor from one level to the next,
 +
* 5: number of recursion steps.
 +
 
<html>
 
<html>
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
 
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
 
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
 
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxturtle.js"></script>
 
 
<form><textarea id="inputtext" rows=3 cols=35 wrap="off" style="width:600px;">
 
<form><textarea id="inputtext" rows=3 cols=35 wrap="off" style="width:600px;">
function fracPolygone(corner,len,shrink,recurs,start) {
+
function fracPolygon(corner,len,shrink,recurs) {
 
     if (recurs>0) {
 
     if (recurs>0) {
         if (start==1) {
+
         if (arguments.length==4) { // initial call
            start = 0;
 
 
             t.rt(180);
 
             t.rt(180);
             fracPolygone(corner,len*shrink,shrink,recurs-1,start);
+
             fracPolygon(corner,len*shrink,shrink,recurs-1,1);
 
             t.lt(180);
 
             t.lt(180);
 
         }
 
         }
Line 17: Line 25:
 
         for(var i=0;i<corner-1;i++) {
 
         for(var i=0;i<corner-1;i++) {
 
             t.rt(180);
 
             t.rt(180);
             fracPolygone(corner,len*shrink,shrink,recurs-1,start);
+
             fracPolygon(corner,len*shrink,shrink,recurs-1,1);
 
             t.lt(180);
 
             t.lt(180);
 
             t.fd(len);
 
             t.fd(len);
Line 28: Line 36:
 
t.setPos(-100,0);
 
t.setPos(-100,0);
 
t.setPenColor('blue');
 
t.setPenColor('blue');
fracPolygone(5,100,0.4,7,1);
+
fracPolygon(5,100,0.4,5);
 
</textarea><br />
 
</textarea><br />
 
<input type="button" value="run" onClick="run()">
 
<input type="button" value="run" onClick="run()">
 
<input type="button" value="clear" onClick="clearturtle()">
 
<input type="button" value="clear" onClick="clearturtle()">
 
</form>
 
</form>
<div id="box" class="jxgbox" style="width:600px; height:600px;"></div>
+
</html>
<script language="JavaScript">
+
<jsxgraph width="600" height="600" box="box">
var brd = JXG.JSXGraph.initBoard('box', {originX: 300, originY: 300, unitX: 1, unitY: 1});
+
var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-250, 250, 250, -250]});
var t = new JSXTurtleObj(brd);
+
var t = brd.create('turtle');
 
function run() {
 
function run() {
 
   brd.suspendUpdate();
 
   brd.suspendUpdate();
   var code = $('inputtext').value;
+
   var code = document.getElementById('inputtext').value;
 
   if (code=='') { return; }
 
   if (code=='') { return; }
 
   eval(code);
 
   eval(code);
Line 47: Line 55:
 
   t.cs();
 
   t.cs();
 
}
 
}
</script>
+
</jsxgraph>
</html>
 
  
 
===References===
 
===References===
* Peter Baptist, Wolfgang Neidhardt, Alfred Wassermann:'' Symmetry and Regular Polygons'',
+
* Peter Baptist, Wolfgang Neidhardt, Alfred Wassermann:'' Symmetry and Regular Polygons'', Prispevki k poucevanju Matematike, The Improvement of Mathematics Education in Secondary Schools: A Tempus Project, Maribor 1996.
Prispevki k poucevanju Matematike, The Improvement of Mathematics Education in Secondary Schools: A Tempus Project, Maribor 1996  
 
  
 
[[Category:Examples]]
 
[[Category:Examples]]
 +
[[Category:Turtle Graphics]]
 +
[[Category:Fractals]]

Latest revision as of 11:28, 31 January 2013

With turtle graphics it is quite easy to construct regular polygons in a recursive manner.

It is possible to play around with this example: In the last line of the input window there is the command

fracPolygon(5,100,0.4,5);

The meaning of the parameters is

  • 5: number of vertices of the regular polygon,
  • 100: length of a side of the initial polygon,
  • 0.4: shrink factor from one level to the next,
  • 5: number of recursion steps.


References

  • Peter Baptist, Wolfgang Neidhardt, Alfred Wassermann: Symmetry and Regular Polygons, Prispevki k poucevanju Matematike, The Improvement of Mathematics Education in Secondary Schools: A Tempus Project, Maribor 1996.