JavaScript Javascript and Canvas Draw Circle with Hole in Middle javascript canvas draw circle,javascript canvas draw line,javascript canvas

I want to draw something like a donut, so a circle with a hole in the middle. I tried using ctx.clip(), but I realized it limits the path to inside, and I want it to limit the path to the outside.

Things to note:
this.lineWidth is how thick the "rim" or the outside portion is

    ctx.beginPath();
    // this should be the hole
    ctx.arc(this.x,this.y,this.r,0,Math.PI*2,false);
    ctx.clip();
    // this should be the outside part
    ctx.arc(this.x,this.y,this.r+this.lineWidth,0,Math.PI*2,false);
    ctx.fillStyle = "#00ff00";
    ctx.fill();

Instead I'm getting a filled-in circle because it's limiting the path to inside the smaller arc instead of outside it. Is there another method that does the opposite of clip()?

Answer:1

I found this solution http://jsfiddle.net/Hnw6a/:

var can = document.getElementById('canvas1');
var ctx = can.getContext('2d');

//ctx.arc(x,y,radius,startAngle,endAngle, anticlockwise);  

ctx.beginPath()
ctx.arc(100,100,100,0,Math.PI*2, false); // outer (filled)
ctx.arc(100,100,55,0,Math.PI*2, true); // outer (unfills it)
ctx.fill();

With following canvas node:

<canvas id="canvas1" width="500" height="500"></canvas>
Answer:2

I'm using Sly Slider with a free wordpress theme. I've enqueued properly the js file, set the html markup and wrote a jquery function according to the documentation but cannot to seem to get it to ...

I'm using Sly Slider with a free wordpress theme. I've enqueued properly the js file, set the html markup and wrote a jquery function according to the documentation but cannot to seem to get it to ...

  1. slider initial bracelet
  2. slider initial value
  3. initialize slider jquery
  4. initialize slider
  5. initial slider necklace
  6. initialize slider bootstrap
  7. slick slider init
  8. slick slider initialize
  9. slick slider init event
  10. slick slider initialslide
  11. slick slider initialize on click
  12. slick slider init not working
  13. slick slider init function
  14. slick slider init event not working
  15. slick slider init not firing
  16. slick slider initialize event
  17. slick slider init callback
  18. jquery slider initial value
  19. swiper slider init
  20. slick slider initialize hidden

Good day, I have received the following error: Uncaught Error: Syntax error, unrecognized expression: a[href*=#]:not([href=#]) for the library jquery-2.2.3.min.js:2 Below is the code: $(document)...

Good day, I have received the following error: Uncaught Error: Syntax error, unrecognized expression: a[href*=#]:not([href=#]) for the library jquery-2.2.3.min.js:2 Below is the code: $(document)...

  1. uncaught error syntax error unrecognized expression
  2. uncaught error syntax error unrecognized
  3. uncaught error syntax error unrecognized expression #

I'm trying to run a super simple program with javascript but I just can't get my head around this issue. Ok here my code: var answer = prompt("Are we there yet?"); while(answer != "yes" || answer != ...

I'm trying to run a super simple program with javascript but I just can't get my head around this issue. Ok here my code: var answer = prompt("Are we there yet?"); while(answer != "yes" || answer != ...

  1. the while loop
  2. the while loop in python
  3. the while loop in c
  4. the while loop in java
  5. the while loop javascript
  6. the while loop in c programming
  7. the while loop condition
  8. the while loop algorithm
  9. the while loop in pascal

I like to use Javascript's split method to split a string like the one below into an array on every blank white line. How can I accomplish this. Splitting on \n doesn't because I'd like each ...

I like to use Javascript's split method to split a string like the one below into an array on every blank white line. How can I accomplish this. Splitting on \n doesn't because I'd like each ...

  1. split string blank space java
  2. split string blank space c#
  3. split string blank python
  4. split string blank
  5. string split blank space
  6. split string by blank space python
  7. powershell split string blank space
  8. java split string blank
  9. ruby split string blank
  10. r split string by blank
  11. bash split string by blank
  12. excel split string by blank
  13. powershell split string on blank line
  14. sql split string by blank
  15. php split string blank space