Guest User

Untitled

a guest
Sep 10th, 2018
109
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void) setUpColorParametersWithSourceInfo:(NSDictionary *)sourceInfo targetInfo:(NSMutableDictionary *)targetInfo isAtmosphere:(BOOL)isAtmosphere
  2. {
  3. // Stir the PRNG fourteen times for backwards compatibility.
  4. unsigned i;
  5. for (i = 0; i < 14; i++)
  6. {
  7. gen_rnd_number();
  8. }
  9.  
  10. Vector landHSB, seaHSB, landPolarHSB, seaPolarHSB;
  11. OOColor *color;
  12.  
  13. landHSB = RandomHSBColor();
  14.  
  15. if (!isAtmosphere)
  16. {
  17. do
  18. {
  19. seaHSB = RandomHSBColor();
  20. }
  21. while (dot_product(landHSB, seaHSB) > .80f); // make sure land and sea colors differ significantly
  22.  
  23. // saturation bias - avoids really grey oceans
  24. if (seaHSB.y < 0.22f) seaHSB.y = seaHSB.y * 0.3f + 0.2f;
  25. // brightness bias - avoids really bright landmasses
  26. if (landHSB.z > 0.66f) landHSB.z = 0.66f;
  27.  
  28. // planetinfo.plist overrides
  29. color = [OOColor colorWithDescription:[sourceInfo objectForKey:@"land_color"]];
  30. if (color != nil) landHSB = HSBColorWithColor(color);
  31. else ScanVectorFromString([sourceInfo oo_stringForKey:@"land_hsb_color"], &landHSB);
  32.  
  33. color = [OOColor colorWithDescription:[sourceInfo objectForKey:@"sea_color"]];
  34. if (color != nil) seaHSB = HSBColorWithColor(color);
  35. else ScanVectorFromString([sourceInfo oo_stringForKey:@"sea_hsb_color"], &seaHSB);
  36.  
  37. // polar areas are brighter but have less colour (closer to white)
  38. color = [OOColor colorWithDescription:[sourceInfo objectForKey:@"polar_land_color"]];
  39. if (color != nil)
  40. {
  41. landPolarHSB = HSBColorWithColor(color);
  42. }
  43. else
  44. {
  45. landPolarHSB = LighterHSBColor(landHSB);
  46. }
  47.  
  48. color = [OOColor colorWithDescription:[sourceInfo objectForKey:@"polar_sea_color"]];
  49. if (color != nil)
  50. {
  51. seaPolarHSB = HSBColorWithColor(color);
  52. }
  53. else
  54. {
  55. seaPolarHSB = LighterHSBColor(seaHSB);
  56. }
  57.  
  58. [targetInfo setObject:ColorWithHSBColor(landHSB) forKey:@"land_color"];
  59. [targetInfo setObject:ColorWithHSBColor(seaHSB) forKey:@"sea_color"];
  60. [targetInfo setObject:ColorWithHSBColor(landPolarHSB) forKey:@"polar_land_color"];
  61. [targetInfo setObject:ColorWithHSBColor(seaPolarHSB) forKey:@"polar_sea_color"];
  62. }
  63. else
  64. {
  65. landHSB = RandomHSBColor(); // NB: randomcolor is called twice to make the cloud colour similar to the old one.
  66.  
  67. // add a cloud_color tinge to sky blue({0.66, 0.3, 1}).
  68. seaHSB = vector_add(landHSB,((Vector){1.333, 0.6, 2})); // 1 part cloud, 2 parts sky blue
  69. scale_vector(&seaHSB, 0.333);
  70.  
  71. float cloudAlpha = OOClamp_0_1_f([sourceInfo oo_floatForKey:@"cloud_alpha" defaultValue:1.0f]);
  72. [targetInfo setObject:[NSNumber numberWithFloat:cloudAlpha] forKey:@"cloud_alpha"];
  73.  
  74. // planetinfo overrides
  75. color = [OOColor colorWithDescription:[sourceInfo objectForKey:@"atmosphere_color"]];
  76. if (color != nil) seaHSB = HSBColorWithColor(color);
  77. color = [OOColor colorWithDescription:[sourceInfo objectForKey:@"cloud_color"]];
  78. if (color != nil) landHSB = HSBColorWithColor(color);
  79.  
  80. // polar areas: brighter, less saturation
  81. landPolarHSB = vector_add(landHSB,LighterHSBColor(landHSB));
  82. scale_vector(&landPolarHSB, 0.5);
  83.  
  84. color = [OOColor colorWithDescription:[sourceInfo objectForKey:@"polar_cloud_color"]];
  85. if (color != nil) landPolarHSB = HSBColorWithColor(color);
  86.  
  87. [targetInfo setObject:ColorWithHSBColor(seaHSB) forKey:@"air_color"];
  88. [targetInfo setObject:ColorWithHSBColor(landHSB) forKey:@"cloud_color"];
  89. [targetInfo setObject:ColorWithHSBColor(landPolarHSB) forKey:@"polar_cloud_color"];
  90. }
  91. }
RAW Paste Data