Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. # calls all functions and does simulation and does intial
  2. def project2(c,x,y,pInit,pFire,pLocl,pDist):
  3. import random
  4. forest=makeEmptyPicture(x,y)
  5. addRectFilled(forest, 0, 0, x, y, black)
  6. addRectFilled(forest, 1, 1, x-2, y-2, white)
  7. intial=forest
  8.  
  9.  
  10. #this intialy adds trees to the black canvas with a black boarder
  11. for p in getPixels(intial):
  12. blue=getBlue(p)
  13. if (blue == 255):
  14. if random.random() < pInit:
  15. setColor(p,green)
  16. show(forest)
  17.  
  18.  
  19. #this simulate the fire for c cycles
  20. for cycle in range(0, c):
  21. copy=duplicatePicture(forest)
  22. for col in range(1, getWidth(forest) - 1):
  23. for row in range(1, getHeight(forest) - 1):
  24. localGreen = localG(copy, col, row)
  25. localRed = localR(copy, col, row)
  26. pixel = getPixel(forest, col, row)
  27. if getColor(pixel) == green and localRed > 0:
  28. setColor(pixel,red)
  29. elif getColor(pixel) == green:
  30. if random.random() < pFire:
  31. setColor(pixel,red)
  32. elif getColor(pixel) == red:
  33. setColor(pixel,white)
  34. elif getColor(pixel) == white:
  35. rand=(pDist + pLocl * localGreen)
  36. if random.random() < rand:
  37. setColor(pixel,green)
  38. repaint(forest)
  39.  
  40.  
  41.  
  42. #this finds how many green pixels are around a certain pixel
  43. def localG(forest, x, y):
  44. lp=forest
  45. count = 0
  46. if getColor(getPixel(lp, x-1, y-1)) == green:
  47. count = count + 1
  48. if getColor(getPixel(lp, x, y-1)) == green:
  49. count = count + 1
  50. if getColor(getPixel(lp, x+1, y-1)) == green:
  51. count = count + 1
  52. if getColor(getPixel(lp, x-1, y)) == green:
  53. count = count + 1
  54. if getColor(getPixel(lp, x+1, y)) == green:
  55. count = count + 1
  56. if getColor(getPixel(lp, x-1, y+1)) == green:
  57. count = count + 1
  58. if getColor(getPixel(lp, x, y+1)) == green:
  59. count = count + 1
  60. if getColor(getPixel(lp, x+1, y+1)) == green:
  61. count = count + 1
  62. return count
  63.  
  64. #this finds how many red pixels are around a certain pixel
  65. def localR(forest, x, y):
  66. lp=forest
  67. count = 0
  68. if getColor(getPixel(lp, x-1, y-1)) == red:
  69. count = count + 1
  70. elif getColor(getPixel(lp, x, y-1)) == red:
  71. count = count + 1
  72. elif getColor(getPixel(lp, x+1, y-1)) == red:
  73. count = count + 1
  74. elif getColor(getPixel(lp, x-1, y)) == red:
  75. count = count + 1
  76. elif getColor(getPixel(lp, x+1, y)) == red:
  77. count = count + 1
  78. elif getColor(getPixel(lp, x-1, y+1)) == red:
  79. count = count + 1
  80. elif getColor(getPixel(lp, x, y+1)) == red:
  81. count = count + 1
  82. elif getColor(getPixel(lp, x+1, y+1)) == red:
  83. count = count + 1
  84. return count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement