UserPreferences

CellularAutomatonPercolationModel


globals [new-mouse-down?]

to initialize
    clear-all
    ask patches [
        ifelse random 100 < initial-green-density * 100 [set pcolor green][set pcolor black]
        if abs pxcor = screen-edge-x [set pcolor black]
        if abs pycor = screen-edge-y [set pcolor black]
    ]
end


to go-once
    
    if mouse-down? and new-mouse-down? [
        set new-mouse-down? false
        ask patch (round mouse-xcor) (round mouse-ycor) [
            if pcolor = green [set pcolor red]
        ]
    ]
    ask patches with [pcolor = red] [
        ask neighbors4 with [pcolor = green] [set pcolor red]
    ]
    
    if not mouse-down? [
        set new-mouse-down? true
        ask patches with [pcolor = red] [set pcolor green]
    ]
end