From 6f6e47281dcd010162a1287efa758173180d2fee Mon Sep 17 00:00:00 2001 From: NicoNicoNii Date: Thu, 1 Dec 2022 21:21:29 -0600 Subject: [PATCH] #10 Co-authored-by: sigonasr2 --- src/sig/JavaProjectTemplate.java | 2 + src/sig/engine/Edge.java | 33 -------- src/sig/engine/Panel.java | 133 +++++-------------------------- 3 files changed, 22 insertions(+), 146 deletions(-) delete mode 100644 src/sig/engine/Edge.java diff --git a/src/sig/JavaProjectTemplate.java b/src/sig/JavaProjectTemplate.java index dddd1ba..e57cdee 100644 --- a/src/sig/JavaProjectTemplate.java +++ b/src/sig/JavaProjectTemplate.java @@ -86,6 +86,8 @@ public class JavaProjectTemplate { game.Draw(100,20,Color.BLACK); //That's not a dead pixel, it's a black one! game.Draw_Line(10,10,35,35,Color.BLACK); //Line Drawing + game.FillCircle(WINDOW_WIDTH/2, WINDOW_HEIGHT/2, 100, Color.BLACK); + game.Draw_Sprite(450,75,bookSpr,Color.GREEN); //Sprite drawing (with green tint) game.Draw_Sprite(450,75+bookSpr.getHeight(),bookSpr,Transform.VERTICAL); //Sprite drawing with vertical flip diff --git a/src/sig/engine/Edge.java b/src/sig/engine/Edge.java deleted file mode 100644 index 97a01b9..0000000 --- a/src/sig/engine/Edge.java +++ /dev/null @@ -1,33 +0,0 @@ -package sig.engine; - -public class Edge { - Point a,b; - int min_y; - int max_y; - int min_x; - int max_x; - double x_of_min_y; - double inverse_slope; - public Edge(Point a, Point b) { - super(); - this.a = a; - this.b = b; - min_y=Math.min(a.y, b.y); - max_y=Math.max(a.y, b.y); - min_x=Math.min(a.x, b.x); - max_x=Math.max(a.x, b.x); - if (a.y==min_y) { - x_of_min_y=a.x; - } else { - x_of_min_y=b.x; - } - - inverse_slope=(double)(a.x-b.x)/(a.y-b.y); - } - @Override - public java.lang.String toString() { - return "Edge [a=" + a + ", b=" + b + ", min_y=" + min_y + ", max_y=" + max_y + ", min_x=" + min_x + ", max_x=" - + max_x + ", x_of_min_y=" + x_of_min_y + ", inverse_slope=" + inverse_slope + "]"; - } - -} diff --git a/src/sig/engine/Panel.java b/src/sig/engine/Panel.java index b804a9b..6d82b08 100644 --- a/src/sig/engine/Panel.java +++ b/src/sig/engine/Panel.java @@ -5,7 +5,6 @@ import java.awt.Toolkit; import java.awt.image.ColorModel; import java.awt.image.MemoryImageSource; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; @@ -268,138 +267,46 @@ public class Panel extends JPanel implements Runnable,KeyListener { } public void FillCircle(double center_x,double center_y,double r,Color col) { - int counter=0; - List> points = new ArrayList>(); + List> points = new ArrayList>(); + points.add(new Point(center_x,center_y)); for (double theta=0;theta((int)(Math.round(Math.sin(theta)*r+center_x)),(int)(Math.round(Math.cos(theta)*r+center_y)))); + points.add(new Point((double)(Math.round(Math.sin(theta)*r+center_x)),(double)(Math.round(Math.cos(theta)*r+center_y)))); } - FillPolygon(0,0,col,points); + FillPolygon(0d,0d,col,points,PolygonStructure.FAN); } public void FillOval(double center_x,double center_y,double w,double h,Color col) { - int counter=0; - List> points = new ArrayList>(); + List> points = new ArrayList>(); double r = Math.max(w,h); double ratio = Math.min(w,h)/r; + points.add(new Point(center_x,center_y)); for (double theta=0;theta newP = new Point((int)(Math.round(Math.sin(theta)*r)),(int)(Math.round(Math.cos(theta)*r))); + Point newP = new Point((double)(Math.round(Math.sin(theta)*r)),(double)(Math.round(Math.cos(theta)*r))); if (w>points) { - Edge[] edges = new Edge[points.size()]; - List edges_sorted = new ArrayList(); - for (int i=0;i=edges[i].min_y) { - edges_sorted.add(j,edges[i]); - inserted=true; - break; - } - } - if (!inserted) { - edges_sorted.add(edges[i]); - } - } - } - } - //System.out.println(edges_sorted); - List active_edges = new ArrayList(); - scanLine = edges_sorted.get(0).min_y-1; - nextScanLine = scanLine+1; - do { - for (int i=0;i=active_edges.size()-1) break; - Edge e1 = active_edges.get(i); - Edge e2 = active_edges.get(i+1); - //System.out.println("Drawing from "+((int)Math.round(e1.x_of_min_y))+" to "+e2.x_of_min_y+" on line "+scanLine); - for (int x=(int)Math.round(e1.x_of_min_y);x<=e2.x_of_min_y;x++) { - if (x<0||x>JavaProjectTemplate.WINDOW_WIDTH) continue; - int index = (scanLine+(int)y_offset)*getWidth()+x+(int)x_offset; - if (index=0) { - Draw(index,col.getColor()); - } - } - } - List new_active_edges = new ArrayList(); - for (int i=0;ie.x_of_min_y) { - new_active_edges.add(j,e); - inserted=true; - break; - } - } - if (!inserted) { - new_active_edges.add(e); - } - } - active_edges=new_active_edges; - GetNextScanLineEdges(edges_sorted, active_edges); - } - while (active_edges.size()>0); + public void FillPolygon(double x_offset,double y_offset,Color col,List>points,PolygonStructure structure) { + List> tex = new ArrayList<>(); + List cols = new ArrayList<>(); + for (int i=0;i((double)0,(double)0)); + cols.add(col); + } + FillTexturedPolygon(points,tex,cols,null,structure); } - private void GetNextScanLineEdges(List edges_sorted, List active_edges) { - if (scanLine==nextScanLine) { - for (int i=0;iscanLine) { - nextScanLine=e.min_y; - break; - } - } - } - } - public void Draw(int x, int y, Color col) { if (x<0||y<0||x>=JavaProjectTemplate.WINDOW_WIDTH||y>=JavaProjectTemplate.WINDOW_HEIGHT) return; Draw(y*JavaProjectTemplate.WINDOW_WIDTH+x,col.getColor());