source: trunk/examples/script/context2d/scripts/translate.js@ 168

Last change on this file since 168 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 766 bytes
Line 
1 var ctx = document.getElementById('tutorial').getContext('2d');
2 ctx.fillRect(0,0,300,300);
3 for (var i=0;i<3;i++) {
4 for (var j=0;j<3;j++) {
5 ctx.save();
6 ctx.strokeStyle = "#9CFF00";
7 ctx.translate(50+j*100,50+i*100);
8 drawSpirograph(ctx,20*(j+2)/(j+1),-8*(i+3)/(i+1),10);
9 ctx.restore();
10 }
11 }
12
13function drawSpirograph(ctx,R,r,O){
14 var x1 = R-O;
15 var y1 = 0;
16 var i = 1;
17 ctx.beginPath();
18 ctx.moveTo(x1,y1);
19 do {
20 if (i>20000) break;
21 var x2 = (R+r)*Math.cos(i*Math.PI/72) - (r+O)*Math.cos(((R+r)/r)*(i*Math.PI/72))
22 var y2 = (R+r)*Math.sin(i*Math.PI/72) - (r+O)*Math.sin(((R+r)/r)*(i*Math.PI/72))
23 ctx.lineTo(x2,y2);
24 x1 = x2;
25 y1 = y2;
26 i++;
27 } while (x2 != R-O && y2 != 0 );
28 ctx.stroke();
29}
Note: See TracBrowser for help on using the repository browser.