@@ -734,64 +734,6 @@ def draw_scatter_plot(world, size, target):
734734 target .set_pixel (int (nx ), (size - 1 ) - int (ny ), (r , 128 , b , 255 ))
735735
736736
737- def draw_hypsographic_plot (world , target , x_bins , y_bins ):
738- # Will draw a Hypsograhpic plot that contains information about the distribution of elevations in the world.
739- # y-axis shows the elevation, x-axis shows how often a certain elevation occurs.
740- # For further details see:
741- # https://en.wikipedia.org/wiki/Elevation#Hypsography
742- # http://www.ngdc.noaa.gov/mgg/global/etopo1_surface_histogram.html
743-
744- assert int (x_bins ) > 0 and int (y_bins ) > 0 , "Hypsographic curve needs more than 0 bins."
745-
746- # set colors
747- color_none = target .get_max_colors () # white
748- color_full = int (color_none / 2 ) # gray
749- color_line = 0 # black
750- color_percent_sep = int (color_none * 0.8 ) # light-gray
751-
752- # Prepare a list of available elevations. Scale them to the y-axis and put them into a sorted list,
753- # smallest point to highest.
754- e = world .elevation ['data' ]
755- e_min = e .min ()
756- e_max = e .max ()
757- e = (e - e_min ) / (e_max - e_min ) # normalize to [0, 1]
758- e *= int (y_bins ) - 0.01 # instead of "- 1", small trick to make the last bin contain more than one point
759- e = numpy .sort (e , axis = None ) # flatten the array and order values by height
760- e = e .astype (dtype = numpy .uint16 ) # do not round (the graph wouldn't change, just shift)
761-
762- # Fill the plot.
763- # Start by calculating how many points of the heightmap have to be represented by a single bin (n).
764- # Then step through the bins and fill in points from highest to lowest. Every bin is set to the average height of
765- # the n points it represents.
766- # Instead of drawing to [y, x] draw to [y_bins - y - 1, x_bins - x - 1] to flip the output in x- and y-direction.
767- n = e .size / float (x_bins )
768- for x in range (x_bins ):
769- avg = sum (e [int (x * n ):int ((x + 1 ) * n )])
770- avg = int (avg / float (n )) # average height of n height-points
771- for y in range (y_bins ):
772- target [y_bins - y - 1 , x_bins - x - 1 ] = color_none if y > avg else color_full
773-
774- # Draw a vertical line every ten percent.
775- step = x_bins / 10.0
776- for i in range (1 , 10 ): # no lines at 0 and (x_bins - 1)
777- x = int (step * i )
778- for y in range (y_bins ):
779- target [y , x_bins - x - 1 ] = color_percent_sep
780-
781- # Map sea-level etc. to appropriate y-positions in the graph.
782- lines = []
783- for threshold in world .elevation ['thresholds' ]: # see generation.py->initialize_ocean_and_thresholds() for details
784- if threshold [1 ] is None :
785- continue # TODO: remove if the thresholds are ever guaranteed to be numbers
786- lines .append (int (numpy .interp (threshold [1 ], [e_min , e_max ], [0 , y_bins ])))
787-
788- # Draw lines for sea-level, hill-level etc. The lines will get lighter with increasing height.
789- for i in range (len (lines )):
790- color = numpy .interp (i , [0 , len (lines )], [color_line , color_none ])
791- for x in range (x_bins ):
792- target [y_bins - lines [i ] - 1 , x ] = color
793-
794-
795737# -------------
796738# Draw on files
797739# -------------
@@ -869,14 +811,6 @@ def draw_scatter_plot_on_file(world, filename):
869811 img .complete ()
870812
871813
872- def draw_hypsographic_plot_on_file (world , filename ):
873- x_bins = 800
874- y_bins = 600
875- img = PNGWriter .grayscale_from_dimensions (x_bins , y_bins , filename , channel_bitdepth = 8 )
876- draw_hypsographic_plot (world , img , x_bins , y_bins )
877- img .complete ()
878-
879-
880814def draw_satellite_on_file (world , filename ):
881815 img = PNGWriter .rgba_from_dimensions (world .width , world .height , filename )
882816 draw_satellite (world , img )
0 commit comments