Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. function drawCircle(ctx, cx, cy, r) {
  2. ctx.clearRect(0, 0,canvas.width, canvas.height);
  3. $("#input-form").empty();
  4. $("#input-form").append(
  5. '<label for="x">x</label><input name="x" id="x" type="number" value='+ cx +'>'+
  6. '<label for="y">y</label><input name="y" id="y" type="number" value='+ cy +'>'+
  7. '<label for="r">r</label><input name="r" id="r" type="number" value=' + r +'>'
  8. );
  9. $("#redraw").click(function(){
  10. console.log($("#x").val());
  11. drawCircle(ctx, $("#x").val(), $('#y').val(), $('#r').val());
  12. });
  13. var d = (5 - r * 4) / 4;
  14. var x = 0;
  15. var y = r;
  16. do {
  17. drawPixel(ctx, cx + x, cy + y);
  18. drawPixel(ctx, cx + x, cy - y);
  19. drawPixel(ctx, cx - x, cy + y);
  20. drawPixel(ctx, cx - x, cy - y);
  21. drawPixel(ctx, cx + y, cy + x);
  22. drawPixel(ctx, cx + y, cy - x);
  23. drawPixel(ctx, cx - y, cy + x);
  24. drawPixel(ctx, cx - y, cy - x);
  25. if (d < 0) {
  26. d = d + (2 * x + 1);
  27. } else {
  28. d = d + (2 * (x - y) + 1);
  29. y = y - 1;
  30. }
  31. x = x + 1;
  32. }
  33. while (x <= y);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement