VBA キャラクターのドット絵を描く

パソコン操作

マリオの右向きのドット絵

    Sub MarioR()
    Dim Color1 As Long
    Dim Color2 As Long
    Dim Color3 As Long
    Dim i As Long
    Dim j As Long
    Color1 = RGB(255, 0, 0)    '赤
    Color2 = RGB(0, 128, 0)    '緑
    Color3 = RGB(255, 220, 220) '肌色
    '顔
        '2行目
        For i = 5 To 9
            Cells(2, i).Interior.Color = Color1
        Next i
        '3行目
        For i = 4 To 12
            Cells(3, i).Interior.Color = Color1
        Next i
        '4行目
        For i = 4 To 6
            Cells(4, i).Interior.Color = Color2
        Next i
        For i = 7 To 8
            Cells(4, i).Interior.Color = Color3
        Next i
            Cells(4, i).Interior.Color = Color2
            i = i + 1
            Cells(4, i).Interior.Color = Color3
        '5行目
        i = 3
            Cells(5, i).Interior.Color = Color2
            i = i + 1
            Cells(5, i).Interior.Color = Color3
            i = i + 1
            Cells(5, i).Interior.Color = Color2
            i = i + 1
            Cells(5, i).Interior.Color = Color3
            i = i + 1
            Cells(5, i).Interior.Color = Color3
            i = i + 1
            Cells(5, i).Interior.Color = Color3
            i = i + 1
            Cells(5, i).Interior.Color = Color2
            i = i + 1
            Cells(5, i).Interior.Color = Color3
            i = i + 1
            Cells(5, i).Interior.Color = Color3
            i = i + 1
            Cells(5, i).Interior.Color = Color3
            i = i + 1
        '6行目
        i = 3
            Cells(6, i).Interior.Color = Color2
            i = i + 1
            Cells(6, i).Interior.Color = Color3
            i = i + 1
            Cells(6, i).Interior.Color = Color2
            i = i + 1
            For j = 1 To 2
                Cells(6, i).Interior.Color = Color2
                i = i + 1
                Cells(6, i).Interior.Color = Color3
                i = i + 1
                Cells(6, i).Interior.Color = Color3
                i = i + 1
                Cells(6, i).Interior.Color = Color3
                i = i + 1
            Next j
        '7行目
        i = 3
            For j = 1 To 2
                Cells(7, i).Interior.Color = Color2
                i = i + 1
            Next j
            For j = 1 To 4
                Cells(7, i).Interior.Color = Color3
                i = i + 1
            Next j
            For j = 1 To 4
                Cells(7, i).Interior.Color = Color2
                i = i + 1
            Next j
    '胴体と足
        '8行目
        i = 5
            For j = 1 To 7
                Cells(8, i).Interior.Color = Color3
                i = i + 1
            Next j
        '9行目
        i = 4
            For j = 1 To 2
                Cells(9, i).Interior.Color = Color2
                i = i + 1
            Next j
                Cells(9, i).Interior.Color = Color1
                i = i + 1
            For j = 1 To 3
                Cells(9, i).Interior.Color = Color2
                i = i + 1
            Next j
        '10行目
        i = 3
            For j = 1 To 3
                Cells(10, i).Interior.Color = Color2
                i = i + 1
            Next j
                Cells(10, i).Interior.Color = Color1
                i = i + 1
            For j = 1 To 2
                Cells(10, i).Interior.Color = Color2
                i = i + 1
            Next j
                Cells(10, i).Interior.Color = Color1
                i = i + 1
            For j = 1 To 3
                Cells(10, i).Interior.Color = Color2
                i = i + 1
            Next j
        '11行目
        i = 2
            For j = 1 To 4
                Cells(11, i).Interior.Color = Color2
                i = i + 1
            Next j
            For j = 1 To 4
                Cells(11, i).Interior.Color = Color1
                i = i + 1
            Next j
            For j = 1 To 4
                Cells(11, i).Interior.Color = Color2
                i = i + 1
            Next j
        '12行目
        i = 2
            For j = 1 To 2
                Cells(12, i).Interior.Color = Color3
                i = i + 1
            Next j
                Cells(12, i).Interior.Color = Color2
                i = i + 1
                Cells(12, i).Interior.Color = Color1
                i = i + 1
                Cells(12, i).Interior.Color = Color3
                i = i + 1
           For j = 1 To 2
                Cells(12, i).Interior.Color = Color1
                i = i + 1
            Next j
                Cells(12, i).Interior.Color = Color3
                i = i + 1
                Cells(12, i).Interior.Color = Color1
                i = i + 1
                Cells(12, i).Interior.Color = Color2
                i = i + 1
            For j = 1 To 2
                Cells(12, i).Interior.Color = Color3
                i = i + 1
            Next j
        '13行目
        i = 2
            For j = 1 To 3
                Cells(13, i).Interior.Color = Color3
                i = i + 1
            Next j
            For j = 1 To 6
                Cells(13, i).Interior.Color = Color1
                i = i + 1
            Next j
            For j = 1 To 3
                Cells(13, i).Interior.Color = Color3
                i = i + 1
            Next j
        '14行目
        i = 2
            For j = 1 To 2
                Cells(14, i).Interior.Color = Color3
                i = i + 1
            Next j
            For j = 1 To 8
                Cells(14, i).Interior.Color = Color1
                i = i + 1
            Next j
            For j = 1 To 2
                Cells(14, i).Interior.Color = Color3
                i = i + 1
            Next j
        '15行目
        i = 4
            For j = 1 To 3
                Cells(15, i).Interior.Color = Color1
                i = i + 1
            Next j
            i = i + 2
            For j = 1 To 3
                Cells(15, i).Interior.Color = Color1
                i = i + 1
            Next j
        '16行目
        i = 3
            For j = 1 To 3
                Cells(16, i).Interior.Color = Color2
                i = i + 1
            Next j
            i = i + 4
            For j = 1 To 3
                Cells(16, i).Interior.Color = Color2
                i = i + 1
            Next j
        '17行目
        i = 2
            For j = 1 To 4
                Cells(17, i).Interior.Color = Color2
                i = i + 1
            Next j
            i = i + 4
            For j = 1 To 4
                Cells(17, i).Interior.Color = Color2
                i = i + 1
            Next j
            Cells(1, 1).Select
        End Sub

次は左向きのドット絵です。

    Sub MarioL()
    Dim Color1 As Long
    Dim Color2 As Long
    Dim Color3 As Long
    Dim i As Long
    Dim j As Long
    Color1 = RGB(255, 0, 0)    '赤
    Color2 = RGB(0, 128, 0)    '緑
    Color3 = RGB(255, 220, 220) '肌色
    '顔
        '2行目
        For i = 6 To 10
            Cells(2, i).Interior.Color = Color1
        Next i
        '3行目
        For i = 3 To 11
            Cells(3, i).Interior.Color = Color1
        Next i
        '4行目
            i = 5
            Cells(4, i).Interior.Color = Color3
            i = i + 1
            Cells(4, i).Interior.Color = Color2
        For i = 7 To 8
            Cells(4, i).Interior.Color = Color3
        Next i
        For i = 9 To 11
            Cells(4, i).Interior.Color = Color2
        Next i
        '5行目
        For i = 3 To 5
            Cells(5, i).Interior.Color = Color3
        Next i
            Cells(5, i).Interior.Color = Color2
        For i = 7 To 9
            Cells(5, i).Interior.Color = Color3
        Next i
            Cells(5, i).Interior.Color = Color2
            i = i + 1
            Cells(5, i).Interior.Color = Color3
            i = i + 1
            Cells(5, i).Interior.Color = Color2
        '6行目
        i = 2
            For j = 1 To 2
                Cells(6, i).Interior.Color = Color3
                i = i + 1
                Cells(6, i).Interior.Color = Color3
                i = i + 1
                Cells(6, i).Interior.Color = Color3
                i = i + 1
                Cells(6, i).Interior.Color = Color2
                i = i + 1
            Next j
        i = 10
            Cells(6, i).Interior.Color = Color2
            i = i + 1
            Cells(6, i).Interior.Color = Color3
            i = i + 1
            Cells(6, i).Interior.Color = Color2
            i = i + 1
        '7行目
        i = 3
            For j = 1 To 4
                Cells(7, i).Interior.Color = Color2
                i = i + 1
            Next j
            For j = 1 To 4
                Cells(7, i).Interior.Color = Color3
                i = i + 1
            Next j
            For j = 1 To 2
                Cells(7, i).Interior.Color = Color2
                i = i + 1
            Next j
    '胴体と足
        '8行目
        i = 4
            For j = 1 To 7
                Cells(8, i).Interior.Color = Color3
                i = i + 1
            Next j
        '9行目
        i = 4
            For j = 1 To 2
                Cells(9, i).Interior.Color = Color2
                i = i + 1
            Next j
                Cells(9, i).Interior.Color = Color1
                i = i + 1
            For j = 1 To 3
                Cells(9, i).Interior.Color = Color2
                i = i + 1
            Next j
        '10行目
        i = 3
            For j = 1 To 3
                Cells(10, i).Interior.Color = Color2
                i = i + 1
            Next j
                Cells(10, i).Interior.Color = Color1
                i = i + 1
            For j = 1 To 2
                Cells(10, i).Interior.Color = Color2
                i = i + 1
            Next j
                Cells(10, i).Interior.Color = Color1
                i = i + 1
            For j = 1 To 3
                Cells(10, i).Interior.Color = Color2
                i = i + 1
            Next j
        '11行目
        i = 2
            For j = 1 To 4
                Cells(11, i).Interior.Color = Color2
                i = i + 1
            Next j
            For j = 1 To 4
                Cells(11, i).Interior.Color = Color1
                i = i + 1
            Next j
            For j = 1 To 4
                Cells(11, i).Interior.Color = Color2
                i = i + 1
            Next j
        '12行目
        i = 2
            For j = 1 To 2
                Cells(12, i).Interior.Color = Color3
                i = i + 1
            Next j
                Cells(12, i).Interior.Color = Color2
                i = i + 1
                Cells(12, i).Interior.Color = Color1
                i = i + 1
                Cells(12, i).Interior.Color = Color3
                i = i + 1
           For j = 1 To 2
                Cells(12, i).Interior.Color = Color1
                i = i + 1
            Next j
                Cells(12, i).Interior.Color = Color3
                i = i + 1
                Cells(12, i).Interior.Color = Color1
                i = i + 1
                Cells(12, i).Interior.Color = Color2
                i = i + 1
            For j = 1 To 2
                Cells(12, i).Interior.Color = Color3
                i = i + 1
            Next j
        '13行目
        i = 2
            For j = 1 To 3
                Cells(13, i).Interior.Color = Color3
                i = i + 1
            Next j
            For j = 1 To 6
                Cells(13, i).Interior.Color = Color1
                i = i + 1
            Next j
            For j = 1 To 3
                Cells(13, i).Interior.Color = Color3
                i = i + 1
            Next j
        '14行目
        i = 2
            For j = 1 To 2
                Cells(14, i).Interior.Color = Color3
                i = i + 1
            Next j
            For j = 1 To 8
                Cells(14, i).Interior.Color = Color1
                i = i + 1
            Next j
            For j = 1 To 2
                Cells(14, i).Interior.Color = Color3
                i = i + 1
            Next j
        '15行目
        i = 4
            For j = 1 To 3
                Cells(15, i).Interior.Color = Color1
                i = i + 1
            Next j
            i = i + 2
            For j = 1 To 3
                Cells(15, i).Interior.Color = Color1
                i = i + 1
            Next j
        '16行目
        i = 3
            For j = 1 To 3
                Cells(16, i).Interior.Color = Color2
                i = i + 1
            Next j
            i = i + 4
            For j = 1 To 3
                Cells(16, i).Interior.Color = Color2
                i = i + 1
            Next j
        '17行目
        i = 2
            For j = 1 To 4
                Cells(17, i).Interior.Color = Color2
                i = i + 1
            Next j
            i = i + 4
            For j = 1 To 4
                Cells(17, i).Interior.Color = Color2
                i = i + 1
            Next j
            Cells(1, 1).Select
        End Sub

コピーしてエクセルVBAに貼り付けてください。

コメント

タイトルとURLをコピーしました