getWidth() public method

public getWidth ( ) : int
return int
コード例 #1
0
ファイル: Layer.cs プロジェクト: N3X15/VoxelSim
		public Layer(Channel r, Channel g, Channel b) {
			this.width = r.getWidth();
			this.height = r.getHeight();
			this.r = r;
			this.g = g;
			this.b = b;
			this.a = null;
		}
コード例 #2
0
ファイル: Layer.cs プロジェクト: N3X15/VoxelSim
		public Layer(Layer rgb, Channel a) {
			this.r = rgb.r;
			this.g = rgb.g;
			this.b = rgb.b;
			this.width = r.getWidth();
			this.height = r.getHeight();
			this.a = a;
		}
コード例 #3
0
ファイル: Layer.cs プロジェクト: N3X15/VoxelSim
		public Layer(Channel r, Channel g, Channel b, Channel a) {
			this.width = r.getWidth();
			this.height = r.getHeight();
			if(!(g.getWidth() == width
				&& b.getWidth() == width
				&& g.getHeight() == height
				&& b.getHeight() == height
				&& (a == null || (a.getWidth() == width && a.getHeight() == height))))
				throw new Exception("trying to combine channels of differing sizes");
			this.r = r;
			this.g = g;
			this.b = b;
			this.a = a;
		}
コード例 #4
0
ファイル: Layer.cs プロジェクト: N3X15/Procedurality4NET
 public Layer tile(int new_width, int new_height)
 {
     r = r.tile(new_width, new_height);
     g = g.tile(new_width, new_height);
     b = b.tile(new_width, new_height);
     if (a != null) {
         a = a.tile(new_width, new_height);
     }
     width = r.getWidth();
     height = r.getHeight();
     return this;
 }
コード例 #5
0
ファイル: Layer.cs プロジェクト: N3X15/Procedurality4NET
 public Layer rotate(int degrees)
 {
     r = r.rotate(degrees);
     g = g.rotate(degrees);
     b = b.rotate(degrees);
     if (a != null) {
         a = a.rotate(degrees);
     }
     width = r.getWidth();
     height = r.getHeight();
     return this;
 }
コード例 #6
0
ファイル: Layer.cs プロジェクト: N3X15/Procedurality4NET
 public Layer cropWrap(int x_lo, int y_lo, int x_hi, int y_hi)
 {
     r = r.cropWrap(x_lo, y_lo, x_hi, y_hi);
     g = g.cropWrap(x_lo, y_lo, x_hi, y_hi);
     b = b.cropWrap(x_lo, y_lo, x_hi, y_hi);
     if (a != null) {
         a = a.cropWrap(x_lo, y_lo, x_hi, y_hi);
     }
     width = r.getWidth();
     height = r.getHeight();
     return this;
 }
コード例 #7
0
ファイル: Layer.cs プロジェクト: N3X15/Procedurality4NET
 public Layer bumpSpecular(Channel bumpmap, float lx, float ly, float lz, float shadow, float light_r, float light_g, float light_b, int specular)
 {
     if(!(bumpmap.getWidth() == width && bumpmap.getHeight() == height))
         throw new Exception("bumpmap size does not match layer size");
     float lnorm = (float)Math.Sqrt(lx*lx + ly*ly + lz*lz);
     float nz = 4*(1f/Math.Min(width, height));
     float nzlz = nz*lz;
     float nz2 = nz*nz;
     int power = 2<<specular;
     for (int y = 0; y < height; y++) {
         for (int x = 0; x < width; x++) {
             float nx = bumpmap.getPixelWrap(x + 1, y) - bumpmap.getPixelWrap(x - 1, y);
             float ny = bumpmap.getPixelWrap(x, y + 1) - bumpmap.getPixelWrap(x, y - 1);
             float brightness = nx*lx + ny*ly;
             float costheta = (brightness + nzlz)/((float)Math.Sqrt(nx*nx + ny*ny + nz2)*lnorm);
             float highlight;
             if (costheta > 0) {
                 highlight = (float)Math.Pow(costheta, power);
             } else {
                 highlight = 0;
             }
             putPixelClip(x, y,
                 (r.getPixel(x, y) + highlight*light_r)*(bumpmap.getPixel(x, y)*shadow + 1 - shadow),
                 (g.getPixel(x, y) + highlight*light_g)*(bumpmap.getPixel(x, y)*shadow + 1 - shadow),
                 (b.getPixel(x, y) + highlight*light_b)*(bumpmap.getPixel(x, y)*shadow + 1 - shadow));
         }
     }
     return this;
 }
コード例 #8
0
ファイル: Layer.cs プロジェクト: N3X15/Procedurality4NET
 public Layer bumpFast(Channel bumpmap, float lx, float light, float ambient)
 {
     if(!(bumpmap.getWidth() == width && bumpmap.getHeight() == height))
         throw new Exception("bumpmap size does not match layer size");
     ambient = 1f - ambient;
     for (int y = 0; y < height; y++) {
         for (int x = 0; x < width; x++) {
             float brightness = lx*(bumpmap.getPixelWrap(x + 1, y) - bumpmap.getPixelWrap(x - 1, y));
             if (brightness >= 0) {
                 brightness = brightness*light;
                 putPixel(x, y, r.getPixel(x, y) + brightness,
                     g.getPixel(x, y) + brightness,
                     b.getPixel(x, y) + brightness);
             } else {
                 brightness = brightness*ambient;
                 putPixel(x, y, r.getPixel(x, y) + brightness,
                     g.getPixel(x, y) + brightness,
                     b.getPixel(x, y) + brightness);
             }
         }
     }
     return this;
 }
コード例 #9
0
ファイル: Layer.cs プロジェクト: N3X15/Procedurality4NET
 public Layer bump(Channel bumpmap, float lx, float ly, float shadow, float light_r, float light_g, float light_b, float ambient_r, float ambient_g, float ambient_b)
 {
     if(!(bumpmap.getWidth() == width && bumpmap.getHeight() == height))
         throw new Exception("bumpmap size does not match layer size");
     for (int y = 0; y < height; y++) {
         for (int x = 0; x < width; x++) {
             float nx = bumpmap.getPixelWrap(x + 1, y) - bumpmap.getPixelWrap(x - 1, y);
             float ny = bumpmap.getPixelWrap(x, y + 1) - bumpmap.getPixelWrap(x, y - 1);
             float brightness = nx*lx + ny*ly;
             if (brightness >= 0) {
                 putPixelClip(x, y, (r.getPixel(x, y) + brightness*light_r)*(bumpmap.getPixel(x, y)*shadow + 1 - shadow),
                     (g.getPixel(x, y) + brightness*light_g)*(bumpmap.getPixel(x, y)*shadow + 1 - shadow),
                     (b.getPixel(x, y) + brightness*light_b)*(bumpmap.getPixel(x, y)*shadow + 1 - shadow));
             } else {
                 putPixelClip(x, y, (r.getPixel(x, y) + brightness*(1 - ambient_r))*(bumpmap.getPixel(x, y)*shadow + 1 - shadow),
                     (g.getPixel(x, y) + brightness*(1 - ambient_g))*(bumpmap.getPixel(x, y)*shadow + 1 - shadow),
                     (b.getPixel(x, y) + brightness*(1 - ambient_b))*(bumpmap.getPixel(x, y)*shadow + 1 - shadow));
             }
         }
     }
     return this;
 }
コード例 #10
0
ファイル: Channel.cs プロジェクト: N3X15/VoxelSim
		public Channel placeDarkest(Channel sprite, int x_offset, int y_offset) {
			for (int y = y_offset; y < y_offset + sprite.getHeight(); y++) {
				for (int x = x_offset; x < x_offset + sprite.getWidth(); x++) {
					putPixelWrap(x, y, Math.Min(getPixelWrap(x, y), sprite.getPixelWrap(x - x_offset, y - y_offset)));
				}
			}
			return this;
		}
コード例 #11
0
ファイル: Channel.cs プロジェクト: N3X15/VoxelSim
		public Channel place(Channel sprite, Channel alpha, int x_offset, int y_offset) {
			float alpha_val;
			for (int y = y_offset; y < y_offset + sprite.getHeight(); y++) {
				for (int x = x_offset; x < x_offset + sprite.getWidth(); x++) {
					alpha_val = alpha.getPixel(x - x_offset, y - y_offset);
					putPixelWrap(x, y, alpha_val*sprite.getPixelWrap(x - x_offset, y - y_offset) + (1 - alpha_val)*getPixelWrap(x, y));
				}
			}
			return this;
		}
コード例 #12
0
ファイル: Channel.cs プロジェクト: N3X15/VoxelSim
		public Channel bump(Channel bumpmap, float lx, float ly, float shadow, float light, float ambient) {
			if(!(bumpmap.getWidth() == width && bumpmap.getHeight() == height))
				throw new Exception("bumpmap does not match channel size");
			Channel channel = new Channel(width, height);
			for (int y = 0; y < height; y++) {
				for (int x = 0; x < width; x++) {
					float nx = bumpmap.getPixelWrap(x + 1, y) - bumpmap.getPixelWrap(x - 1, y);
					float ny = bumpmap.getPixelWrap(x, y + 1) - bumpmap.getPixelWrap(x, y - 1);
					float brightness = nx*lx + ny*ly;
					if (brightness >= 0) {
						channel.putPixelClip(x, y, (getPixel(x, y) + brightness*light)*(bumpmap.getPixel(x, y)*shadow + 1 - shadow));
					} else {
						channel.putPixelClip(x, y, (getPixel(x, y) + brightness*(1 - ambient))*(bumpmap.getPixel(x, y)*shadow + 1 - shadow));
					}
				}
			}
			pixels = channel.getPixels();
			return this;
		}
コード例 #13
0
ファイル: Main.cs プロジェクト: N3X15/Procedurality4NET
 public static Channel LoadTerrain(String file)
 {
     using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         Bitmap bitmap = new Bitmap(stream);
         try
         {
             Channel terrain = new Channel(bitmap.Width, bitmap.Height);
             Console.WriteLine("LOADED {0}x{1} BITMAP!", bitmap.Height, bitmap.Width);
             for (int x = 0; x < bitmap.Width; x++)
             {
                 for (int y = 0; y < bitmap.Height; y++)
                 {
                     terrain.putPixel(x, y, bitmap.GetPixel(x, y).GetBrightness());
                 }
             }
             Console.WriteLine("LOADED {0}x{1} CHANNEL!", terrain.getHeight(), terrain.getWidth());
             return terrain;//.invert();
         }
         catch (IOException)
         {
             Console.WriteLine("Cannot find " + file + ", using blank channel.");
             return new Channel(256, 256);
         }
     }
 }