こんにちは。
円形のグラデーションを実装したいのですが、難しいです。円形のグラデーションを描く方法はありますか?中心座標は画面サイズの半分に設定しています(ScreenWidth / 2、ScreenHeight / 2)。
for文で円を描く方法が分かりません。 数学式が必要ですか? グラデーションが滑らかでなくても大丈夫です。
for (auto i = 0; i < 360; ++i) {
auto angle = i * (DX_PI_F / 180.0F);
x = ?
y = ?
}
xとyをどうすればいいでしょうか?
以下は線形グラデーション(Linear-Gradient)コードです。VERTEX2Dを応用して作る方法が分かりません。
==================================================
DrawLinearGradient2D(const int x1, const int y1, const int x2, const int y2, const unsigned int startColor, const int startAlpha, const unsigned int endColor, const int endAlpha, const int alpha, const eGradientDirection dir) const noexcept {
int start_red, start_green, start_blue;
DxLib::GetColor2(startColor, &start_red, &start_green, &start_blue);
int end_red, end_green, end_blue;
DxLib::GetColor2(endColor, &end_red, &end_green, &end_blue);
DxLib::VERTEX2D Vertex[6];
DxLib::SetDrawBlendMode(DX_BLENDMODE_ALPHA, alpha);
switch (dir) {
case eGradientDirection::Left: {
Vertex[0].pos = DxLib::VGet(x1, y1, 0.0F);
Vertex[0].rhw = 1.0F;
Vertex[0].dif = { (unsigned char)start_red, (unsigned char)start_green, (unsigned char)start_blue, (unsigned char)startAlpha };
Vertex[0].u = 0.0F;
Vertex[0].v = 0.0F;
Vertex[1].pos = DxLib::VGet(x2, y1, 0.0F);
Vertex[1].rhw = 1.0F;
Vertex[1].dif = { (unsigned char)end_red, (unsigned char)end_green, (unsigned char)end_blue, (unsigned char)endAlpha };
Vertex[1].u = 0.0F;
Vertex[1].v = 0.0F;
Vertex[2].pos = DxLib::VGet(x1, y2, 0.0F);
Vertex[2].rhw = 1.0F;
Vertex[2].dif = { (unsigned char)start_red, (unsigned char)start_green, (unsigned char)start_blue, (unsigned char)startAlpha };
Vertex[2].u = 0.0F;
Vertex[2].v = 0.0F;
Vertex[3].pos = DxLib::VGet(x2, y2, 0.0F);
Vertex[3].rhw = 1.0F;
Vertex[3].dif = { (unsigned char)end_red, (unsigned char)end_green, (unsigned char)end_blue, (unsigned char)endAlpha };
Vertex[3].u = 0.0F;
Vertex[3].v = 0.0F;
Vertex[4] = Vertex[2];
Vertex[5] = Vertex[1];
} break;
case eGradientDirection::Right: {
Vertex[0].pos = DxLib::VGet(x1, y1, 0.0F);
Vertex[0].rhw = 1.0F;
Vertex[0].dif = { (unsigned char)end_red, (unsigned char)end_green, (unsigned char)end_blue, (unsigned char)endAlpha };
Vertex[0].u = 0.0F;
Vertex[0].v = 0.0F;
Vertex[1].pos = DxLib::VGet(x2, y1, 0.0F);
Vertex[1].rhw = 1.0F;
Vertex[1].dif = { (unsigned char)start_red, (unsigned char)start_green, (unsigned char)start_blue, (unsigned char)startAlpha };
Vertex[1].u = 0.0F;
Vertex[1].v = 0.0F;
Vertex[2].pos = DxLib::VGet(x1, y2, 0.0F);
Vertex[2].rhw = 1.0F;
Vertex[2].dif = { (unsigned char)end_red, (unsigned char)end_green, (unsigned char)end_blue, (unsigned char)endAlpha };
Vertex[2].u = 0.0F;
Vertex[2].v = 0.0F;
Vertex[3].pos = DxLib::VGet(x2, y2, 0.0F);
Vertex[3].rhw = 1.0F;
Vertex[3].dif = { (unsigned char)start_red, (unsigned char)start_green, (unsigned char)start_blue, (unsigned char)startAlpha };
Vertex[3].u = 0.0F;
Vertex[3].v = 0.0F;
Vertex[4] = Vertex[2];
Vertex[5] = Vertex[1];
} break;
case eGradientDirection::Top: {
Vertex[0].pos = DxLib::VGet(x1, y1, 0.0F);
Vertex[0].rhw = 1.0F;
Vertex[0].dif = { (unsigned char)start_red, (unsigned char)start_green, (unsigned char)start_blue, (unsigned char)startAlpha };
Vertex[0].u = 0.0F;
Vertex[0].v = 0.0F;
Vertex[1].pos = DxLib::VGet(x2, y1, 0.0F);
Vertex[1].rhw = 1.0F;
Vertex[1].dif = { (unsigned char)start_red, (unsigned char)start_green, (unsigned char)start_blue, (unsigned char)startAlpha };
Vertex[1].u = 0.0F;
Vertex[1].v = 0.0F;
Vertex[2].pos = DxLib::VGet(x1, y2, 0.0F);
Vertex[2].rhw = 1.0F;
Vertex[2].dif = { (unsigned char)end_red, (unsigned char)end_green, (unsigned char)end_blue, (unsigned char)endAlpha };
Vertex[2].u = 0.0F;
Vertex[2].v = 0.0F;
Vertex[3].pos = DxLib::VGet(x1, y2, 0.0F);
Vertex[3].rhw = 1.0F;
Vertex[3].dif = { (unsigned char)end_red, (unsigned char)end_green, (unsigned char)end_blue, (unsigned char)endAlpha };
Vertex[3].u = 0.0F;
Vertex[3].v = 0.0F;
Vertex[4] = Vertex[2];
Vertex[5] = Vertex[1];
} break;
case eGradientDirection::Bottom: {
Vertex[0].pos = DxLib::VGet(x1, y1, 0.0F);
Vertex[0].rhw = 1.0F;
Vertex[0].dif = { (unsigned char)end_red, (unsigned char)end_green, (unsigned char)end_blue, (unsigned char)endAlpha };
Vertex[0].u = 0.0F;
Vertex[0].v = 0.0F;
Vertex[1].pos = DxLib::VGet(x2, y1, 0.0F);
Vertex[1].rhw = 1.0F;
Vertex[1].dif = { (unsigned char)end_red, (unsigned char)end_green, (unsigned char)end_blue, (unsigned char)endAlpha };
Vertex[1].u = 0.0F;
Vertex[1].v = 0.0F;
Vertex[2].pos = DxLib::VGet(x1, y2, 0.0F);
Vertex[2].rhw = 1.0F;
Vertex[2].dif = { (unsigned char)start_red, (unsigned char)start_green, (unsigned char)start_blue, (unsigned char)startAlpha };
Vertex[2].u = 0.0F;
Vertex[2].v = 0.0F;
Vertex[3].pos = DxLib::VGet(x2, y2, 0.0F);
Vertex[3].rhw = 1.0F;
Vertex[3].dif = { (unsigned char)start_red, (unsigned char)start_green, (unsigned char)start_blue, (unsigned char)startAlpha };
Vertex[3].u = 0.0F;
Vertex[3].v = 0.0F;
Vertex[4] = Vertex[2];
Vertex[5] = Vertex[1];
} break;
default: { return; } break;
}
DxLib::DrawPolygon2D(Vertex, 2, DX_NONE_GRAPH, FALSE);
DxLib::SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0);
DxLib::ClearDrawScreenZBuffer(); // Reset
}