Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # calls all functions and does simulation and does intial
- def project2(c,x,y,pInit,pFire,pLocl,pDist):
- import random
- forest=makeEmptyPicture(x,y)
- addRectFilled(forest, 0, 0, x, y, black)
- addRectFilled(forest, 1, 1, x-2, y-2, white)
- intial=forest
- #this intialy adds trees to the black canvas with a black boarder
- for p in getPixels(intial):
- blue=getBlue(p)
- if (blue == 255):
- if random.random() < pInit:
- setColor(p,green)
- show(forest)
- #this simulate the fire for c cycles
- for cycle in range(0, c):
- copy=duplicatePicture(forest)
- for col in range(1, getWidth(forest) - 1):
- for row in range(1, getHeight(forest) - 1):
- localGreen = localG(copy, col, row)
- localRed = localR(copy, col, row)
- pixel = getPixel(forest, col, row)
- if getColor(pixel) == green and localRed > 0:
- setColor(pixel,red)
- elif getColor(pixel) == green:
- if random.random() < pFire:
- setColor(pixel,red)
- elif getColor(pixel) == red:
- setColor(pixel,white)
- elif getColor(pixel) == white:
- rand=(pDist + pLocl * localGreen)
- if random.random() < rand:
- setColor(pixel,green)
- repaint(forest)
- #this finds how many green pixels are around a certain pixel
- def localG(forest, x, y):
- lp=forest
- count = 0
- if getColor(getPixel(lp, x-1, y-1)) == green:
- count = count + 1
- if getColor(getPixel(lp, x, y-1)) == green:
- count = count + 1
- if getColor(getPixel(lp, x+1, y-1)) == green:
- count = count + 1
- if getColor(getPixel(lp, x-1, y)) == green:
- count = count + 1
- if getColor(getPixel(lp, x+1, y)) == green:
- count = count + 1
- if getColor(getPixel(lp, x-1, y+1)) == green:
- count = count + 1
- if getColor(getPixel(lp, x, y+1)) == green:
- count = count + 1
- if getColor(getPixel(lp, x+1, y+1)) == green:
- count = count + 1
- return count
- #this finds how many red pixels are around a certain pixel
- def localR(forest, x, y):
- lp=forest
- count = 0
- if getColor(getPixel(lp, x-1, y-1)) == red:
- count = count + 1
- elif getColor(getPixel(lp, x, y-1)) == red:
- count = count + 1
- elif getColor(getPixel(lp, x+1, y-1)) == red:
- count = count + 1
- elif getColor(getPixel(lp, x-1, y)) == red:
- count = count + 1
- elif getColor(getPixel(lp, x+1, y)) == red:
- count = count + 1
- elif getColor(getPixel(lp, x-1, y+1)) == red:
- count = count + 1
- elif getColor(getPixel(lp, x, y+1)) == red:
- count = count + 1
- elif getColor(getPixel(lp, x+1, y+1)) == red:
- count = count + 1
- return count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement