[Japanese][Menu][Home]

Lissajous' curves



I use dojo.js.

JavaScript source

  dojo.require("dojo.gfx.*");
  function myinit() {
    var fld = dojo.byId("fld");
    var canvas = dojo.gfx.createSurface(fld, 200, 200);
    var pathShape = canvas.createPath();
    pathShape.setStroke({color: "red", width: 2});
    var i=4;
    var n=50;
    var y0=100;
    var x0=100;
    pathShape.moveTo(x0,y0);
    for(j=0;j<=2*Math.PI;j+=Math.PI/n/i){
      x=70*Math.sin(i*j);
      y=70*Math.sin((i+1)*j);
      pathShape.lineTo(x0+x,y0-y);
    }
    pathShape.closePath();
  }
  dojo.addOnLoad(myinit);