Producing realistic dice images.

I wanted to generate the display programmatically ( rather than from predrawn images), putting repeated images of the dot in the right places on a die face. Two different ways were tried. One was MUCH neater coding than the other. As a side effect you can generate dice displaying dots for up to a 9.

The single dot image - and the blank die.


LB code

( download as zip including images)


    nomainwin

    WindowWidth  =140
    WindowHeight =170

    open "Dice generator- 2 to 9" for graphics_nsb as #wg

    #wg "trapclose quit"
    #wg "down ; fill 200 200 80"

    loadbmp "die", "blankDie.bmp"
    loadbmp "dot",      "dot.bmp"

    for i =1 to 9
        #wg "cls ; fill 200 200 80 ; drawbmp die 18 10"
        call drawDots i

        #wg "getbmp dieA 18 10 110 110"
        bmpsave "dieA", "die" +str$( i) +".bmp"

        timer 1000, [p]
        wait
        [p]
        timer 0
    next

    wait

    sub drawDots i
        select case i
            case 1
                call Dots "4"
            case 2
                call Dots "17"
            case 3
                call Dots "147"
            case 4
                call Dots "1357"
            case 5
                call Dots "13457"
            case 6
                call Dots "123567"
            case 7
                call Dots "1235674"
            case 8
                call Dots "12356789"
            case 9
                call Dots "123567489"
        end select
    end sub

    sub Dots i$
        for j =1 to len( i$)
            select case mid$( i$, j, 1)
            case "1"
                #wg "drawbmp dot 50 30"
            case "2"
                #wg "drawbmp dot 50 52"
            case "3"
                #wg "drawbmp dot 50 74"
            case "4"
                #wg "drawbmp dot 70 52"
            case "5"
                #wg "drawbmp dot 90 30"
            case "6"
                #wg "drawbmp dot 90 52"
            case "7"
                #wg "drawbmp dot 90 74"
            case "8"
                #wg "drawbmp dot 70 30"
            case "9"
                #wg "drawbmp dot 70 74"
            end select
        next j
    end sub

    sub quit h$
        close #wg
        end
    end sub