背景が寂しかったので 麻の葉模様を書いてみました。
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 ),
} );
}
}
}
こんなにいっぱい線を書くのが正解かどうかはわかりませんし、もう少しきれいなコードが書ける物なのか・・・。