diff --git a/src/sig/JavaProjectTemplate.java b/src/sig/JavaProjectTemplate.java index 4d4f923..168c4e0 100644 --- a/src/sig/JavaProjectTemplate.java +++ b/src/sig/JavaProjectTemplate.java @@ -66,7 +66,7 @@ public class JavaProjectTemplate { game.Draw_Text(10,40,new sig.engine.String("Hello World!"),Font.PROFONT_12); game.Draw_Text_Ext(10,52,new sig.engine.String("Hello World 2!"),Font.PROFONT_36,Color.MAGENTA); - game.Draw_ + game.Fill_Triangle(160,160,190,190,50,250,Color.RED); } public static void main(String[] args) { diff --git a/src/sig/engine/Panel.java b/src/sig/engine/Panel.java index 8f23649..e8fc548 100644 --- a/src/sig/engine/Panel.java +++ b/src/sig/engine/Panel.java @@ -237,7 +237,7 @@ public class Panel extends JPanel implements Runnable,KeyListener { gameInstance.drawGame(); } - public void FillCircle(Color col,double center_x,double center_y,double r) { + public void FillCircle(double center_x,double center_y,double r,Color col) { int counter=0; Point[] points = new Point[CIRCLE_PRECISION]; for (double theta=0;theta edges_sorted = new ArrayList(); for (int i=0;i=0&&y+yy>=0&&x+xx y2) {temp=(int)y1;y1=y2;y2=temp;temp=(int)x1;x1=x2;x2=temp;} + if (y1 > y3) {temp=(int)y1;y1=y3;y3=temp;temp=(int)x1;x1=x3;x3=temp;} + if (y2 > y3) {temp=(int)y2;y2=y3;y3=temp;temp=(int)x2;x2=x3;x3=temp;} + + t1x = t2x = (int)x1; y = (int)y1; // Starting points + dx1 = (int)(x2 - x1); + if (dx1 < 0) { dx1 = -dx1; signx1 = -1; } + else signx1 = 1; + dy1 = (int)(y2 - y1); + + dx2 = (int)(x3 - x1); + if (dx2 < 0) { dx2 = -dx2; signx2 = -1; } + else signx2 = 1; + dy2 = (int)(y3 - y1); + + if (dy1 > dx1) {temp=dx1;dx1=dy1;dy1=temp;changed1 = true; } + if (dy2 > dx2) {temp=dx2;dx2=dy2;dy2=temp;changed2 = true; } + + e2 = (int)(dx2 >> 1); + // Flat top, just process the second half + boolean firstHalfDone=false; + if (y1 == y2) firstHalfDone=true; + if (!firstHalfDone) { + e1 = (int)(dx1 >> 1); + + for (int i = 0; i < dx1;) { + t1xp = 0; t2xp = 0; + if (t1x < t2x) { minx = t1x; maxx = t2x; } + else { minx = t2x; maxx = t1x; } + // process first line until y value is about to change + next0: + while (i < dx1) { + i++; + e1 += dy1; + while (e1 >= dx1) { + e1 -= dx1; + if (changed1) t1xp = signx1;//t1x += signx1; + else { + break next0; + } + } + if (changed1) break; + else t1x += signx1; + } + // Move line + next1: + // process second line until y value is about to change + while (true) { + e2 += dy2; + while (e2 >= dx2) { + e2 -= dx2; + if (changed2) t2xp = signx2;//t2x += signx2; + else { + break next1; + } + } + if (changed2) break; + else t2x += signx2; + } + if (minx > t1x) minx = t1x; + if (minx > t2x) minx = t2x; + if (maxx < t1x) maxx = t1x; + if (maxx < t2x) maxx = t2x; + drawline(minx, maxx, y, col); // Draw line from min to max points found on the y + // Now increase y + if (!changed1) t1x += signx1; + t1x += t1xp; + if (!changed2) t2x += signx2; + t2x += t2xp; + y += 1; + if (y == y2) break; + } + } + // Second half + dx1 = (int)(x3 - x2); if (dx1 < 0) { dx1 = -dx1; signx1 = -1; } + else signx1 = 1; + dy1 = (int)(y3 - y2); + t1x = (int)x2; + + if (dy1 > dx1) { // swap values + temp=dy1;dx1=dy1;dy1=temp; + changed1 = true; + } + else changed1 = false; + + e1 = (int)(dx1 >> 1); + + for (int i = 0; i <= dx1; i++) { + t1xp = 0; t2xp = 0; + if (t1x < t2x) { minx = t1x; maxx = t2x; } + else { minx = t2x; maxx = t1x; } + // process first line until y value is about to change + next3: + while (i < dx1) { + e1 += dy1; + while (e1 >= dx1) { + e1 -= dx1; + if (changed1) { t1xp = signx1; break; }//t1x += signx1; + else break next3; + } + if (changed1) break; + else t1x += signx1; + if (i < dx1) i++; + } + next4: + // process second line until y value is about to change + while (t2x != x3) { + e2 += dy2; + while (e2 >= dx2) { + e2 -= dx2; + if (changed2) t2xp = signx2; + else break next4; + } + if (changed2) break; + else t2x += signx2; + } + + if (minx > t1x) minx = t1x; + if (minx > t2x) minx = t2x; + if (maxx < t1x) maxx = t1x; + if (maxx < t2x) maxx = t2x; + drawline(minx, maxx, y,col); + if (!changed1) t1x += signx1; + t1x += t1xp; + if (!changed2) t2x += signx2; + t2x += t2xp; + y += 1; + if (y > y3) return; + } + } + public void Clear(Color col){ for (int y=0;y