All pastes #776353 Raw Edit

Vermischtes

public text v1 · immutable
·published 2007-11-16 00:34 UTC
rendered paste body
#include <iostream>
#include <fstream>

using namespace std;

int bwGradient(){
	int h = 50;
	int w = 10;
	int f = 255; //farbwerte max
	int fw; // zu schreibender farbwert
	float k = (float)f/(float)w; // inkrementproportion
	float fadd=0.0; // floatadd zur wertrundung
	//int p = (int)(k+0.5);
	ofstream mypgm ("test.pgm");
	if ( !mypgm.is_open() ){
		cout<< "Error creating file! (rootuser access?)";
	}
	else {
		mypgm<<"P2\n# test.pgm\n"<<w<<" "<<h<<"\n"<<f<<"\n";
		for (int i=0; i<h; ++i){
			for (int j=0; j<w; ++j){
				fadd += k;
				fw = (int)(fadd+0.5);
				mypgm<<fw<<" ";
			}
			fadd=0.0;
			mypgm<<"\n";
		}
		cout<<"Succesfully written!!!";
	}
	
	return 0;
}

int main() {
	bwGradient();
}