GabeLinux

Web - 4 - 4

Jan 30th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const WIDTH = 720
  2. const HEIGHT = 480
  3.  
  4. const canvas = document.querySelector('#game')
  5. canvas.width = WIDTH
  6. canvas.height = HEIGHT
  7.  
  8. const ctx = canvas.getContext('2d')
  9.  
  10. ctx.fillStyle = 'white'
  11. ctx.fillRect(0, 0, WIDTH, HEIGHT)
  12.  
  13. // purple rectangle
  14. ctx.fillStyle = 'purple'
  15. ctx.fillRect(450, 50, 200, 200)
  16.  
  17. // grey ellipse
  18. ctx.fillStyle = '#333333'
  19. ctx.beginPath()
  20. ctx.ellipse(350, 350, 50, 75, 45 * Math.PI / 180, 0, 2 * Math.PI)
  21. ctx.fill()
  22.  
  23. // red arc
  24. ctx.strokeStyle = 'red'
  25. ctx.beginPath()
  26. ctx.arc(200, 75, 50, 0, 2 * Math.PI)
  27. ctx.stroke()
  28.  
  29. // blue freeform shape
  30. ctx.strokeStyle = 'blue'
  31. ctx.lineWidth = 5
  32. ctx.beginPath()
  33. ctx.moveTo(100, 150)
  34. ctx.lineTo(100, 250)
  35. ctx.arc(200, 300, 50, 1.5 * Math.PI, 0)
  36. ctx.lineTo(100, 400)
  37. ctx.closePath()
  38. ctx.stroke()
  39.  
  40. // head
  41. ctx.strokeStyle= '#FFA000'
  42. ctx.beginPath()
  43. ctx.arc(600, 350, 75, 0, 2 * Math.PI, false)
  44. ctx.lineWidth = 5
  45. ctx.stroke()
  46.  
  47. // eyes
  48. ctx.fillStyle = '#FFA000'
  49. ctx.beginPath()
  50. ctx.arc(570, 330, 10, 0, 2 * Math.PI, false)
  51. ctx.arc(630, 330, 10, 0, 2 * Math.PI, false)
  52. ctx.fill()
  53.  
  54. // mouth
  55. ctx.strokeStyle= '#FFA000'
  56. ctx.beginPath()
  57. ctx.arc(600, 360, 50, 0, Math.PI, false)
  58. ctx.stroke()
Add Comment
Please, Sign In to add comment