Ejemplo n.º 1
0
int main(int argc, char* argv[]){

	const int NP=256;				// Number of points in curve
	const int N1=31, N2=N1*N1;		// Size of graph
	float pixels[N2];				// Accumulation buffer

	Complex<double> phase(1,0), freq;
	

	printf("\nUnit circle\n");
	mem::zero(pixels, N2);
	freq.fromPhase(M_2PI/NP);
	for(int i=0; i<NP; ++i){
		int ix = posToInd(phase[0], N1);
		int iy = posToInd(phase[1], N1);
		phase *= freq;
		pixels[iy*N1 + ix] += 0.125;
	}
	print2D(pixels, N1, N1);


	printf("\nHalf circle\n");
	mem::zero(pixels, N2);
	phase(0.5, 0);
	freq.fromPhase(M_2PI/NP);
	for(int i=0; i<NP; ++i){
		int ix = posToInd(phase[0], N1);
		int iy = posToInd(phase[1], N1);
		phase *= freq;
		pixels[iy*N1 + ix] += 0.125;
	}
	print2D(pixels, N1, N1);	

	return 0;
}
Ejemplo n.º 2
0
int main(){

	const int NP=256;				// Number of points in curve
	const int N1=17, N2=N1*N1;		// Size of graph
	float pixels[N2];				// Accumulation buffer

	CSine<> osc(1./NP);
	SineR<> oscAM;

	for(int k=2; k<5; ++k){
	for(int j=0; j<3; ++j){
	
		mem::zero(pixels, N2);

		float w = j*0.3 + 0.2;		// "petalness" factor
		oscAM.set(k/(float)NP, w);
		
		for(int i=0; i<NP; ++i){
			Complex<> c = osc() * (1-w + oscAM());
			int ix = posToInd( c.r, N1);
			int iy = posToInd(-c.i, N1);
			pixels[iy*N1 + ix] += 0.1;
		}

		print2D(pixels, N1, N1);
		printf("\n");
	}}
}
Ejemplo n.º 3
0
int main(){

	const int NP=256;				// Number of points in curve
	const int N1=31, N2=N1*N1;		// Size of graph
	float pixels[N2];				// Accumulation buffer
	
	// Use two complex oscillators as harmonics of curve
	CSine<> csin1(1./NP), csin2;

	// Plot several harmonics summed with fundamental
	for(int j=1; j<8; ++j){

		printf("\ne^iw + e^%diw\n\n", j);
		mem::zero(pixels, N2);
		
		csin2.freq(j/(float)NP);		// Harmonic rotating in tandem with fundamental
		csin2.amp(1./j);				// Amplitude is 1/f to give equal energy
		float r = 0.99/(1. + 1./j);		// Factor to normalize sum of partials

		for(int i=0; i<NP; ++i){
			Complex<> c = csin1() + csin2();
			int ix = posToInd( c.r * r, N1);	// map real component to x
			int iy = posToInd(-c.i * r, N1);	// map imag component to y
			pixels[iy*N1 + ix] += 0.1;
		}

		print2D(pixels, N1, N1);
		printf("\n");
	}
}
Ejemplo n.º 4
0
int main(int argc, char* argv[]){

	const int NP=256;				// Number of points in curve
	const int N1=15, N2=N1*N1;		// Size of graph
	float pixels[N2];				// Accumulation buffer

	SineR<> sineX, sineY;

	for(int k=1; k<4; ++k){
	for(int j=1; j<4; ++j){
	
		mem::zero(pixels, N2);
		sineX.set(float(j)/NP, 1);
		sineY.set(float(k)/NP, 1);
		
		printf("\nx:y = %d:%d\n\n", j,k);
		
		for(int i=0; i<NP; ++i){
			int ix = posToInd( sineX(), N1);
			int iy = posToInd(-sineY(), N1);
			pixels[iy*N1 + ix] += 0.125;
		}

		print2D(pixels, N1, N1);
		printf("\n");
	}}

	return 0;
}
Ejemplo n.º 5
0
int main(){

	const int NP=256;				// Number of points in curve
	const int N1=31, N2=N1*N1;		// Size of graph
	float pixels[N2];				// Accumulation buffer
	
	CSine<> csin;

	// Plot several winding and damping amounts
	for(int k=1; k<4; ++k){
	for(int j=1; j<4; ++j){

		printf("\nwinding=%d, decay=%d\n\n", k, j);
		mem::zero(pixels, N2);
		
		csin.decay(NP*j);			// Number of iterations for amp to decay by 0.0001
		csin.freq(k/(float)NP);		// Winding number
		csin.reset();				// Reset oscillator to (1,0)

		for(int i=0; i<NP; ++i){
			Complex<> c = csin();
			int ix = posToInd( c.r, N1);	// map real component to x
			int iy = posToInd(-c.i, N1);	// map imag component to y
			pixels[iy*N1 + ix] += 0.1;
		}

		print2D(pixels, N1, N1);
		printf("\n");
	}}
}