6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DXライブラリで色コードを使う

Last updated at Posted at 2016-10-23

色コード調べてるうちに色コード使ってGetColor関数使えたらいいなとか思い始めて作ってみました。

color.cpp
#include "DxLib.h"
#include <string>
#include <stdexcept>
unsigned int GetColor(const std::string& code) {
	if (code.size() != 7 || '#' != code.at(0)) throw std::runtime_error("色コードが不正です。");
	auto change_str_to_num = [code](const size_t start) {
		return std::stoi(std::string(code.begin() + start, code.begin() + start + 2), nullptr, 16);
	};
	return DxLib::GetColor(change_str_to_num(1), change_str_to_num(3), change_str_to_num(5));
}

もう少しきれいに書きたいという気持ちがあるので現在も改良中です。

6
4
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?