| 1 |
<html> |
| 2 |
<head> |
| 3 |
<title>Spirograph | JSXGraph Example</title> |
| 4 |
<link rel="stylesheet" type="text/css" href="../../distrib/jsxgraph.css" /> |
| 5 |
<script type="text/javascript" src="../../distrib/jsxgraphcore.js"></script> |
| 6 |
</head> |
| 7 |
<body> |
| 8 |
<div id="debug" style="display: none"></div> |
| 9 |
<center> |
| 10 |
<div style="width: 1000px;"> |
| 11 |
<div style="width:500px; height: 510px;"> |
| 12 |
<div id="jxgbox" class="jxgbox" style="width:500px; height:500px; text-align: left; float: left;"></div> |
| 13 |
<div id="polynomials" style="display: none; width: 500px; height: 500px; margin-left: 10px; text-align: left; padding-left: -200px;"></div> |
| 14 |
</div> |
| 15 |
|
| 16 |
<div style="width: 800px; margin-top: 10px;"> |
| 17 |
<form> |
| 18 |
<input type="button" onclick="chooseCoordinateSystem();" value="Choose coordinate system" /> |
| 19 |
<input type="button" onclick="generatePolynomials();" value="Generate system of polynomial equations" /> |
| 20 |
<br /> |
| 21 |
<input type="button" onclick="calculateLocus();" value="Calculate locus" /> |
| 22 |
<input type="button" onclick="showLocusEquation();" value="Show locus equation" /> |
| 23 |
<input type="button" onclick="showBoard();" value="Show board" /> |
| 24 |
<!--br /> |
| 25 |
<input type="button" onclick="extend();" value="Extend the construction" /> |
| 26 |
<input type="button" onclick="extendedLocus();" value="Calculate extended locus" /--> |
| 27 |
<br /> |
| 28 |
<input type="text" value="0.2" id="dim" size="3" /> |
| 29 |
<input type="button" onclick="dimConstruction();" value="Dim construction" /> |
| 30 |
<input type="button" onclick="dimLocus();" value="Dim locus" /> |
| 31 |
<!--input type="button" onclick="dimExtension();" value="Dim extension" /> |
| 32 |
<input type="button" onclick="dimLocus2();" value="Dim extended locus" /--> |
| 33 |
</form> |
| 34 |
</div> |
| 35 |
</div> |
| 36 |
</center> |
| 37 |
<script type="text/javascript"> |
| 38 |
/* <![CDATA[ */ |
| 39 |
|
| 40 |
var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox:[-5,5,5,-5], keepaspectratio:true}); |
| 41 |
var board = brd; |
| 42 |
|
| 43 |
var O = brd.create('point',[0,0],{name:'O',fixed:true, fillColor:'blue', strokeColor:'blue'}); |
| 44 |
var A = brd.create('point',[2,0],{name:'A'}); |
| 45 |
var k = brd.create('circle',[O,A],{name:'k'}); |
| 46 |
|
| 47 |
var B = brd.create('glider',[0.7,1,k],{name:'B drag me'}); |
| 48 |
|
| 49 |
var g1 = brd.create('line',[O,B], {strokeColor:'lightgray'}); |
| 50 |
//var C = brd.create('reflection',[g1,A],{name:'C', fillColor:'blue', strokeColor:'blue'}); |
| 51 |
|
| 52 |
var k2 = brd.create('circle',[O,O.Dist(A)+1], {strokeColor: 'lightgray'}); |
| 53 |
|
| 54 |
var M = brd.create('intersection',[k2,g1,0], {name:'M', fillColor:'blue', strokeColor:'blue'}); |
| 55 |
var k3 = brd.create('circle',[M,B],{name:'k'}); |
| 56 |
|
| 57 |
var gpar = brd.create('parallel',[O,A,M], {name:"g", strokeColor:'lightgray'}); |
| 58 |
var Cprime = brd.create('intersection',[gpar,k3,0], {name:"C'", trace: false, fillColor:'green', strokeColor:'green'}); |
| 59 |
|
| 60 |
var p14_1 = Cprime; |
| 61 |
|
| 62 |
var loc = null; |
| 63 |
|
| 64 |
|
| 65 |
function chooseCoordinateSystem() { |
| 66 |
var k, o; |
| 67 |
document.getElementById('polynomials').style.display = 'none'; |
| 68 |
document.getElementById('jxgbox').style.display = 'block'; |
| 69 |
JXG.Math.Symbolic.generateSymbolicCoordinatesPartial(board, p14_1, 'u', 'brace'); |
| 70 |
|
| 71 |
for(k in board.objects) { |
| 72 |
o = board.objects[k]; |
| 73 |
if(o.elementClass == JXG.OBJECT_CLASS_POINT) { |
| 74 |
o.label.content.setText(o.name + ' (' + o.symbolic.x + ', ' + o.symbolic.y + ')'); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
board.update(); |
| 79 |
JXG.Math.Symbolic.clearSymbolicCoordinates(board); |
| 80 |
} |
| 81 |
|
| 82 |
function generatePolynomials() { |
| 83 |
var res = JXG.Math.Symbolic.generatePolynomials(board, p14_1, true), |
| 84 |
i, out = document.getElementById('polynomials'); |
| 85 |
|
| 86 |
out.innerHTML = '<ul>'; |
| 87 |
for(i=0; i<res.length; i++) |
| 88 |
out.innerHTML += '<li>' + res[i] + ' = 0</li>'; |
| 89 |
out.innerHTML += '</ul>'; |
| 90 |
out.style.display = 'block'; |
| 91 |
document.getElementById('jxgbox').style.display = 'none'; |
| 92 |
} |
| 93 |
|
| 94 |
function calculateLocus() { |
| 95 |
loc = board.create('locus', [p14_1], {strokeColor: 'black', strokeWidth: '2px'}); |
| 96 |
} |
| 97 |
|
| 98 |
function showLocusEquation() { |
| 99 |
var out = document.getElementById('polynomials'); |
| 100 |
|
| 101 |
out.innerHTML = '<ul>'; |
| 102 |
for(i=0; i<loc.eq.length; i++) |
| 103 |
out.innerHTML += '<li>' + loc.eq[i] + ' = 0</li>'; |
| 104 |
out.innerHTML += '</ul>'; |
| 105 |
out.style.display = 'block'; |
| 106 |
document.getElementById('jxgbox').style.display = 'none'; |
| 107 |
} |
| 108 |
|
| 109 |
function showBoard() { |
| 110 |
document.getElementById('polynomials').style.display = 'none'; |
| 111 |
document.getElementById('jxgbox').style.display = 'block'; |
| 112 |
} |
| 113 |
|
| 114 |
function dimConstruction() { |
| 115 |
var c = [O, A, k, B, g1, k2, M, k3, gpar, Cprime/*, C*/], i, o = getDim(); |
| 116 |
|
| 117 |
if(O.visProp['strokeOpacity'] == o) |
| 118 |
o = 1.0; |
| 119 |
|
| 120 |
for(i=0; i<c.length; i++) { |
| 121 |
c[i].setProperty({strokeOpacity: o, fillOpacity: o}); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
function dimLocus() { |
| 126 |
var o = getDim(); |
| 127 |
|
| 128 |
if(loc != null) { |
| 129 |
if(loc.visProp['strokeOpacity'] == o) |
| 130 |
o = 1.0; |
| 131 |
loc.setProperty({strokeOpacity: o}); |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
function dimLocus2() { |
| 136 |
var o = getDim(); |
| 137 |
|
| 138 |
if(loc2 != null) { |
| 139 |
if(loc2.visProp['strokeOpacity'] == o) |
| 140 |
o = 1.0; |
| 141 |
loc2.setProperty({strokeOpacity: o}); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
function extend() { |
| 146 |
if(loc==null) |
| 147 |
return; |
| 148 |
|
| 149 |
board.suspendUpdate(); |
| 150 |
tg = board.create('glider', [loc]); |
| 151 |
|
| 152 |
tc = board.create('circle', [tg, 3]); |
| 153 |
ti = board.create('intersection', [tc, c1, 0]); |
| 154 |
tm = board.create('midpoint', [tg, ti]); |
| 155 |
board.unsuspendUpdate(); |
| 156 |
} |
| 157 |
|
| 158 |
function dimExtension() { |
| 159 |
if(tg == null) |
| 160 |
return; |
| 161 |
|
| 162 |
var c = [tg, tc, ti, tm], i, o = getDim(); |
| 163 |
|
| 164 |
if(tg.visProp['strokeOpacity'] == o) |
| 165 |
o = 1.0; |
| 166 |
|
| 167 |
for(i=0; i<c.length; i++) { |
| 168 |
c[i].setProperty({strokeOpacity: o, fillOpacity: o}); |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
function getDim() { |
| 173 |
return parseFloat(document.getElementById('dim').value); |
| 174 |
} |
| 175 |
|
| 176 |
function extendedLocus() { |
| 177 |
loc2 = board.create('locus', [tm], {strokeColor: 'black', strokeWidth: '2px'}); |
| 178 |
} |
| 179 |
/* ]]> */ |
| 180 |
</script> |
| 181 |
<br/> |
| 182 |
</body> |
| 183 |
</html> |