LoginSignup
1
1

More than 5 years have passed since last update.

ニコニコ生放送にて、30分で作ったお絵かきソフト

Posted at

20140607-153244-866.png

Main.cpp

//お絵かきソフト

# include <Siv3D.hpp>

void Main()
{
    Window::Resize({ 640, 640 });

    Graphics::SetBackground(Palette::Gray);

    Image image{ 640, 480, Palette::White };

    DynamicTexture texture{ image };

    const std::array<Color, 16> colors =
    {
        Palette::Black,
        Palette::Gray,
        Palette::Silver,
        Palette::White,
        Palette::Maroon,
        Palette::Red,
        Palette::Olive,
        Palette::Yellow,
        Palette::Green,
        Palette::Lime,
        Palette::Teal,
        Palette::Aqua,
        Palette::Navy,
        Palette::Blue,
        Palette::Purple,
        Palette::Fuchsia
    };

    std::array<Rect, 16> buttons;

    const Point areaSize{ 80, 80 };

    const Point margin{ 5, 5 };

    const Point buttonSize = areaSize - margin * 2;

    const Point firstPos = Point(0, 480) + areaSize / 2;

    for (int i = 0; i < buttons.size(); ++i)
    {
        buttons[i].setSize(buttonSize);

        buttons[i].setCenter(firstPos + Point((i % 8) * areaSize.x, (i / 8) * areaSize.y));
    }

    Color penColor;


    while (System::Update())
    {
        for (int i = 0; i < buttons.size(); ++i)
        {
            if (buttons[i].leftClicked)
            {
                penColor = colors[i];
            }
        }

        if (Input::MouseL.pressed)
        {
            const Point pos = Input::MouseL.clicked ? Mouse::Pos() : Mouse::PreviousPos();

            Line{ pos, Mouse::Pos() }.write(image, 8, penColor);

            texture.fill(image);
        }

        texture.draw();

        for (int i = 0; i < buttons.size(); ++i)
        {
            buttons[i].draw(colors[i]);

            buttons[i].drawFrame(1.0, 1.0, Palette::White);
        }
    }
}

1
1
0

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
1
1