Add colors and offset

main
sigonasr2 3 years ago
parent 4b14f30509
commit 02a1a2849b
  1. BIN
      bin/sig/Color.class
  2. BIN
      bin/sig/Panel.class
  3. BIN
      bin/sig/PolygonFill.class
  4. 33
      src/sig/Color.java
  5. 20
      src/sig/Panel.java
  6. 1
      src/sig/PolygonFill.java

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,33 @@
package sig;
public class Color {
int r,g,b;
final static public Color BLACK = new Color(0,0,0);
final static public Color RED = new Color(204,0,0);
final static public Color GREEN = new Color(78,154,6);
final static public Color YELLOW = new Color(196,160,0);
final static public Color BLUE = new Color(114,159,207);
final static public Color MAGENTA = new Color(117,80,123);
final static public Color CYAN = new Color(6,152,154);
final static public Color WHITE = new Color(211,215,207);
final static public Color BRIGHT_BLACK = new Color(85,87,83);
final static public Color BRIGHT_RED = new Color(239,41,41);
final static public Color BRIGHT_GREEN = new Color(138,226,52);
final static public Color BRIGHT_YELLOW = new Color(252,233,79);
final static public Color BRIGHT_BLUE = new Color(50,175,255);
final static public Color BRIGHT_MAGENTA = new Color(173,127,168);
final static public Color BRIGHT_CYAN = new Color(52,226,226);
final static public Color BRIGHT_WHITE = new Color(255,255,255);
public Color(int r, int g, int b) {
super();
this.r = r;
this.g = g;
this.b = b;
}
public int getColor() {
return (r<<16)+(g<<16)+b;
}
}

@ -21,6 +21,8 @@ public class Panel extends JPanel implements Runnable {
private ColorModel cm;
int scanLine=0;
int nextScanLine=0;
double x_offset=0;
double y_offset=0;
public Panel() {
super(true);
@ -83,13 +85,16 @@ public class Panel extends JPanel implements Runnable {
int[] p = pixel; // this avoid crash when resizing
//a=h/w
for (int x=0;x<1280;x++) {
for (int y=0;y<720;y++) {
p[y*1280+x]=(0<<16)+(0<<8)+0;
for (int x=0;x<width;x++) {
for (int y=0;y<height;y++) {
p[y*width+x]=(0<<16)+(0<<8)+0;
}
}
FillPolygon(new Point[] {
x_offset=50;
y_offset=50;
FillPolygon(p,Color.BLUE,new Point[] {
new Point(135,2),
new Point(166,96),
new Point(265,97),
@ -103,7 +108,7 @@ public class Panel extends JPanel implements Runnable {
});
}
public void FillPolygon(Point...points) {
public void FillPolygon(int[] p,Color col,Point...points) {
Edge[] edges = new Edge[points.length];
List<Edge> edges_sorted = new ArrayList<Edge>();
for (int i=0;i<points.length;i++) {
@ -141,7 +146,10 @@ public class Panel extends JPanel implements Runnable {
Edge e1 = active_edges.get(i);
Edge e2 = active_edges.get(i+1);
for (int x=(int)Math.round(e1.x_of_min_y);x<=e2.x_of_min_y;x++) {
pixel[scanLine*width+x]=(255<<16)+(0<<8)+0;
int index = (scanLine+(int)y_offset)*width+x+(int)x_offset;
if (index<p.length&&index>=0) {
p[index]=col.getColor();
}
}
}
for (int i=0;i<active_edges.size();i++) {

@ -16,6 +16,7 @@ public class PolygonFill {
while (true) {
p.render();
try {Thread.sleep(20);} catch (InterruptedException e) {}
}
}
}

Loading…
Cancel
Save