Keyboard

Takuichi Hirano

ピアノの鍵盤を描く

\(\(Keyboard = 
        Module[{dx = 1, dy = 4}, 
dx2 = 
            dx*\((2/3)\); 
dy2 = 
            dy*0.55; 
WhiteKey = {"C", "D", "E", "F", "G", "A", "B"}; 
BlackKey = {"C#", "D#", "", "F#", "G#", "A#"}; 
Rectangle2[v1_, v2_] := 
            Line[{v1, {v2[\([1]\)], v1[\([2]\)]}, 
                v2, {v1[\([1]\)], v2[\([2]\)]}, 
                v1}]; 
{
Table[{AbsoluteThickness[2], Rectangle2[{dx*\((i - 1)\), 0}, {dx*i, dy}]}, {i, 1, 
                7}], 
Table[{Rectangle[{dx*\((i - 
                            1)\) + \((dx - dx2/2)\), 
                    dy - dy2}, {dx*\((i - 1)\) + \((dx + dx2/2)\), dy}]}, {i, 
                1, 2}], 
Table[{Rectangle[{dx*\((i - 
                            1)\) + \((dx - dx2/2)\), 
                    dy - dy2}, {dx*\((i - 1)\) + \((dx + dx2/2)\), dy}]}, {i, 
                4, 6}], 
Table[
              Text[StyleForm[WhiteKey[\([i]\)], FontSize -> 14, 
                  FontWeight -> "Bold"], {dx*\((i - 1)\) + 
                    dx/2, \((dy - dy2)\)/2}, {0, 0}, {1, 
                  0}], 
{i, 1, 
                7}], 
Table[{RGBColor[1, 1, 
                  1], 
Text[
                  StyleForm[BlackKey[\([i]\)], FontSize -> 14, 
                    FontWeight -> "Bold"], {dx*\((i)\), \((dy - 
                          dy2)\) + dy2/2}, {0, 0}, {1, 
                    0}]}, 
{i, 1, 
                2}], 
Table[{RGBColor[1, 1, 
                  1], 
Text[
                  StyleForm[BlackKey[\([i]\)], FontSize -> 14, 
                    FontWeight -> "Bold"], {dx*\((i)\), \((dy - 
                          dy2)\) + dy2/2}, {0, 0}, {1, 
                    0}]}, 
{i, 4, 
                6}]
}
];\)\)
Show[
        Graphics[Keyboard], 
AspectRatio -> 
          Automatic];