Hi All, 

As per the below example, i did draw a circle on 50, 50 (x,y) with radius 50 

This means the circumference should touch the top left - that does not happen 
with the below code.

Any help ?

Regards,
Muthu Veerappan


<?xml version="1.0" encoding="UTF-8" ?>
<canvas width="300" height="300" debug="false" >
    <class name="circle" extends="drawview" >
        <attribute name="circlecolor" value="white"/>
        <attribute name="r" value="100"/>
        <handler name="oninit">
          this.redraw();
        </handler>
        <handler name="onr">
          this.redraw();
        </handler>
        <method name="redraw" ><![CDATA[
            this.clear();
            this.beginPath();
            this.moveTo(x+r, y);
            var a = Math.tan(22.5 * Math.PI/180);
            for (var angle = 45; angle<=360; angle += 45) {
                // endpoint:
                var endx = r*Math.cos(angle*Math.PI/180);
                var endy = r*Math.sin(angle*Math.PI/180);
                // control:
                // (angle-90 is used to give the correct sign)
                var cx =endx + r*a*Math.cos((angle-90)*Math.PI/180);
                var cy =endy + r*a*Math.sin((angle-90)*Math.PI/180);
                this.quadraticCurveTo(cx+x, cy+y, endx+x, endy+y);
            }
          
            var g = this.createLinearGradient(0, 0, 8, x+r, y+r, 0)
            this.globalAlpha = 1;
            g.addColorStop(0, 0xffffff);
            this.globalAlpha = 0;
            g.addColorStop(1, this.circlecolor);
            this.fillStyle = g;
            this.fill()
            this.globalAlpha = 1;
            this.linewidth= 5;
            this.stroke();
        ]]>
        </method>
    </class>

    <circle r="50" x="50" y="50" circlecolor="blue"/>
     
</canvas>


Reply via email to