11/** @format */
22
33import type { Tile } from "@derivean/chunk" ;
4- import { HSLA , hslaToRgba , type Color } from "@derivean/utils" ;
5-
6- /**
7- * Color definitions for different land types
8- * Using HSLA as it's easier to make color transitions
9- */
10- const COLOR_MAP = {
11- mountain : HSLA ( [ 0 , 0 , 35 , 1 ] ) , // Gray mountains
12- platau : HSLA ( [ 30 , 60 , 70 , 1 ] ) , // Brownish plateaus
13- valley : HSLA ( [ 115 , 50 , 32 , 1 ] ) , // Dark green valleys
14- hill : HSLA ( [ 85 , 65 , 50 , 1 ] ) , // Lighter green hills
15- plain : HSLA ( [ 60 , 70 , 75 , 1 ] ) , // Yellowish plains
16- } ;
4+ import { HSLA , hslaToRgba , mapNoiseToColor , type Color } from "@derivean/utils" ;
175
186export namespace withColorMap {
197 export interface Props {
@@ -22,61 +10,18 @@ export namespace withColorMap {
2210}
2311
2412/**
25- * Maps noise values to HSLA/ RGBA colors based on the strength of each land type
26- * Blends colors based on the relative strength of each land type
13+ * Maps a noise value to an RGBA color based on the provided color map
14+ * Currently uses heightmap as the primary source for color mapping
2715 */
2816export const withColorMap = ( { tile } : withColorMap . Props ) : Color . RGBA => {
29- // Extract land properties
30- const { mountain, platau, valley, hill, plain } = tile . land ;
31-
32- // Map each noise value to a normalized weight (0 to 1)
33- // First, convert from -1,1 range to 0,1 range
34- const mountainWeight = ( mountain + 1 ) / 2 ;
35- const platauWeight = ( platau + 1 ) / 2 ;
36- const valleyWeight = ( valley + 1 ) / 2 ;
37- const hillWeight = ( hill + 1 ) / 2 ;
38- const plainWeight = ( plain + 1 ) / 2 ;
39-
40- // Calculate total weight to normalize
41- const totalWeight = mountainWeight + platauWeight + valleyWeight + hillWeight + plainWeight ;
42-
43- // Guard against division by zero
44- if ( totalWeight === 0 ) {
45- return hslaToRgba ( HSLA ( [ 0 , 0 , 50 , 1 ] ) ) ; // Default gray if all weights are zero
46- }
47-
48- // Initialize color components for weighted average
49- let h = 0 ;
50- let s = 0 ;
51- let l = 0 ;
52-
53- // Add weighted contribution from each land type
54- h += COLOR_MAP . mountain . color [ 0 ] * mountainWeight ;
55- h += COLOR_MAP . platau . color [ 0 ] * platauWeight ;
56- h += COLOR_MAP . valley . color [ 0 ] * valleyWeight ;
57- h += COLOR_MAP . hill . color [ 0 ] * hillWeight ;
58- h += COLOR_MAP . plain . color [ 0 ] * plainWeight ;
59-
60- s += COLOR_MAP . mountain . color [ 1 ] * mountainWeight ;
61- s += COLOR_MAP . platau . color [ 1 ] * platauWeight ;
62- s += COLOR_MAP . valley . color [ 1 ] * valleyWeight ;
63- s += COLOR_MAP . hill . color [ 1 ] * hillWeight ;
64- s += COLOR_MAP . plain . color [ 1 ] * plainWeight ;
65-
66- l += COLOR_MAP . mountain . color [ 2 ] * mountainWeight ;
67- l += COLOR_MAP . platau . color [ 2 ] * platauWeight ;
68- l += COLOR_MAP . valley . color [ 2 ] * valleyWeight ;
69- l += COLOR_MAP . hill . color [ 2 ] * hillWeight ;
70- l += COLOR_MAP . plain . color [ 2 ] * plainWeight ;
71-
72- // Normalize by dividing by total weight
73- h /= totalWeight ;
74- s /= totalWeight ;
75- l /= totalWeight ;
17+ const color = HSLA ( [ 0 , 0 , 0 , 1 ] ) ;
7618
77- // Create the final blended HSLA color
78- const blendedColor = HSLA ( [ h , s , l , 1 ] ) ;
19+ return hslaToRgba (
20+ mapNoiseToColor ( tile . biome . deep_ocean , {
21+ min : HSLA ( [ 220 , 100 , 30 , 1 ] ) ,
22+ max : HSLA ( [ 200 , 80 , 60 , 1 ] ) ,
23+ } ) ,
24+ ) ;
7925
80- // Convert to RGBA and return
81- return hslaToRgba ( blendedColor ) ;
26+ // return hslaToRgba(color);
8227} ;
0 commit comments