# Difference between revisions of "Spirograph"

From JSXGraph Wiki

Jump to navigationJump to searchA WASSERMANN (talk | contribs) |
A WASSERMANN (talk | contribs) |
||

Line 1: | Line 1: | ||

<jsxgraph width="600" height="600"> | <jsxgraph width="600" height="600"> | ||

var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox:[-5,5,5,-5], kkeepaspectratio:true}); | var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox:[-5,5,5,-5], kkeepaspectratio:true}); | ||

+ | var R = 2.0; | ||

+ | var r = brd.create('slider',[[-3,4],[3,4],[-5,1,5]],{name:'r'}); | ||

+ | var a = brd.create('slider',[[-3,3],[3,3],[-5,1,5]],{name:'a'}); | ||

+ | |||

+ | var c = brd.create('curve',[ | ||

+ | function(t){ | ||

+ | var r1 = r.Value(); | ||

+ | return (R-r1)*Math.cos(r1/R*t)+a.Value()*Math.cos((1-r1/R)*t); | ||

+ | }, | ||

+ | function(t){ | ||

+ | var r1 = r.Value(); | ||

+ | return (R-r1)*Math.sin(r1/R*t)+a.Value()*Math.sin((1-r1/R)*t); | ||

+ | } | ||

+ | }, {strokeWidth:3, strokeColor:'3355ff', strokeOpacity:0.7}); | ||

</jsxgraph> | </jsxgraph> |