Advertisement
CaptainSpaceCat

3DPMaze - FrameImage

Jul 19th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. import java.awt.image.*;
  2.  
  3. public class FrameImage extends BufferedImage {
  4.  
  5.   private int w, h;
  6.   private int mW, mH;
  7.   private static final int COLOR_BLACK = -16777216;
  8.   private int s = 500; //size
  9.   private int t = 2; //thickness
  10.  
  11.  
  12.   public FrameImage(int wd, int ht) {
  13.     super(wd, ht, TYPE_INT_ARGB);
  14.     w = wd;
  15.     h = ht;
  16.     this.reset();
  17.   }
  18.  
  19.   public FrameImage(int wd, int ht, int size, int thicc, boolean[][][] m) {
  20.     super(wd, ht, BufferedImage.TYPE_INT_ARGB);
  21.     s = size;
  22.     t = thicc;
  23.     mW = (wd-t*(m.length+1))/m.length;
  24.     mH = (ht-t*(m[0].length+1))/m[0].length;
  25.     w = wd;
  26.     h = ht;
  27.     reset();
  28.     showMaze(m);
  29.   }
  30.  
  31.   public void reset() {
  32.     for (int y = 0; y < h; y++) {
  33.       for (int x = 0; x < w; x++) {
  34.         this.setRGB(x, y, -1);
  35.       }
  36.     }
  37.   }
  38.  
  39.   public void showMaze(boolean[][][] m) {
  40.     for (int i = mW+t; i < w; i++) {
  41.       for (int n = 0; n < t; n++) {
  42.         this.setRGB(i, n, COLOR_BLACK);
  43.       }
  44.     }
  45.     for (int i = 0; i < w-mW-t; i++) {
  46.       for (int n = 0; n < t; n++) {
  47.         this.setRGB(i, h-1-n, COLOR_BLACK);
  48.       }
  49.     }
  50.     for (int i = 0; i < h; i++) {
  51.       for (int n = 0; n < t; n++) {
  52.         this.setRGB(n, i, COLOR_BLACK);
  53.         this.setRGB(w-1-n, i, COLOR_BLACK);
  54.       }
  55.     }
  56.    
  57.     for (int y = 0; y < m[0].length; y++) {
  58.       for (int x = 0; x < m.length; x++) {
  59.         if (m[x][y][1] && x < m.length-1) {
  60.           for (int i = (mH+t)*y; i < (mH+t)*(y+1)+t; i++) {
  61.             for (int n = 0; n < t; n++) {
  62.               this.setRGB((mW+t)*(x+1)+n, i, COLOR_BLACK);
  63.             }
  64.           }
  65.         }
  66.         if (m[x][y][2] && y < m[0].length-1) {
  67.           for (int i = (mW+t)*x; i < (mW+t)*(x+1)+t; i++) {
  68.             for (int n = 0; n < t; n++) {
  69.               this.setRGB(i, (mH+t)*(y+1)+n, COLOR_BLACK);
  70.             }
  71.           }
  72.         }
  73.       }
  74.     }
  75.   }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement