Re: Help with Simple Graphics Demo

new topic     » goto parent     » topic index » view thread      » older message » newer message

Here's my take.  Needs some tweaking.

include Win32lib.ew
without warning

--------------------------------------------------------------------------------
--  Window Window1
constant Window1 = createEx( Window, "Thrown Dice Chart", 0, Default,
Default, 276, 300, 0, 0 )
constant txt_Sides = createEx( EditText, "6", Window1, 48, 8, 48, 20, 0, 0 )
constant LText3 = createEx( LText, "Sides", Window1, 12, 12, 36, 20, 0, 0 )
constant LText4 = createEx( LText, "QTY", Window1, 12, 36, 36, 20, 0, 0 )
constant txt_QTY = createEx( EditText, "3", Window1, 48, 32, 48, 20, 0, 0 )
constant LText6 = createEx( LText, "Rolls", Window1, 12, 60, 36, 20, 0, 0 )
constant txt_Rolls = createEx( EditText, "1000", Window1, 48, 56, 48,
20, 0, 0 )
constant bttn_Roll = createEx( PushButton, "Roll", Window1, 104, 8, 156,
68, 0, 0 )
constant Bitmap9 = createEx( Pixmap, "Bitmap9", Window1, 8, 84, 252,
184, 0, 0 )

procedure update_roll_button()  
    setText( bttn_Roll, getText( txt_QTY ) & "d" & getText( txt_Sides )
& " x " & getText( txt_Rolls ) )
end procedure

update_roll_button()

setHandler( txt_Sides, w32HChange, routine_id("txt_Sides_onChange"))
integer BIGGEST, WIDTH, HEIGHT

    roll = 0
    BIGGEST = 0
    dice_num = getNumber( txt_QTY )
    dice_sides = getNumber( txt_Sides )
    dice_rolls = getNumber( txt_Rolls )
    dice_results = repeat(0,dice_sides*dice_num)
   
    WIDTH = floor(244/(dice_num*dice_sides))
    HEIGHT = floor(100/(dice_num*dice_sides))
   
    for t=1 to dice_rolls do
        roll = 0
        for t2 = 1 to dice_num do
            roll += floor(rand(dice_sides*1000)/1000)+1
           end for
        dice_results[roll] += 1

        if dice_results[roll] > BIGGEST then   
            BIGGEST = dice_results[roll]
        end if
    end for
    setPenColor(Bitmap9,Black)
    drawRectangle(Bitmap9,1,0,0,244,183)
    setPenColor(Bitmap9,BrightRed)
    for loop = 1 to length(dice_results) do
        drawRectangle(Bitmap9,1,(loop-1) * WIDTH,183,((loop-1) * 
WIDTH)+WIDTH,183-(183-floor((dice_results[loop]/BIGGEST)*100)))
    end for
    copyBlt(Window1,8,80,Bitmap9)
end procedure
setHandler( bttn_Roll, w32HClick, routine_id("bttn_Roll_onClick"))
setHandler( txt_QTY, w32HChange, routine_id("txt_QTY_onChange"))
setHandler( txt_Rolls, w32HChange, routine_id("txt_Rolls_onChange"))


WinMain( Window1,Normal )

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu