Not sure about 'BlitzMax Beginners Area', i need a 'BlitzMax Forum Beginners Area' to hone my posting skills ;) Here goes for the third time, hopefully with a codebox, a couple more comments and better formatting, preview post was a good idea this time too...
Anyway, thanks for bearing with me, any comments (about my code, rather than my lack of forum skill) would still be appreciated :)
'---------------------------------------- ' Matt's little radioactive decay program '---------------------------------------- '-------------------------------- ' Setup variables '-------------------------------- Strict Global atoms[24,24] 'an array to hold the states of all the atoms, 1 = active, 0 = decayed Global undecayed[100] 'an array to store the number of undecayed atoms after each second Global time:Int = 0 Global graphx:Int = 390 'position of graph on screen Global graphy:Int = 110 'position of graph on screen Global atomx:Int = 100 'position of atoms diagram on screen Global atomy:Int = 100 'position of atoms diagram on screen Global probofdecay:Float = 0.05 'probability of atom decaying each second Global height:Int = 600 Global width:Int = 800 Const hdivision:Int = 600/20 'for drawing gradient background SeedRnd MilliSecs() ' -------------- ' Start graphics ' -------------- 'SetGraphicsDriver GLMax2DDriver() Graphics width,height,24 '----------- ' initialise '----------- newstart() ' --------- ' main loop ' --------- While Not KeyHit(KEY_ESCAPE) If KeyHit(KEY_SPACE) And time < 99 For Local t = 1 To 99 time:+1 decayatoms() drawatoms() countatoms() drawscreen() Next EndIf If KeyHit(KEY_SPACE) And time = 99 newstart() EndIf If KeyHit(KEY_ESCAPE) FlushMem End EndIf Wend End '========== FUNCTIONS ================ '------------------------------------------------------- ' populate atoms - sets every atom in array atoms() to 1 '------------------------------------------------------- Function populateatoms() For Local x:Int = 0 To 23 For Local y:Int = 0 To 23 atoms[x,y] = 1 Next Next EndFunction '------------------------------------------------------------------------ ' draw atoms - draw the square of atoms, colour coded, to the back buffer '------------------------------------------------------------------------ Function drawatoms() For Local x:Int = 0 To 23 For Local y:Int = 0 To 23 If atoms[x,y] = 1 SetColor ((atoms[x,y] * 255),0,0) Else SetColor(0,0,128) EndIf DrawText "o",(10 + (x * 10))+atomx,(10 + (y * 10))+atomy Next Next EndFunction '---------------------------------------------------- ' count atoms - counts the number of atoms remaining (i.e. equal to 1) '---------------------------------------------------- Function countatoms() For Local x:Int = 0 To 23 For Local y:Int = 0 To 23 undecayed[time] = undecayed[time] + atoms[x,y] Next Next EndFunction '----------------------------------------------------------------- ' decay atoms - change array value to 0 for each atom which decays '----------------------------------------------------------------- Function decayatoms() ' decay atoms For Local x:Int = 0 To 23 For Local y:Int = 0 To 23 If atoms[x,y] = 1 And Rnd() < probofdecay atoms[x,y] = 0 EndIf Next Next EndFunction '-------------------------- ' draw graph to back buffer '-------------------------- Function drawgraph() SetColor(255,255,255) DrawRect(graphx,graphy,305,305) For Local x = 0 To time SetColor(0,0,0) DrawOval((x * 3)+graphx,(Int(((Float(undecayed[0]) - Float(undecayed[x]))/Float(undecayed[0]))*300))+graphy,5,5) If x>0 SetColor(0,0,255) DrawOval((x*3)+graphx,(300-Int(((Float(undecayed[x-1]) - Float(undecayed[x]))/Float(undecayed[0]))*300))+graphy,5,5) EndIf Next SetColor(0,0,0) SetClsColor(0,0,0) EndFunction '---------------------------------------------- ' drawscreen - draws the screen image and flips '---------------------------------------------- Function drawscreen() SetClsColor(0,0,64) Cls drawbg() SetColor(255,255,0) DrawText("Probability of Decay = "+Int(probofdecay*100)+"%",70,430) DrawText("Atoms Remaining = "+undecayed[time],70,370) DrawText("Time = "+time+" seconds (99 max)",70,400) If time < 99 DrawText("Press <SPACE> to start",70,460) Else DrawText("Press <ESCAPE> to exit or <SPACE> to reset.",70,460) EndIf SetColor(255,255,255) DrawText "MemUsage="+MemUsage(),0,0 drawatoms() drawgraph() Flip FlushMem EndFunction '------------------------------------------------------- ' drawbg - draws the background & non-changing text etc. '------------------------------------------------------- Function drawbg() Local intensity:Int = 0 For Local h:Int = 0 To height Step hdivision intensity:+1 SetColor(0,0,intensity*5) DrawRect(0,h,width,hdivision) Next SetColor(255,255,255) DrawRect(graphx-10,graphy-10,325,360) SetColor(0,0,0) DrawRect(graphx-5,graphy-5,315,350) SetColor(255,255,255) DrawRect(graphx,graphy+310,305,30) SetColor(0,0,0) DrawText("Atoms Remaining",graphx+20,graphy+315) SetColor(0,0,255) DrawText("Activity",graphx+220,graphy+315) SetBlend(ALPHABLEND) SetAlpha(0.2) SetColor(255,255,255) DrawRect(atomx+5,atomy+8,250,250) SetScale(6,6) DrawText("ATOMS",atomx+10,atomy+100) SetAlpha(1) SetBlend(MASKBLEND) SetScale(1,1) EndFunction '---------------------------------------- ' newstart - reset to original conditions '---------------------------------------- Function newstart() time = 0 populateatoms() countatoms() drawscreen() EndFunction
Anyway, thanks for bearing with me, any comments (about my code, rather than my lack of forum skill) would still be appreciated :)