فهرست منبع

added rotationAngle to h2d.Graphics.drawEllipse (#434)

Josu Igoa 7 سال پیش
والد
کامیت
c8d9f070ac
2فایلهای تغییر یافته به همراه7 افزوده شده و 4 حذف شده
  1. 2 2
      CHANGELOG.md
  2. 5 2
      h2d/Graphics.hx

+ 2 - 2
CHANGELOG.md

@@ -2,7 +2,7 @@
 
 * haxe 4 preview5+ support
 * added h2d.filter.Outline (Leo Bergman)
-* added h2d.Graphics.drawEllipse (Josu Iga)
+* added h2d.Graphics.drawEllipse (Josu Igoa)
 * added JS custom cursors + hl/js animated cursors support (Pavel Alexandrov)
 * JS sound quality fixes (Pavel Alexandrov)
 * renamed h2d.Sprite to h2d.Object and some other API changes
@@ -15,4 +15,4 @@
 
 ## previous versions
 
-* everything else
+* everything else

+ 5 - 2
h2d/Graphics.hx

@@ -444,15 +444,18 @@ class Graphics extends Drawable {
 		flush();
 	}
 	
-	public function drawEllipse( cx : Float, cy : Float, radiusX : Float, radiusY : Float, nsegments = 0 ) {
+	public function drawEllipse( cx : Float, cy : Float, radiusX : Float, radiusY : Float, rotationAngle : Float = 0, nsegments = 0 ) {
 		flush();
 		if( nsegments == 0 )
 			nsegments = Math.ceil(Math.abs(radiusY * 3.14 * 2 / 4));
 		if( nsegments < 3 ) nsegments = 3;
 		var angle = Math.PI * 2 / nsegments;
+		var x1, y1;
 		for( i in 0...nsegments + 1 ) {
 			var a = i * angle;
-			lineTo(cx + Math.cos(a) * radiusX, cy + Math.sin(a) * radiusY);
+			x1 = Math.cos(a) * Math.cos(rotationAngle) * radiusX - Math.sin(a) * Math.sin(rotationAngle) * radiusY;
+			y1 = Math.cos(rotationAngle) * Math.sin(a) * radiusY + Math.cos(a) * Math.sin(rotationAngle) * radiusX;
+			lineTo(cx + x1, cy + y1);
 		}
 		flush();
 	}