# include <Siv3D.hpp> // OpenSiv3D v0.6.10 void Main() { // 背景の色を設定する | Set the background color Scene::SetBackground(ColorF{ 0.6, 0.8, 0.7 }); // 絵文字からテクスチャを作成する | Create a texture from an emoji const Texture emoji{ U"🦖"_emoji }; // 太文字のフォントを作成する | Create a bold font with MSDF method const Font font{ FontMethod::MSDF, 48, Typeface::Bold }; // テキストに含まれる絵文字のためのフォントを作成し、font に追加する | Create a font for emojis in text and add it to font as a fallback const Font emojiFont{ 48, Typeface::ColorEmoji }; font.addFallback(emojiFont); const int WIDTH = 800; const int HEIGHT = 600; const int ELEM_WIDTH = 50; const int MAG_HEIGHT = 30;//高さにかける倍率 int element[10] = { 9,13,11,7,1,4,8,5,2,10 }; //値×10倍ぐらいで高さを決める //Rect{{x, y}, width, height}.draw() while (System::Update()) { for (int i = 0; i < 10; i++) { Rect{ {150 + ELEM_WIDTH * i, 100}, ELEM_WIDTH, element[i] * MAG_HEIGHT }.draw(Palette::Darkblue); Rect{ {150 + ELEM_WIDTH * i, 100}, ELEM_WIDTH, element[i] * MAG_HEIGHT }.drawFrame(1, 1, Palette::Black); } } //まず反転 //最大値は明るい色 //最小値は暗い色 }
# include <Siv3D.hpp> // OpenSiv3D v0.6.10 Point& TransformMathToScreen(Point &_p, Size _size) { Point p{ _p.x, _size.y - _p.y }; _p = p; return(_p); } void Main() { // 背景の色を設定する | Set the background color Scene::SetBackground(ColorF{ 0.6, 0.8, 0.7 }); // 画像ファイルからテクスチャを作成する | Create a texture from an image file const Texture texture{ U"example/windmill.png" }; // 絵文字からテクスチャを作成する | Create a texture from an emoji const Texture emoji{ U"🦖"_emoji }; // 太文字のフォントを作成する | Create a bold font with MSDF method const Font font{ FontMethod::MSDF, 48, Typeface::Bold }; // テキストに含まれる絵文字のためのフォントを作成し、font に追加する | Create a font for emojis in text and add it to font as a fallback const Font emojiFont{ 48, Typeface::ColorEmoji }; font.addFallback(emojiFont); while (System::Update()) { // 背景の色を設定する | Set the background color Scene::SetBackground(Palette::Floralwhite); const int WIDTH = 800; //スクリーンの高さ(px) const int HEIGHT = 600; //スクリーンの幅(px) const int ELEM_WIDTH = 50; //棒グラフの幅(px) const int MAG_HEIGHT = 30;//高さにかける倍率(倍) const int HEIGHT_MARGIN = 100; //スクリーンの下からどのぐらいのところからグラフを書くかの空白(px) const int DATA_SIZE = 10; //私用するデータの数(個) const int LEFT_MARGIN = 150; //左側の空白(px) int element[DATA_SIZE] = { 9, 13, 11, 7, 1, 4, 8, 5, 2, 10 }; //値×10倍ぐらいで高さを決める //最大、最小を計算 int min = element[0]; //最小値の初期値を配列の0番に設定しておく(何でもいいんだけどね) int max = element[0]; //最大値 〃 int index_min = 0; int index_max = 0; for (int i = 0; i < DATA_SIZE; i++) { if (min > element[i]) { min = element[i]; index_min = i; } if (max < element[i]) { max = element[i]; index_max = i; } } //Rect{{x, y}, width, height}.draw() 左上の点と、幅、高さを指定 while (System::Update()) { for (int i = 0; i < DATA_SIZE; i++) { Point LeftTop{ LEFT_MARGIN + ELEM_WIDTH * i, element[i] * MAG_HEIGHT + HEIGHT_MARGIN }; Point ScrP = TransformMathToScreen(LeftTop, { WIDTH,HEIGHT }); if (i == index_max) { Rect{ ScrP, ELEM_WIDTH, element[i] * MAG_HEIGHT }.draw(Palette::Lemonchiffon); Rect{ ScrP, ELEM_WIDTH, element[i] * MAG_HEIGHT }.drawFrame(1, 1, Palette::Black); } else if (i == index_min) { Rect{ ScrP, ELEM_WIDTH, element[i] * MAG_HEIGHT }.draw(Palette::Cornflowerblue); Rect{ ScrP, ELEM_WIDTH, element[i] * MAG_HEIGHT }.drawFrame(1, 1, Palette::Black); } else { Rect{ ScrP, ELEM_WIDTH, element[i] * MAG_HEIGHT }.draw(Palette::Plum); Rect{ ScrP, ELEM_WIDTH, element[i] * MAG_HEIGHT }.drawFrame(1, 1, Palette::Black); } } } } }
# include <Siv3D.hpp> // OpenSiv3D v0.6.10 Point& TransformMathToScreen(Point& _p, Size _size) { Point p{ _p.x, _size.y - _p.y }; _p = p; return(_p); } void Main() { // 背景の色を設定する | Set the background color Scene::SetBackground(ColorF{ 0.6, 0.8, 0.7 }); while (System::Update()) { // 背景の色を設定する | Set the background color Scene::SetBackground(Palette::Floralwhite); const int WIDTH = 800; //スクリーンの高さ(px) const int HEIGHT = 600; //スクリーンの幅(px) const int ELEM_WIDTH = 50; //棒グラフの幅(px) const int MAG_HEIGHT = 30;//高さにかける倍率(倍) const int HEIGHT_MARGIN = 100; //スクリーンの下からどのぐらいのところからグラフを書くかの空白(px) const int DATA_SIZE = 10; //私用するデータの数(個) const int LEFT_MARGIN = 150; //左側の空白(px) const Color FRAME_COLOR = Palette::Black; int element[DATA_SIZE] = { 9, 13, 11, 7, 1, 4, 8, 5, 2, 10 }; //値×10倍ぐらいで高さを決める Color elem_color[DATA_SIZE]; for (int i = 0; i < DATA_SIZE; i++) elem_color[i] = Palette::Plum;//デフォルトカラーで全部初期化 //最大、最小を計算 int min = element[0]; //最小値の初期値を配列の0番に設定しておく(何でもいいんだけどね) int max = element[0]; //最大値 〃 int index_min = 0; int index_max = 0; Color maxColor = Palette::Lemonchiffon; Color minColor = Palette::Cornflowerblue; for (int i = 0; i < DATA_SIZE; i++) { if (min > element[i]) { min = element[i]; index_min = i; } if (max < element[i]) { max = element[i]; index_max = i; } } //ここまでで最大値最小値のindexがindex_max,index_minに入ってるよね elem_color[index_min] = minColor; elem_color[index_max] = maxColor; //Rect{{x, y}, width, height}.draw() 左上の点と、幅、高さを指定 while (System::Update()) { for (int i = 0; i < DATA_SIZE; i++) { Point LeftTop{ LEFT_MARGIN + ELEM_WIDTH * i, element[i] * MAG_HEIGHT + HEIGHT_MARGIN }; Point ScrP = TransformMathToScreen(LeftTop, { WIDTH,HEIGHT }); Rect{ ScrP, ELEM_WIDTH, element[i] * MAG_HEIGHT }.draw(elem_color[i]); Rect{ ScrP, ELEM_WIDTH, element[i] * MAG_HEIGHT }.drawFrame(1, 1, FRAME_COLOR); } } } }