pop.draw.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * collection on methods that abstract drawing simple shapes
  3. * onto the canvas
  4. *
  5. * @access public
  6. * @return null
  7. *
  8. */
  9. POP.draw = {
  10. clear: function() {
  11. POP.ctx.clearRect(0, 0, POP.W, POP.H);
  12. POP.ctx.fillStyle = "#003466";
  13. POP.ctx.fillRect(0, 0, POP.W, POP.H);
  14. },
  15. rect: function(x, y, w, h, col) {
  16. POP.ctx.fillStyle = col;
  17. POP.ctx.fillRect(x, y, w, h);
  18. },
  19. circle: function(x, y, r, col, stroke) {
  20. POP.ctx.fillStyle = col;
  21. POP.ctx.beginPath();
  22. POP.ctx.arc(x, y, r, 0, Math.PI*2, true);
  23. POP.ctx.closePath();
  24. POP.ctx.fill();
  25. if (stroke) {
  26. POP.ctx.strokeStyle = stroke;
  27. POP.ctx.lineWidth = 2;
  28. POP.ctx.stroke();
  29. }
  30. },
  31. text: function(x, y, str, size, col) {
  32. col = col || '#fff';
  33. size = size || 12;
  34. var font = (size < 13) ? 'SilkscreenExpandedBold, Droid Sans, Monospaced' : 'Sniglet, cursive';
  35. x = (x === 'center')
  36. ? ~~(POP.W / 2) - ((str.length * size) / 2.90 )
  37. : x;
  38. POP.ctx.font = 'bold '+size+'px '+font;
  39. POP.ctx.fillStyle = col;
  40. POP.ctx.fillText(str.toUpperCase(), x, y);
  41. }
  42. };