3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

麻の葉模様を描いてみた

Last updated at Posted at 2019-10-07

背景が寂しかったので 麻の葉模様を書いてみました。

結果の画像
sample.png

xaml
	<Grid Background="#404445">
		<Grid>
			<Grid.Resources>
				<Style TargetType="Line">
					<Setter Property="Stroke" Value="#505050"/>
					<Setter Property="StrokeThickness" Value="1"/>
				</Style>
			</Grid.Resources>
			<Canvas Name="asa" Loaded="asa_Loaded" ClipToBounds="True">
			</Canvas>
		</Grid>
	</Grid>
C#
		private void asa_Loaded( object sender, RoutedEventArgs e )
		{
			double sizeX = 90;
			double sizeY = sizeX / 2;


			for( int x = 0; x < 20; x++ ) {
				for( int y = 0; y < 15; y++ ) {
					asa.Children.Add( new Line {
						X1 = 0 + ( x * sizeX ),
						X2 = sizeX / 3 + ( x * sizeX ),
						Y1 = 0 + ( y * sizeY ),
						Y2 = 0 + ( y * sizeY ),
						StrokeThickness = 0.5
					} );
					asa.Children.Add( new Line {
						X1 = sizeX * 2 / 3 + ( x * sizeX ),
						X2 = sizeX + ( x * sizeX ),
						Y1 = 0 + ( y * sizeY ),
						Y2 = 0 + ( y * sizeY ),
						StrokeThickness = 0.5
					} );
					asa.Children.Add( new Line {
						X1 = sizeX / 3 + ( x * sizeX ),
						X2 = sizeX / 2 + ( x * sizeX ),
						Y1 = 0 + ( y * sizeY ),
						Y2 = sizeY / 2 + ( y * sizeY ),
					} );
					asa.Children.Add( new Line {
						X1 = sizeX / 2 + ( x * sizeX ),
						X2 = sizeX * 2 / 3 + ( x * sizeX ),
						Y1 = sizeY / 2 + ( y * sizeY ),
						Y2 = 0 + ( y * sizeY ),
					} );
					asa.Children.Add( new Line {
						X1 = 0 + ( x * sizeX ),
						X2 = sizeX / 2 + ( x * sizeX ),
						Y1 = 0 + ( y * sizeY ),
						Y2 = sizeY / 2 + ( y * sizeY ),
					} );
					asa.Children.Add( new Line {
						X1 = sizeX / 2 + ( x * sizeX ),
						X2 = sizeX + ( x * sizeX ),
						Y1 = sizeY / 2 + ( y * sizeY ),
						Y2 = 0 + ( y * sizeY ),
					} );
					asa.Children.Add( new Line {
						X1 = sizeX / 6 + ( x * sizeX ),
						X2 = sizeX * 5 / 6 + ( x * sizeX ),
						Y1 = sizeY / 2 + ( y * sizeY ),
						Y2 = sizeY / 2 + ( y * sizeY ),
					} );
					asa.Children.Add( new Line {
						X1 = sizeX / 2 + ( x * sizeX ),
						X2 = sizeX / 2 + ( x * sizeX ),
						Y1 = 0 + ( y * sizeY ),
						Y2 = sizeY + ( y * sizeY ),
					} );
					asa.Children.Add( new Line {
						X1 = 0 + ( x * sizeX ),
						X2 = sizeX / 3 + ( x * sizeX ),
						Y1 = sizeY + ( y * sizeY ),
						Y2 = sizeY + ( y * sizeY ),
						StrokeThickness = 0.5
					} );
					asa.Children.Add( new Line {
						X1 = sizeX * 2 / 3 + ( x * sizeX ),
						X2 = sizeX + ( x * sizeX ),
						Y1 = sizeY + ( y * sizeY ),
						Y2 = sizeY + ( y * sizeY ),
						StrokeThickness = 0.5
					} );
					asa.Children.Add( new Line {
						X1 = sizeX * 2 / 3 + ( x * sizeX ),
						X2 = sizeX / 2 + ( x * sizeX ),
						Y1 = sizeY + ( y * sizeY ),
						Y2 = sizeY / 2 + ( y * sizeY ),
					} );
					asa.Children.Add( new Line {
						X1 = sizeX / 3 + ( x * sizeX ),
						X2 = sizeX / 2 + ( x * sizeX ),
						Y1 = sizeY + ( y * sizeY ),
						Y2 = sizeY / 2 + ( y * sizeY ),
					} );
					asa.Children.Add( new Line {
						X1 = 0 + ( x * sizeX ),
						X2 = sizeX / 2 + ( x * sizeX ),
						Y1 = sizeY + ( y * sizeY ),
						Y2 = sizeY / 2 + ( y * sizeY ),
					} );
					asa.Children.Add( new Line {
						X1 = sizeX / 2 + ( x * sizeX ),
						X2 = sizeX + ( x * sizeX ),
						Y1 = sizeY / 2 + ( y * sizeY ),
						Y2 = sizeY + ( y * sizeY ),
					} );
					asa.Children.Add( new Line {
						X1 = 0 + ( x * sizeX ),
						X2 = 0 + ( x * sizeX ),
						Y1 = 0 + ( y * sizeY ),
						Y2 = sizeY + ( y * sizeY ),
						StrokeThickness = 0.5
					} );
					asa.Children.Add( new Line {
						X1 = sizeX + ( x * sizeX ),
						X2 = sizeX + ( x * sizeX ),
						Y1 = 0 + ( y * sizeY ),
						Y2 = sizeY + ( y * sizeY ),
						StrokeThickness = 0.5
					} );

					asa.Children.Add( new Line {
						X1 = 0 + ( x * sizeX ),
						X2 = sizeX / 6 + ( x * sizeX ),
						Y1 = 0 + ( y * sizeY ),
						Y2 = sizeY / 2 + ( y * sizeY ),
					} );
					asa.Children.Add( new Line {
						X1 = sizeX / 6 + ( x * sizeX ),
						X2 = 0 + ( x * sizeX ),
						Y1 = sizeY / 2 + ( y * sizeY ),
						Y2 = sizeY + ( y * sizeY ),
					} );
					asa.Children.Add( new Line {
						X1 = sizeX + ( x * sizeX ),
						X2 = sizeX * 5 / 6 + ( x * sizeX ),
						Y1 = 0 + ( y * sizeY ),
						Y2 = sizeY / 2 + ( y * sizeY ),
					} );
					asa.Children.Add( new Line {
						X1 = sizeX * 5 / 6 + ( x * sizeX ),
						X2 = sizeX + ( x * sizeX ),
						Y1 = sizeY / 2 + ( y * sizeY ),
						Y2 = sizeY + ( y * sizeY ),
					} );
				}
			}
		}

こんなにいっぱい線を書くのが正解かどうかはわかりませんし、もう少しきれいなコードが書ける物なのか・・・。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?