# include // 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); } } } }