2018年05月12日
《その382》三角形,五角形 の表示
三角形,五角形 の表示
今回は、三角形,五角形 の表示です。
Polygonクラスを利用すれば、何角形でも作ることができます。

以下は、MainPage.xaml.cpp です。
//
//
// MainPage.xaml.cpp
// MainPage クラスの実装。
//
#include "pch.h"
#include "MainPage.xaml.h"
using namespace App4;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
// 正五角形の頂点の座標 (x01, y01) ~ (x05, y05)
const float pi = (float)3.1416;
float x01 = 200 + 100 * cos(pi * 54 / 180);
float y01 = 100 + 100 * sin(pi * 54 / 180);
float x02 = 200 + 100 * cos(pi * 126 / 180);
float y02 = 100 + 100 * sin(pi * 126 / 180);
float x03 = 200 + 100 * cos(pi * 198 / 180);
float y03 = 100 + 100 * sin(pi * 198 / 180);
float x04 = 200 + 100 * cos(pi * 270 / 180);
float y04 = 100 + 100 * sin(pi * 270 / 180);
float x05 = 200 + 100 * cos(pi * 342 / 180);
float y05 = 100 + 100 * sin(pi * 342 / 180);
MainPage::MainPage()
{
InitializeComponent();
// 正三角形
auto triangle = ref new Shapes::Polygon();
auto points1 = ref new PointCollection();
points1->Append(Point(110, 10));
points1->Append(Point( 10, 183));
points1->Append(Point(210, 183));
triangle->Points = points1;
triangle->Stroke
= ref new SolidColorBrush(Windows::UI::Colors::Blue);
triangle->StrokeThickness = 5;
canvas1->Margin = Thickness(20, 10, 0, 0);
canvas1->Children->Append(triangle);
// 正五角形
auto pentagon = ref new Shapes::Polygon();
auto points2 = ref new PointCollection();
points2->Append(Point(x01, y01));
points2->Append(Point(x02, y02));
points2->Append(Point(x03, y03));
points2->Append(Point(x04, y04));
points2->Append(Point(x05, y05));
pentagon->Points = points2;
pentagon->Stroke
= ref new SolidColorBrush(Windows::UI::Colors::Red);
pentagon->StrokeThickness = 5;
canvas2->Margin = Thickness(200, 10, 0, 0);
canvas2->Children->Append(pentagon);
}
この記事へのコメント
コメントを書く
この記事へのトラックバックURL
https://fanblogs.jp/tb/7649384
※ブログオーナーが承認したトラックバックのみ表示されます。
この記事へのトラックバック