Procedurality.Channel.offset C# (CSharp) Method

offset() public method

public offset ( int x_offset, int y_offset ) : Channel
x_offset int
y_offset int
return Channel
		public Channel offset(int x_offset, int y_offset) {
			Channel channel = new Channel(width, height);
			for (int y = 0; y < height; y++) {
				for (int x = 0; x < width; x++) {
					channel.putPixel(x, y, getPixelWrap(x - x_offset, y - y_offset));
				}
			}
			pixels = channel.getPixels();
			return this;
		}
	

Usage Example

コード例 #1
0
ファイル: Channel.cs プロジェクト: N3X15/VoxelSim
		public Channel[] fft() {
			if(!(width == height))
				throw new Exception("square images only");
			int size = width;
			if(!(Utils.isPowerOf2(size)))
				throw new Exception("size must be power of 2");
	
			// convert channel to complex number array
			float[] a = new float[size*size*2 + 1];
			int n = 1;
			for (int x = 0; x < size; x++) {
				for (int y = 0; y < size; y++) {
					a[n] = getPixel(x, y);
					n += 2;
				}
			}
	
			// perform fast fourier transform
			fastFourierTransform(a, size, 1);
	
			// convert complex number array to channels
			n = 1;
			Channel magnitude = new Channel(size, size);
			Channel phase = new Channel(size, size);
			float real, imag;
			for (int x = 0; x < size; x++) {
				for (int y = 0; y < size; y++) {
					real = a[n++];
					imag = a[n++];
					magnitude.putPixel(x, y, (float)Math.Sqrt(real*real + imag*imag));
					if (imag == 0 && real >= 0) {
						phase.putPixel(x, y, (float)Math.PI/2f);
					} else if (imag == 0 && real < 0) {
						phase.putPixel(x, y, (float)Math.PI/-2f);
					} else {
						phase.putPixel(x, y, (float)Math.Atan(real/imag));
					}
				}
			}
	
			// return magnitude and phase channels
			return new Channel[]{magnitude.offset(size>>1, size>>1), phase};
		}