22import datashader as ds
33from datashader .transfer_functions import shade
44from datashader .transfer_functions import stack
5- from datashader .transfer_functions import dynspread
6- from datashader .transfer_functions import set_background
75from datashader .colors import Elevation
86
97
2321
2422terrain = generate_terrain (canvas = cvs )
2523
24+
2625def heights (locations , src , src_range , height = 20 ):
2726 num_bumps = locations .shape [0 ]
2827 out = np .zeros (num_bumps , dtype = np .uint16 )
@@ -35,11 +34,15 @@ def heights(locations, src, src_range, height=20):
3534 out [r ] = height
3635 return out
3736
37+
3838T = 300000 # Number of trees to add per call
3939src = terrain .data
40- trees = bump (W , H , count = T , height_func = partial (heights , src = src , src_range = (1000 , 1300 ), height = 5 ))
41- trees += bump (W , H , count = T // 2 , height_func = partial (heights , src = src , src_range = (1300 , 1700 ), height = 20 ))
42- trees += bump (W , H , count = T // 3 , height_func = partial (heights , src = src , src_range = (1700 , 2000 ), height = 5 ))
40+ trees = bump (W , H , count = T , height_func = partial (heights , src = src ,
41+ src_range = (1000 , 1300 ), height = 5 ))
42+ trees += bump (W , H , count = T // 2 , height_func = partial (
43+ heights , src = src , src_range = (1300 , 1700 ), height = 20 ))
44+ trees += bump (W , H , count = T // 3 , height_func = partial (
45+ heights , src = src , src_range = (1700 , 2000 ), height = 5 ))
4346
4447tree_colorize = trees .copy ()
4548tree_colorize .data [tree_colorize .data == 0 ] = np .nan
@@ -51,6 +54,7 @@ def heights(locations, src, src_range, height=20):
5154water = mean (water , passes = 50 , excludes = [LAND_CONSTANT ])
5255water .data [water .data == LAND_CONSTANT ] = np .nan
5356
57+
5458def create_map (azimuth ):
5559
5660 global cvs
@@ -59,10 +63,11 @@ def create_map(azimuth):
5963 global trees
6064
6165 img = stack (shade (terrain , cmap = Elevation , how = 'linear' ),
62- shade (water , cmap = ['aqua' , 'white' ]),
63- shade (hillshade (terrain + trees , azimuth = azimuth ), cmap = ['black' , 'white' ], how = 'linear' , alpha = 128 ),
64- shade (tree_colorize , cmap = 'limegreen' , how = 'linear' )
65- )
66+ shade (water , cmap = ['aqua' , 'white' ]),
67+ shade (hillshade (terrain + trees , azimuth = azimuth ),
68+ cmap = ['black' , 'white' ], how = 'linear' , alpha = 128 ),
69+ shade (tree_colorize , cmap = 'limegreen' , how = 'linear' )
70+ )
6671
6772 print ('image created' )
6873
@@ -85,29 +90,33 @@ def create_map2():
8590 yield img .to_pil ()
8691
8792 img = stack (shade (terrain , cmap = Elevation , how = 'linear' ),
88- shade (hillshade (terrain , azimuth = 210 ), cmap = ['black' , 'white' ], how = 'linear' , alpha = 128 ),
89- )
93+ shade (hillshade (terrain , azimuth = 210 ),
94+ cmap = ['black' , 'white' ], how = 'linear' , alpha = 128 ),
95+ )
9096
9197 yield img .to_pil ()
9298
9399 img = stack (shade (terrain , cmap = Elevation , how = 'linear' ),
94- shade (water , cmap = ['aqua' , 'white' ]),
95- shade (hillshade (terrain , azimuth = 210 ), cmap = ['black' , 'white' ], how = 'linear' , alpha = 128 ),
96- )
100+ shade (water , cmap = ['aqua' , 'white' ]),
101+ shade (hillshade (terrain , azimuth = 210 ),
102+ cmap = ['black' , 'white' ], how = 'linear' , alpha = 128 ),
103+ )
97104
98105 yield img .to_pil ()
99106
100107 img = stack (shade (terrain , cmap = Elevation , how = 'linear' ),
101- shade (water , cmap = ['aqua' , 'white' ]),
102- shade (hillshade (terrain + trees , azimuth = 210 ), cmap = ['black' , 'white' ], how = 'linear' , alpha = 128 ),
103- shade (tree_colorize , cmap = 'limegreen' , how = 'linear' )
104- )
108+ shade (water , cmap = ['aqua' , 'white' ]),
109+ shade (hillshade (terrain + trees , azimuth = 210 ),
110+ cmap = ['black' , 'white' ], how = 'linear' , alpha = 128 ),
111+ shade (tree_colorize , cmap = 'limegreen' , how = 'linear' )
112+ )
105113
106114 yield img .to_pil ()
107115 yield img .to_pil ()
108116 yield img .to_pil ()
109117 yield img .to_pil ()
110118
119+
111120def gif1 ():
112121
113122 images = []
@@ -119,6 +128,7 @@ def gif1():
119128 save_all = True , append_images = images [1 :],
120129 optimize = False , duration = 5000 , loop = 0 )
121130
131+
122132def gif2 ():
123133
124134 images = list (create_map2 ())
@@ -127,4 +137,5 @@ def gif2():
127137 save_all = True , append_images = images [1 :],
128138 optimize = False , duration = 1000 , loop = 0 )
129139
140+
130141gif2 ()
0 commit comments