1. RE: Help with Simple Graphics Demo
- Posted by Brian Broker <bkb at cnw.com> Feb 13, 2004
- 537 views
Where's the "fun" when you want somebody else to do it? -- Brian euphoric wrote: > > > Here's something just for fun. I was wondering if somebody could > complete the missing puzzle piece for me...
2. RE: Help with Simple Graphics Demo
- Posted by Brian Broker <bkb at cnw.com> Feb 13, 2004
- 541 views
I am, by no means, offended and I'm working on it "for fun" but it's most certainly not the easiest thing I've done... -- Brian euphoric wrote: > > > Brian Broker wrote: > > > > >Where's the "fun" when you want somebody else to do it? > > > > > It's only missing a piece of the puzzle! I've already done all the hard > work. :) > > Look, I've seen tons of questions posted to this group about, "Can > somebody do this..." or "How do I do that?" Ultimately, somebody posts > code to do what the requestor requested. I figured I'd get the same kind > > of response. > > I'll do it myself when I have a spare moment... I just thought somebody > might be interested in helping out (thereby getting it done quicker). > > I apologize if I offended you in any way. > >
3. RE: Help with Simple Graphics Demo
- Posted by Brian Broker <bkb at cnw.com> Feb 13, 2004
- 537 views
See code below... it may need some tweaking but it's a start. -- Brian euphoric wrote: > > > C. K. Lester wrote: > > > As an example (use non-proportional font to view)... > > > > | > > |||| > > |||||| > > 123456 > > > > A nice bell curve should be expected on 3d6x1000. > > Oops! That bell curve should be looking like this: > > || > ||| > |||||||| > |||||||||||| > |||||||||||||||| > 3456789012345678 > > (valid values are 3 to 18) include Win32lib.ew without warning -------------------------------------------------------------------------------- -- 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 ) -------------------------------------------------------------------------------- function prepare_graph() integer dice_num, dice_sides, dice_rolls, width, height dice_num = getNumber( txt_QTY ) dice_sides = getNumber( txt_Sides ) dice_rolls = getNumber( txt_Rolls ) width = dice_sides*dice_num-dice_num+1 height = dice_rolls/2 setCtlSize( Graph, 30*width+20, height ) setCtlSize( Window1, 30*width+20, height+113 ) for i = dice_num to dice_num*dice_sides do setPenPos( Graph, 30*(i-dice_num), height - 20 ) wPrintf( Graph, "%d", {i} ) end for copyBlt(Window1,8,84,Graph) -- return the size of the graph return {30*width+20, height} end function ------------------------------ 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 () integer dice_num, dice_sides, dice_rolls, roll, slot sequence dice_results, graph_size graph_size = prepare_graph() 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) 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 setPenColor( Graph, Black ) 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 ? 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 ) ------------------------------
4. RE: Help with Simple Graphics Demo
- Posted by Brian Broker <bkb at cnw.com> Feb 14, 2004
- 531 views
euphoric wrote: > Brian, where did I screw this up? It's not drawing the complete lines... > > only the tops. And even some are not being drawn. :/ A quick look reveals that the heart of the bar drawing is no longer a nested loop as it should be... 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 setPenColor( Graph, Black ) 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
5. RE: Help with Simple Graphics Demo
- Posted by Brian Broker <bkb at cnw.com> Feb 14, 2004
- 530 views
Oh, now I see what you are trying to do. You want to set the window height to account for the biggest number you'll get in the set. Since the y-value of the line is based on dice_results[slot], you'll need to rebuild that sequence... try this: dice_results = repeat(0,dice_sides*dice_num-dice_num+1) for i=1 to dice_rolls do slot = rolls[i] dice_results[slot] += 1 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 Brian Broker wrote: > > > euphoric wrote: > > Brian, where did I screw this up? It's not drawing the complete lines... > > > > > > only the tops. And even some are not being drawn. :/ > > > A quick look reveals that the heart of the bar drawing is no longer in a > > nested loop as it should be...
6. RE: Help with Simple Graphics Demo
- Posted by Brian Broker <bkb at cnw.com> Feb 15, 2004
- 556 views
Hey CK, A thought just came to mind that you might want to donate some code as a Win32Lib demo before it gets too complicated. At least it's a way to keep it from getting buried into the list. I donated my defective 'dots' demos and they easily made in into the distro. (personally, I think most of the current demos suck; this one would actually be "fun"). -- Brian EUPHORiCK wrote: > > > Brian Broker wrote: > > >Oh, now I see what you are trying to do. You want to set the window > >height to account for the biggest number you'll get in the set. Since > >the y-value of the line is based on dice_results[slot], you'll need to > >rebuild that sequence... try this: > > > > dice_results = repeat(0,dice_sides*dice_num-dice_num+1) > > for i=1 to dice_rolls do > > slot = rolls[i] > > dice_results[slot] += 1 > > 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 > > > > > Works great, Brian. Thanks a LOT for your help. :)
7. RE: Help with Simple Graphics Demo
- Posted by Brian Broker <bkb at cnw.com> Feb 15, 2004
- 510 views
mmmm... crap. My bad. Meant to send this privately. (no offense intended to the hard-working D.P.) Brian Broker wrote: > > > Hey CK, <snip>