Requires

Provides

Shapes for ART

Authors:
[Valerio Proietti](http://mad4milk.net), [Sebastian Markbåge](http://calyptus.eu/)
  1. 12
  2. 13
  3. 14
  4. 15
  5. 16
  6. 17
  7. 18
  8. 19
  9. 20
  10. 21
  11. 22
  12. 23
  13. 24
  14. 25
  15. 26
  16. 27
  17. 28
  18. 29
  19. 30
  20. 31
  21. 32
  22. 33
  23. 34
  24. 35
  25. 36
  26. 37
  27. 38
  28. 39
  29. 40
  30. 41
  31. 42
  32. 43
  33. 44
  34. 45
  35. 46
  36. 47
  37. 48
  38. 49
  39. 50
  40. 51
  41. 52
  42. 53
  43. 54
  44. 55
  45. 56
  46. 57
  47. 58
  48. 59
  49. 60
  50. 61
  51. 62
  52. 63
  53. 64
  54. 65
  55. 66
  56. 67
  57. 68
  58. 69
  59. 70
  60. 71
  61. 72
  62. 73
  63. 74
  64. 75
  65. 76
  66. 77
  67. 78
  68. 79
  69. 80
  70. 81
  71. 82
  72. 83
  73. 84
  74. 85
  75. 86
  76. 87
  77. 88
  78. 89
  79. 90
  80. 91
  81. 92
  82. 93
  83. 94
  84. 95
  85. 96
  86. 97
  87. 98
  88. 99
  89. 100
  90. 101
  91. 102
  92. 103
  93. 104
  94. 105
  95. 106
  96. 107
  97. 108
  98. 109
  99. 110
  100. 111
  101. 112
  102. 113
  103. 114
  104. 115
  105. 116
  106. 117
  107. 118
  108. 119
  109. 120
  110. 121
  111. 122
  112. 123
  113. 124
  114. 125
  115. 126
  116. 127
  117. 128
  118. 129
  119. 130
  120. 131
  121. 132
  122. 133
  123. 134
  124. 135
  125. 136
  126. 137
ART.Rectangle = new Class({ Extends: ART.Shape, initialize: function(width, height, radius){ this.parent(); if (width != null && height != null) this.draw(width, height, radius); }, draw: function(width, height, radius){ var path = new ART.Path; if (!radius){ path.move(0, 0).line(width, 0).line(0, height).line(-width, 0).line(0, -height); } else { if (typeof radius == 'number') radius = [radius, radius, radius, radius]; var tl = radius[0], tr = radius[1], br = radius[2], bl = radius[3]; if (tl < 0) tl = 0; if (tr < 0) tr = 0; if (bl < 0) bl = 0; if (br < 0) br = 0; path.move(0, tl); if (width < 0) path.move(width, 0); if (height < 0) path.move(0, height); if (tl > 0) path.arc(tl, -tl); path.line(Math.abs(width) - (tr + tl), 0); if (tr > 0) path.arc(tr, tr); path.line(0, Math.abs(height) - (tr + br)); if (br > 0) path.arc(-br, br); path.line(- Math.abs(width) + (br + bl), 0); if (bl > 0) path.arc(-bl, -bl); path.line(0, - Math.abs(height) + (bl + tl)); } path.close(); return this.parent(path, width, height); } }); ART.Pill = new Class({ Extends: ART.Rectangle, draw: function(width, height){ return this.parent(width, height, ((width < height) ? width : height) / 2); } }); ART.Ellipse = new Class({ Extends: ART.Shape, initialize: function(width, height){ this.parent(); if (width != null && height != null) this.draw(width, height); }, draw: function(width, height){ var path = new ART.Path; var rx = width / 2, ry = height / 2; path.move(0, ry).arc(width, 0, rx, ry).arc(-width, 0, rx, ry); path.close(); return this.parent(path, width, height); } }); ART.Wedge = new Class({ Extends: ART.Shape, initialize: function(innerRadius, outerRadius, startAngle, endAngle){ this.parent(); if (innerRadius != null || outerRadius != null) this.draw(innerRadius, outerRadius, startAngle, endAngle); }, draw: function(innerRadius, outerRadius, startAngle, endAngle){ var path = new ART.Path; var circle = Math.PI * 2, radiansPerDegree = Math.PI / 180, sa = startAngle * radiansPerDegree % circle || 0, ea = endAngle * radiansPerDegree % circle || 0, ir = Math.min(innerRadius || 0, outerRadius || 0), or = Math.max(innerRadius || 0, outerRadius || 0), a = sa > ea ? circle - sa + ea : ea - sa; if (a >= circle){ path.move(0, or).arc(or * 2, 0, or).arc(-or * 2, 0, or); if (ir) path.move(or - ir, 0).counterArc(ir * 2, 0, ir).counterArc(-ir * 2, 0, ir); } else { var ss = Math.sin(sa), es = Math.sin(ea), sc = Math.cos(sa), ec = Math.cos(ea), ds = es - ss, dc = ec - sc, dr = ir - or, large = a > Math.PI; path.move(or + or * ss, or - or * sc).arc(or * ds, or * -dc, or, or, large).line(dr * es, dr * -ec); if (ir) path.counterArc(ir * -ds, ir * dc, ir, ir, large); } path.close(); return this.parent(path, or * 2, or * 2); } });