コード例 #1
0
ファイル: ShapesTests.cpp プロジェクト: Toffanim/Patchwork
int main()
#endif
{
	
	Shape_test::run_tests();
	SDL_Init(SDL_INIT_VIDEO);
	SDL_Event event;
	SDL_Window *window;
	SDL_Renderer *renderer;
	SDL_CreateWindowAndRenderer(800, 600, 0, &window, &renderer);

	Circle c = Circle(Vec2(400, 300), 50, Color(255, 0, 0));
	Polygon p = Polygon({ { 500, 200 }, { 550, 200 }, { 550, 250 }, { 500, 250 } }, Color(0, 0, 255));
	Line l = Line(Vec2(400, 300), Vec2(100, 100), Color(255, 128, 50));
	Ellipse e = Ellipse(Vec2(600, 500), Vec2(100, 50), Color(0, 255, 0));
	while (1) {
		SDL_PollEvent(&event);
		if (event.type == SDL_QUIT) {
			break;
		}
		SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0x00);
		SDL_RenderClear(renderer);
		c.display(renderer, 1.f);
		p.display(renderer, 1.f);
		l.display(renderer, 1.f);
		e.display(renderer, 1.f);
		SDL_RenderPresent(renderer);
	}
	
	return 0;
}
コード例 #2
0
ファイル: 6-2.cpp プロジェクト: laijingwu/Cpp-Experiment
int main()
{
	Circle c;
	c.setValue(6);
	c.display();
	InSquare i;
	i.setValue(6);
	i.display();
	OutSquare o;
	o.setValue(6);
	o.display();
	return 0;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: luo-yu/SchoolWorks
int main(int argc, const char * argv[]) {
    ifstream inputFile;
    
    inputFile.open(argv[1], ios::in);
    
    //Create a vector of shape pointer
	vector<Shape*> v;
    //if the file is open
    if(inputFile.is_open()){
	string line;
        
	//Use to extract shape names
	string shapeName;
	double radius, side, width, length;
        
	//As long as there is still lines in the file
	//keep reading the file
	while(getline(inputFile, line)){
                //extract the shape name out of a line
		shapeName = line.substr(0, line.find(" "));

		string a;
		//In each of the foolowing condition block, 
		//read the line and extract the shape. 
		//After extracgint, create the shape
                //and call display function
		//Also, use a pointer point to the newly created
		//shape, and push to a vector of Shape pointer
		if(shapeName =="circle"){
			a =line.substr(line.find(" ")+1);
			istringstream iss(a);
			iss>>radius;
			
			
			Circle* temp = new Circle(radius);
			temp->display();
		       	cout<<"The area is: "<<temp->computeArea()<<endl;
 
			//Push the Circle pointer
			//to the vector
			v.push_back(temp);
		}

		else if(shapeName=="square"){