Re: Help with Simple Graphics Demo
- Posted by euphoric <euphoric at cklester.com> Feb 13, 2004
- 558 views
Brian Broker wrote: >See code below... it may need some tweaking but it's a start. > > Brian, where did I screw this up? It's not drawing the complete lines... only the tops. And even some are not being drawn. :/ include Win32lib.ew without warning sequence last_graph_size last_graph_size = {0,0} -------------------------------------------------------------------------------- -- Window Window1 constant Window1 = createEx( Window, "Thrown Dice Chart", 0, 0, 0, 276, 113, 0, 0 ), txt_Sides = createEx( EditText, "6", Window1, 48, 8, 48, 20, 0, 0 ), LText3 = createEx( LText, "Sides", Window1, 12, 12, 36, 20, 0, 0 ), LText4 = createEx( LText, "QTY", Window1, 12, 36, 36, 20, 0, 0 ), txt_QTY = createEx( EditText, "3", Window1, 48, 32, 48, 20, 0, 0 ), LText6 = createEx( LText, "Rolls", Window1, 12, 60, 36, 20, 0, 0 ), txt_Rolls = createEx( EditText, "1000", Window1, 48, 56, 48, 20, 0, 0 ), bttn_Roll = createEx( PushButton, "Roll", Window1, 104, 8, 156, 68, 0, 0 ), Graph = 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() ------------------------------ procedure bttn_Roll_onClick (integer self, integer event, sequence params)--params is () atom width, gWidth, height integer dice_num, dice_sides, dice_rolls, roll, slot, maxVal sequence dice_results, graph_size, rolls -- clear last graph if not equal( last_graph_size, {0,0}) then -- clear it setPenColor( Graph, getSysColor( COLOR_BTNFACE ) ) drawRectangle ( Graph, W32_True, 0, 0, last_graph_size[1], last_graph_size[2] ) copyBlt( Window1,8,84,Graph) end if dice_num = getNumber( txt_QTY ) dice_sides = getNumber( txt_Sides ) dice_rolls = getNumber( txt_Rolls ) dice_results = repeat(0,dice_sides*dice_num-dice_num+1) -- first get a set of numbers rolls = {} for i = 1 to dice_rolls do roll = 0 for j = 1 to dice_num do roll += rand( dice_sides ) end for slot = roll-dice_num+1 dice_results[slot] += 1 rolls &= slot end for maxVal = 0 for t=1 to length(dice_results) do if maxVal < dice_results[t] then maxVal = dice_results[t] end if end for -- now set window height graph_size = { 30*(dice_sides*dice_num-dice_num+1)+25, maxVal } gWidth = graph_size[1]+20 if gWidth < 276 then gWidth = 276 end if setCtlSize( Graph, graph_size[1], graph_size[2] ) setCtlSize( Window1, gWidth, graph_size[2]+113 ) setPenColor( Graph, Black ) for i = dice_num to dice_num*dice_sides do setPenPos( Graph, 30*(i-dice_num), graph_size[2]-15 ) wPrintf( Graph, "%d", {i} ) end for for i=1 to dice_rolls do slot = rolls[i] drawLine(Graph,30*(slot)-30,graph_size[2]-20-dice_results[slot], 30*(slot)-20,graph_size[2]-20-dice_results[slot]) copyBlt(Window1,8,84,Graph) end for last_graph_size = graph_size -- ? dice_results end procedure setHandler( bttn_Roll, w32HClick, routine_id("bttn_Roll_onClick")) ------------------------------ procedure txt_onChange (integer self, integer event, sequence params)--params is () -- update button when txt_Sides, txt_Rolls, or txt_QTY changes update_roll_button() end procedure setHandler( {txt_Sides,txt_Rolls,txt_QTY}, w32HChange, routine_id("txt_onChange")) ------------------------------ procedure paintWindow( integer self, integer event, sequence params ) copyBlt(Window1,8,84,Graph) end procedure setHandler( Window1, w32HPaint, routine_id("paintWindow") ) ------------------------------ WinMain( Window1,Normal ) ------------------------------