Skip to content

ファイル出力

Kasugaccho edited this page Mar 8, 2019 · 16 revisions

ファイル出力

テキスト/セーブデータ

csvファイルを書き込む

bool dtl::file::write::stl::csv(matrix, write_file_name);

#include <array>
#include "DTL.hpp"

int main() {

	using dungeon_t = bool;
	std::array<std::array<dungeon_t, 10>, 8> matrix{ {} };
	dtl::generator::common::stl::createBorder(matrix);

	dtl::file::write::stl::csv(matrix, "write_test.csv");

	dtl::console::output::stl::stringBool(matrix, "##", "  ");

	return 0;
}

書き込んだcsvデータ(write_test.csv)

1,1,1,1,1,1,1,1,1,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,1,1,1,1,1,1,1,1,1

出力例

####################
##                ##
##                ##
##                ##
##                ##
##                ##
##                ##
####################

dtlmファイルを書き込む(独自拡張子)

bool dtl::file::write::stl::dtlm(matrix, write_file_name);

#include <array>
#include "DTL.hpp"

int main() {

	using dungeon_t = bool;
	std::array<std::array<dungeon_t, 10>, 8> matrix{ {} };
	dtl::generator::common::stl::createBorder(matrix);

	dtl::file::write::stl::dtlm(matrix, "write_test.dtlm");

	dtl::console::output::stl::stringBool(matrix, "##", "  ");

	return 0;
}

書き込んだdtlmデータ(write_test.dtlm)※バイナリデータ

0a 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 
01 01 01 01 01 01 01 01 01 01 01 00 00 00 00 00 
00 00 00 01 01 00 00 00 00 00 00 00 00 01 01 00 
00 00 00 00 00 00 00 01 01 00 00 00 00 00 00 00 
00 01 01 00 00 00 00 00 00 00 00 01 01 00 00 00 
00 00 00 00 00 01 01 01 01 01 01 01 01 01 01 01

出力例

####################
##                ##
##                ##
##                ##
##                ##
##                ##
##                ##
####################

画像

bmpファイルを書き込む

bool dtl::file::write::stl::bmp(matrix, write_file_name);

#include <array>
#include "DTL.hpp"

int main() {

	using dungeon_t = bool;
	std::array<std::array<dungeon_t, 10>, 8> matrix{ {} };
	dtl::generator::common::stl::createBorder(matrix);

	dtl::file::write::stl::bmp(matrix, "write_test.bmp");

	dtl::console::output::stl::stringBool(matrix, "##", "  ");

	return 0;
}

書き込んだbmpデータ(write_test.bmp)※バイナリデータ

42 4d 5e 00 00 00 00 00 00 00 3e 00 00 00 28 00 
00 00 0a 00 00 00 08 00 00 00 01 00 01 00 00 00 
00 00 20 00 00 00 0a 00 00 00 08 00 00 00 00 00 
00 00 00 00 00 00 ff ff ff 00 00 00 00 00 ff ff 
00 00 80 7f 00 00 80 60 00 00 80 60 00 00 80 60 
00 00 80 60 00 00 80 60 00 00 ff e0 00 00 

出力例

####################
##                ##
##                ##
##                ##
##                ##
##                ##
##                ##
####################

pbmファイルを書き込む

bool dtl::file::write::stl::pbm(matrix, write_file_name);

#include <array>
#include "DTL.hpp"

int main() {

	using dungeon_t = bool;
	std::array<std::array<dungeon_t, 10>, 8> matrix{ {} };
	dtl::generator::common::stl::createBorder(matrix);

	dtl::file::write::stl::pbm(matrix, "write_test.pbm");

	dtl::console::output::stl::stringBool(matrix, "##", "  ");

	return 0;
}

書き込んだpbmデータ(write_test.pbm)※バイナリデータ

31 20 30 20 30 20 30 20 30 20 30 20 30 20 30 20 
30 20 31 0d 0a 31 20 30 20 30 20 30 20 30 20 30 
20 30 20 30 20 30 20 31 0d 0a 31 20 30 20 30 20 
30 20 30 20 30 20 30 20 30 20 30 20 31 0d 0a 31 
20 30 20 30 20 30 20 30 20 30 20 30 20 30 20 30 
20 31 0d 0a 31 20 30 20 30 20 30 20 30 20 30 20 
30 20 30 20 30 20 31 0d 0a 31 20 31 20 31 20 31 
20 31 20 31 20 31 20 31 20 31 20 31 0d 0a

出力例

####################
##                ##
##                ##
##                ##
##                ##
##                ##
##                ##
####################

svgファイルを書き込む

bool dtl::file::write::stl::svg(matrix, write_file_name);

#include <array>
#include "DTL.hpp"

int main() {

	using dungeon_t = bool;
	std::array<std::array<dungeon_t, 10>, 8> matrix{ {} };
	dtl::generator::common::stl::createBorder(matrix);

	dtl::file::write::stl::svg(matrix, "write_test.svg");

	dtl::console::output::stl::stringBool(matrix, "##", "  ");

	return 0;
}

書き込んだsvgデータ(write_test.svg)

<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="layer" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 10 8" style="enable-background:new 0 0 10 8;" xml:space="preserve">
<rect x="0" y="0" width="1" height="1"/>
<rect x="1" y="0" width="1" height="1"/>
<rect x="2" y="0" width="1" height="1"/>
<rect x="3" y="0" width="1" height="1"/>
<rect x="4" y="0" width="1" height="1"/>
<rect x="5" y="0" width="1" height="1"/>
<rect x="6" y="0" width="1" height="1"/>
<rect x="7" y="0" width="1" height="1"/>
<rect x="8" y="0" width="1" height="1"/>
<rect x="9" y="0" width="1" height="1"/>
<rect x="0" y="1" width="1" height="1"/>
<rect x="9" y="1" width="1" height="1"/>
<rect x="0" y="2" width="1" height="1"/>
<rect x="9" y="2" width="1" height="1"/>
<rect x="0" y="3" width="1" height="1"/>
<rect x="9" y="3" width="1" height="1"/>
<rect x="0" y="4" width="1" height="1"/>
<rect x="9" y="4" width="1" height="1"/>
<rect x="0" y="5" width="1" height="1"/>
<rect x="9" y="5" width="1" height="1"/>
<rect x="0" y="6" width="1" height="1"/>
<rect x="9" y="6" width="1" height="1"/>
<rect x="0" y="7" width="1" height="1"/>
<rect x="1" y="7" width="1" height="1"/>
<rect x="2" y="7" width="1" height="1"/>
<rect x="3" y="7" width="1" height="1"/>
<rect x="4" y="7" width="1" height="1"/>
<rect x="5" y="7" width="1" height="1"/>
<rect x="6" y="7" width="1" height="1"/>
<rect x="7" y="7" width="1" height="1"/>
<rect x="8" y="7" width="1" height="1"/>
<rect x="9" y="7" width="1" height="1"/>
</svg>

出力例

####################
##                ##
##                ##
##                ##
##                ##
##                ##
##                ##
####################

3D

objファイルを書き込む(ブロック型)

bool dtl::file::write::stl::objBoard(matrix, write_file_name);

#include <array>
#include "DTL.hpp"

int main() {

	using dungeon_t = bool;
	std::array<std::array<dungeon_t, 10>, 8> matrix{ {} };
	dtl::generator::common::stl::createBorder(matrix);

	dtl::file::write::stl::objBoard<dungeon_t>(matrix, "write_board_test.obj");

	dtl::console::output::stl::stringBool(matrix, "##", "  ");

	return 0;
}

書き込んだobjデータ(write_board_test.obj) https://github.com/Kasugaccho/DungeonPicture/blob/master/Picture/reference/write_board_test.obj picture

出力例

####################
##                ##
##                ##
##                ##
##                ##
##                ##
##                ##
####################

objファイルを書き込む(ブロック型)

bool dtl::file::write::stl::objBoard(matrix, write_file_name, block_height, block_id);

#include <array>
#include "DTL.hpp"

int main() {

	using dungeon_t = bool;
	std::array<std::array<dungeon_t, 10>, 8> matrix{ {} };
	dtl::generator::common::stl::createBorder(matrix);

	dtl::file::write::stl::objBoard<dungeon_t>(matrix, "write_board_test_2.obj", 5, 1);

	dtl::console::output::stl::stringBool(matrix, "##", "  ");

	return 0;
}

書き込んだobjデータ(write_board_test_2.obj) https://github.com/Kasugaccho/DungeonPicture/blob/master/Picture/reference/write_board_test_2.obj picture

出力例

####################
##                ##
##                ##
##                ##
##                ##
##                ##
##                ##
####################

当記事のライセンス

CC0

Clone this wiki locally