コード例 #1
0
ファイル: main.cpp プロジェクト: eriklumens/PolyTori
int main()
{
    //set up basisvectors
    std::vector<std::vector<double> > basis2(2,std::vector<double>(2));
    basis2[0][0] = 1;
    basis2[0][1] = 0;
    basis2[1][0] = 0;
    basis2[1][1] = 1;
    
    //define lattice
    Lattice myLattice(2,basis2);
    
    //set up 2d polytopes
    
    std::vector<std::vector<double> > ver0(3,std::vector<double>(2));
    std::vector<std::vector<double> > ver1(4,std::vector<double>(2));
    std::vector<std::vector<double> > ver2(4,std::vector<double>(2));
    std::vector<std::vector<double> > ver3(3,std::vector<double>(2));
    std::vector<std::vector<double> > ver4(5,std::vector<double>(2));
    std::vector<std::vector<double> > ver5(4,std::vector<double>(2));
    std::vector<std::vector<double> > ver6(6,std::vector<double>(2));
    std::vector<std::vector<double> > ver7(4,std::vector<double>(2));
    std::vector<std::vector<double> > ver8(5,std::vector<double>(2));
    std::vector<std::vector<double> > ver9(3,std::vector<double>(2));
    std::vector<std::vector<double> > ver10(4,std::vector<double>(2));
    
    ver0[0][0] = 1;
    ver0[0][1] = 0;
    ver0[1][0] = 0;
    ver0[1][1] = 1;
    ver0[2][0] = -1;
    ver0[2][1] = -1;
    
    ver1[0][0] = 1;
    ver1[0][1] = 0;
    ver1[1][0] = 0;
    ver1[1][1] = 1;
    ver1[2][0] = -1;
    ver1[2][1] = 0;
    ver1[3][0] = 0;
    ver1[3][1] = -1;
    
    ver2[0][0] = 1;
    ver2[0][1] = 0;
    ver2[1][0] = 0;
    ver2[1][1] = 1;
    ver2[2][0] = -1;
    ver2[2][1] = 0;
    ver2[3][0] = -1;
    ver2[3][1] = -1;
    
    ver3[0][0] = 1;
    ver3[0][1] = 0;
    ver3[1][0] = 0;
    ver3[1][1] = 1;
    ver3[2][0] = -2;
    ver3[2][1] = -1;
    
    ver4[0][0] = 1;
    ver4[0][1] = 0;
    ver4[1][0] = 1;
    ver4[1][1] = 1;
    ver4[2][0] = 0;
    ver4[2][1] = 1;
    ver4[3][0] = -1;
    ver4[3][1] = 0;
    ver4[4][0] = 0;
    ver4[4][1] = -1;
    
    ver5[0][0] = 1;
    ver5[0][1] = 0;
    ver5[1][0] = 0;
    ver5[1][1] = 1;
    ver5[2][0] = -1;
    ver5[2][1] = 1;
    ver5[3][0] = -1;
    ver5[3][1] = -1;
    
    Polytope pol0(ver0,myLattice);
    Polytope pol1(ver1,myLattice);
    Polytope pol2(ver2,myLattice);
    Polytope pol3(ver3,myLattice);
    Polytope pol4(ver4,myLattice);
    Polytope pol5(ver5,myLattice);
    
    Polytope pol15 = pol0.getCorrespondingDualPolytope();
    Polytope pol14 = pol1.getCorrespondingDualPolytope();
    Polytope pol13 = pol2.getCorrespondingDualPolytope();
    Polytope pol12 = pol3.getCorrespondingDualPolytope();
    Polytope pol11 = pol4.getCorrespondingDualPolytope();
    Polytope pol10 = pol5.getCorrespondingDualPolytope();
    
    ver6[0][0] = 1;
    ver6[0][1] = 0;
    ver6[1][0] = 1;
    ver6[1][1] = 1;
    ver6[2][0] = 0;
    ver6[2][1] = 1;
    ver6[3][0] = -1;
    ver6[3][1] = 0;
    ver6[4][0] = -1;
    ver6[4][1] = -1;
    ver6[5][0] = 0;
    ver6[5][1] = -1;
    
    ver7[0][0] = 1;
    ver7[0][1] = 0;
    ver7[1][0] = -1;
    ver7[1][1] = 1;
    ver7[2][0] = -1;
    ver7[2][1] = -1;
    ver7[3][0] = 1;
    ver7[3][1] = -1;
    
    ver8[0][0] = 1;
    ver8[0][1] = 0;
    ver8[1][0] = 1;
    ver8[1][1] = 1;
    ver8[2][0] = -1;
    ver8[2][1] = 1;
    ver8[3][0] = -1;
    ver8[3][1] = 0;
    ver8[4][0] = 0;
    ver8[4][1] = -1;
    
    ver9[0][0] = 1;
    ver9[0][1] = 0;
    ver9[1][0] = -1;
    ver9[1][1] = 2;
    ver9[2][0] = -1;
    ver9[2][1] = -1;
    
    Polytope pol6(ver6,myLattice);
    Polytope pol7(ver7,myLattice);
    Polytope pol8(ver8,myLattice);
    Polytope pol9(ver9,myLattice);
    
    //Polytope polytopes2D[16] = {pol0, pol1, pol2, pol3, pol4, pol5, pol6, pol7, pol8, pol9, pol10, pol11, pol12, pol13, pol14, pol15};
    //Polytope polytopes2DDual[16] = {pol15, pol14, pol13, pol12, pol11, pol10, pol6, pol7, pol8, pol9, pol5, pol4, pol3, pol2, pol1, pol0};
    std::vector<Polytope > myList = {pol0, pol1, pol2, pol3, pol4, pol5, pol6, pol7, pol8, pol9, pol10, pol11, pol12, pol13, pol14, pol15};
    std::vector<Polytope > myFiveVerticesList = {pol0, pol3, pol9, pol12, pol15};
    //Construct 4d polytopes from this data
    std::string fileName = "output";
    //pol0.printListFrom2DTo4DPolytopesToFile(fileName, myList);
    pol0.printListFrom2DTo4DPolytopesToFile("outputForFiveVertices", myFiveVerticesList);
}
コード例 #2
0
ファイル: result.cpp プロジェクト: faizilham/grafika-tubes1
void Result::showResultLose(int score){
	int left = -320;
	int right = 320;
	int top = 240;
	int bot = -240;
	char strbuffer[64];
	// L
	Point pol1(left+60,top-80);
	Point pol2(left+60,bot+220);
	Point pol3(left+180,bot+220);
	Point pol4(left+180,bot+270);
	Point pol5(left+110,bot+270);
	Point pol6(left+110,top-80);
	Point polc((pol1.x+pol3.x)/2,(pol1.y+pol3.y)/2);
	vector<Point> pol;
	pol.push_back(pol1);
	pol.push_back(pol2);
	pol.push_back(pol3);
	pol.push_back(pol4);
	pol.push_back(pol5);
	pol.push_back(pol6);
	if (firsttime){
		pol_l.setCorner(pol);
		pol_l.setCenter(polc);
		Transform scale = createScale(0.1, 0.1);
		pol_l.applyTransform(scale);
	}

	// O
	Point poo1(left+190,top-80);
	Point poo2(left+190,bot+220);
	Point poo3(left+310,bot+220);
	Point poo4(left+310,top-80);
	Point poo5(left+230,top-120);
	Point poo6(left+230,bot+260);
	Point poo7(left+270,bot+260);
	Point poo8(left+270,top-120);
	Point pooc((poo1.x+poo3.x)/2,(poo1.y+poo3.y)/2);
	vector<Point> poo, poov;
	poo.push_back(poo1);
	poo.push_back(poo2);
	poo.push_back(poo3);
	poo.push_back(poo4);
	poov.push_back(poo5);
	poov.push_back(poo6);
	poov.push_back(poo7);
	poov.push_back(poo8);
	if (firsttime){
		pol_o.setCorner(poo);
		pol_o.setCenter(pooc);
		pol_o1.setCorner(poov);
		pol_o1.setCenter(pooc);
		Transform scale = createScale(0.1, 0.1);
		pol_o.applyTransform(scale);
		pol_o1.applyTransform(scale);
	}
	// S
	Point pos1(left+320,top-80);
	Point pos2(left+320,top-190);
	Point pos3(left+410,top-190);
	Point pos4(left+410,top-220);
	Point pos5(left+320,top-220);
	Point pos6(left+320,top-260);
	Point pos7(left+450,top-260);
	Point pos8(left+450,top-150);
	Point pos9(left+360,top-150);
	Point pos10(left+360,top-120);
	Point pos11(left+450,top-120);
	Point pos12(left+450,top-80);
	Point posc((pos1.x+pos7.x)/2,(pos1.y+pos7.y)/2);
	vector<Point> pos;
	pos.push_back(pos1);
	pos.push_back(pos2);
	pos.push_back(pos3);
	pos.push_back(pos4);
	pos.push_back(pos5);
	pos.push_back(pos6);
	pos.push_back(pos7);
	pos.push_back(pos8);
	pos.push_back(pos9);
	pos.push_back(pos10);
	pos.push_back(pos11);
	pos.push_back(pos12);
	if (firsttime){
		pol_s.setCorner(pos);
		pol_s.setCenter(posc);
		Transform scale = createScale(0.1, 0.1);
		pol_s.applyTransform(scale);
	}
	

	// E
	Point poe1(left+460,top-80);
	Point poe2(left+460,bot+220);
	Point poe3(left+580,bot+220);
	Point poe4(left+580,bot+260);
	Point poe5(left+510,bot+260);
	Point poe6(left+510,bot+290);

	Point poe7(left+580,bot+220+70);
	Point poe8(left+580,bot+260+70);
	Point poe9(left+510,bot+260+70);
	Point poe10(left+510,bot+290+70);

	Point poe11(left+580,bot+220+140);
	Point poe12(left+580,bot+260+140);
	Point poec((poe1.x+poe3.x)/2,(poe1.y+poe3.y)/2);
	vector<Point> poe;
	poe.push_back(poe1);
	poe.push_back(poe2);
	poe.push_back(poe3);
	poe.push_back(poe4);
	poe.push_back(poe5);
	poe.push_back(poe6);
	poe.push_back(poe7);
	poe.push_back(poe8);
	poe.push_back(poe9);
	poe.push_back(poe10);
	poe.push_back(poe11);
	poe.push_back(poe12);
	if (firsttime){
		pol_e.setCorner(poe);
		pol_e.setCenter(poec);
		Transform scale = createScale(0.1, 0.1);
		pol_e.applyTransform(scale);
	}

	

	// Other
	Point pot1(left+60, top-40);
	Point pot2(right-60, top-40);
	Point pot3(right-60, top-60);
	Point pot4(left+60, top-60);
	Point potc((pot1.x+pot2.x)/2,(pot2.x+pot3.x)/2);
	vector<Point> pot;
	pot.push_back(pot1);
	pot.push_back(pot2);
	pot.push_back(pot3);
	pot.push_back(pot4);
	if (firsttime){
		pol_pot1.setCorner(pot);
		pol_pot1.setCenter(potc);
		Transform scale = createScale(0.1, 0.1);
		pol_pot1.applyTransform(scale);
	}
	

	pot1.set(left+60, bot+180);
	pot2.set(right-60, bot+180);
	pot3.set(right-60, bot+200);
	pot4.set(left+60, bot+200);
	potc.set((pot1.x+pot2.x)/2,(pot2.x+pot3.x)/2);
	pot.clear();
	pot.push_back(pot1);
	pot.push_back(pot2);
	pot.push_back(pot3);
	pot.push_back(pot4);
	if (firsttime){
		pol_pot2.setCorner(pot);
		pol_pot2.setCenter(potc);
		Transform scale = createScale(0.1, 0.1);
		pol_pot2.applyTransform(scale);
	}
	

	resultframe++;
	if (resultframe >= 25)
		resultframe = 25;
	else {
		Transform scale = createScale(1.1, 1.1);
		pol_pot1.applyTransform(scale);
		pol_pot2.applyTransform(scale);
		pol_l.applyTransform(scale);
		pol_o.applyTransform(scale);
		pol_o1.applyTransform(scale);
		pol_s.applyTransform(scale);
		pol_e.applyTransform(scale);
	}
	pol_l.draw(WHITE);
	fill_polygon(pol_l[0].x, pol_l[2].y, pol_l[2].x, pol_l[0].y,WHITE,WHITE);
	pol_o.draw(WHITE);
	fill_polygon(pol_o[0].x, pol_o[2].y, pol_o[2].x, pol_o[0].y,WHITE,WHITE);
	pol_o1.draw(BLACK);
	fill_polygon(pol_o1[0].x, pol_o1[2].y, pol_o1[2].x, pol_o1[0].y,BLACK,BLACK);	
	pol_s.draw(WHITE);
	fill_polygon(pol_s[0].x, pol_s[6].y, pol_s[6].x, pol_s[0].y,WHITE,WHITE);
	pol_e.draw(WHITE);
	fill_polygon(pol_e[0].x, pol_e[2].y, pol_e[2].x, pol_e[0].y,WHITE,WHITE);
	pol_pot1.draw(WHITE);
	pol_pot2.draw(WHITE);

	settextstyle(7,0,40);
	setcolor(WHITE);
	sprintf(strbuffer,"%d",score);
	outtextxy(getmaxx()/2-50, getmaxy()/2+100, strbuffer);
	firsttime = false;
}