Skip to content

Commit

Permalink
Add map colour palette selector to map view menu
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielsherry committed Jun 10, 2024
1 parent 4ee53a4 commit 6101a5e
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ public Stop(int argb, float position) {
};

private List<Stop> stops;
private String name;

public Gradient(List<Stop> stops) {
public Gradient(String name, List<Stop> stops) {
this.stops = stops;
this.name = name;
}

public Gradient(Stop... stops) {
public Gradient(String name, Stop... stops) {
this.stops = List.of(stops);
this.name = name;
}

public List<PaletteColour> toList(int steps) {
Expand Down Expand Up @@ -118,6 +121,10 @@ public static List<PaletteColour> extrapolateStops(float totalSteps, List<Stop>
return spectrum;

}

public String getName() {
return name;
}


}
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
package org.peakaboo.framework.cyclops.visualization.palette;

import java.util.List;
import java.util.Optional;

import org.peakaboo.framework.cyclops.visualization.palette.Gradient.Stop;

public class Gradients {

private Gradients() {};


public static final Gradient MONOCHROME = new Gradient(
public static final Gradient MONOCHROME = new Gradient("Monochrome",
new Stop(0xff000000, 0f),
new Stop(0xffffffff, 1f)
);

public static final Gradient INV_MONOCHROME = new Gradient(
public static final Gradient INV_MONOCHROME = new Gradient("Inverted Monochrome",
new Stop(0xffffffff, 0f),
new Stop(0xff000000, 1f)
);


public static final Gradient THERMAL = new Gradient(
public static final Gradient SPECTRUM = new Gradient("Spectrum",
new Stop(0xff10154D, 0f),
new Stop(0xff0D47A1, 0.235f),
new Stop(0xff388E3C, 0.392f),
Expand All @@ -28,7 +31,62 @@ public class Gradients {
);


public static final Gradient GEORGIA = new Gradient(
public static final Gradient NAVIA = new Gradient("Navia",
new Stop(0xff0b1627, 0f),
new Stop(0xff1a2b3f, 0.11f),
new Stop(0xff19598c, 0.22f),
new Stop(0xff29728e, 0.33f),
new Stop(0xff3a8285, 0.44f),
new Stop(0xff4b9379, 0.55f),
new Stop(0xff66aa6a, 0.66f),
new Stop(0xff98ca6e, 0.77f),
new Stop(0xffd9e5a6, 0.88f),
new Stop(0xfffcf5d9, 1f)
);


public static final Gradient LAJOLLA = new Gradient("Lajolla",
new Stop(0xff1f1e0f, 0f),
new Stop(0xff332312, 0.11f),
new Stop(0xff5b2f22, 0.22f),
new Stop(0xff91403c, 0.33f),
new Stop(0xffc94e4a, 0.44f),
new Stop(0xffe1714d, 0.55f),
new Stop(0xffe9924f, 0.66f),
new Stop(0xffefb553, 0.77f),
new Stop(0xfff8de7a, 0.88f),
new Stop(0xfffcf9cb, 1f)
);

public static final Gradient OSLO = new Gradient("Oslo",
new Stop(0xff080706, 0f),
new Stop(0xff101928, 0.11f),
new Stop(0xff143250, 0.22f),
new Stop(0xff1f4c7b, 0.33f),
new Stop(0xff3968a7, 0.44f),
new Stop(0xff688ac4, 0.55f),
new Stop(0xff8a9fc8, 0.66f),
new Stop(0xffabb6c9, 0.77f),
new Stop(0xffd4d6da, 0.88f),
new Stop(0xfffefefe, 1f)
);

public static final Gradient IRON = new Gradient("Iron",
new Stop(0xff020f15, 0f),
new Stop(0xff26036c, 0.1f),
new Stop(0xff66059f, 0.2f),
new Stop(0xffa60b9c, 0.3f),
new Stop(0xffcd2972, 0.4f),
new Stop(0xffee4e3d, 0.5f),
new Stop(0xfffa7c0f, 0.6f),
new Stop(0xfff6aa00, 0.7f),
new Stop(0xfffdcc06, 0.8f),
new Stop(0xfffeee5c, 0.9f),
new Stop(0xfff0fff0, 1f)
);


public static final Gradient GEORGIA = new Gradient("Georgia",
new Stop(0xffFFFFFF, 0f),
new Stop(0xffE6B350, 0.2f),
new Stop(0xffF27C55, 0.4f),
Expand All @@ -38,98 +96,30 @@ public class Gradients {
);


public static final Gradient RATIO_THERMAL = new Gradient(
public static final Gradient RATIO_THERMAL = new Gradient("Ratio Thermal",
new Stop(0xff1485CC, 0f),
new Stop(0xff000000, 0.5f),
new Stop(0xffff0000, 1f)
);


public static final Gradient RATIO_MONOCHROME = new Gradient(
public static final Gradient RATIO_MONOCHROME = new Gradient("Ratio Monochrome",
new Stop(0xff000000, 0f),
new Stop(0xffffffff, 1f)
);


// nice
public static final Gradient THOUGHTFUL = new Gradient(
new Stop(0xffecd078, 0f),
new Stop(0xffd95b43, 0.333f),
new Stop(0xffc02942, 0.666f),
new Stop(0xff542437, 1f)
);


// nice
public static final Gradient TERRA = new Gradient(
new Stop(0xff031634, 0f),
new Stop(0xff033649, 0.25f),
new Stop(0xff036564, 0.50f),
new Stop(0xffcdb380, 0.75f),
new Stop(0xffe8ddcb, 1f)
);


//good on unsubtracted, okay on subtracted
public static final Gradient OLIVE = new Gradient(
new Stop(0xff300018, 0f),
new Stop(0xff5a3d31, 0.25f),
new Stop(0xff837b47, 0.50f),
new Stop(0xffadb85f, 0.57f),
new Stop(0xffe5edb8, 1f)
);


public static final Gradient VINTAGE = new Gradient(
new Stop(0xff8c2318, 0f),
new Stop(0xff5e8c6a, 0.25f),
new Stop(0xff88a65e, 0.50f),
new Stop(0xffbfb35a, 0.75f),
new Stop(0xfff2c45a, 1f)
);


public static final Gradient GOLDFISH = new Gradient(
new Stop(0xff69d2e7, 0f),
new Stop(0xffa7dbd8, 0.304f),
new Stop(0xffe0e4cc, 0.548f),
new Stop(0xffd9d6b8, 0.639f),
new Stop(0xfff39449, 0.700f),
new Stop(0xfffa6900, 0.882f),
new Stop(0xffff4000, 1f)
);


// based off of "sugar is three"
public static final Gradient SUGAR = new Gradient(
new Stop(0xff2c8b9a, 0f),
new Stop(0xff6ac3ae, 0.25f),
new Stop(0xffd9c8a7, 0.44f),
new Stop(0xfff9cdad, 0.63f),
new Stop(0xfffc9d9a, 0.82f),
new Stop(0xfffe4365, 0.94f),
new Stop(0xfffe264d, 1f)
);




public static final Gradient BROWNSUGAR = new Gradient(
new Stop(0xff490a3d, 0f),
new Stop(0xffbd1550, 0.25f),
new Stop(0xffe97f02, 0.50f),
new Stop(0xfff8ca00, 0.74f),
new Stop(0xff8a9b0f, 1f)
);


public static final Gradient BLACKBODY = new Gradient(
new Stop(0xfff82600, 0f),
new Stop(0xffffb12f, 0.25f),
new Stop(0xffffe7bf, 0.50f),
new Stop(0xffdfe6ff, 0.75f),
new Stop(0xffa6baff, 1f)
);
public static final Gradient DEFAULT = SPECTRUM;

public static Optional<Gradient> forName(String colourPalette) {
var gs = List.of(MONOCHROME, INV_MONOCHROME, SPECTRUM, NAVIA, LAJOLLA, OSLO, IRON, GEORGIA);
for (var g : gs) {
if (g.getName().equalsIgnoreCase(colourPalette)) {
return Optional.of(g);
}
}
return Optional.empty();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public MapRenderSettings getRenderSettings() {
settings.mapTitle = this.getFitting().mapLongTitle();

settings.scalemode = this.getFitting().getMapScaleMode();
settings.monochrome = this.getSettings().getMonochrome();
settings.gradient = this.getSettings().getColourGradient();
settings.darkmode = this.getParentPlotController().view().getDarkMode();
settings.contours = this.getSettings().getContours();
settings.contourSteps = this.getSettings().getSpectrumSteps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.peakaboo.controller.mapper.MappingController;
import org.peakaboo.framework.cyclops.Bounds;
import org.peakaboo.framework.cyclops.Coord;
import org.peakaboo.framework.cyclops.visualization.palette.Gradient;
import org.peakaboo.framework.cyclops.visualization.palette.Gradients;
import org.peakaboo.framework.eventful.EventfulType;

/**
Expand All @@ -30,7 +32,7 @@ public class MapSettingsController extends EventfulType<MapUpdateType>

private int spectrumSteps = 15;
private boolean contour = false;
private boolean monochrome = false;
private Gradient colourGradient = Gradients.DEFAULT;

private float zoom = 1f;

Expand Down Expand Up @@ -93,20 +95,19 @@ public int getSpectrumSteps()
return this.spectrumSteps;
}


public void setMonochrome(boolean mono)
public void setColourGradient(Gradient gradient)
{
this.monochrome = mono;
this.colourGradient = gradient;
updateListeners(MapUpdateType.UI_OPTIONS);
}


public boolean getMonochrome()
public Gradient getColourGradient()
{
return this.monochrome;
return this.colourGradient;
}



public void setShowSpectrum(boolean show)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.peakaboo.controller.mapper.settings;

import org.peakaboo.framework.cyclops.visualization.palette.Gradients;

public class SavedMapSettingsController {

public boolean drawCoordinates = true;
Expand All @@ -10,7 +12,7 @@ public class SavedMapSettingsController {

public int spectrumSteps = 15;
public boolean contour = false;
public boolean monochrome = false;
public String colourPalette = "";

public void loadInto(MapSettingsController controller) {
controller.setShowCoords(drawCoordinates);
Expand All @@ -20,7 +22,8 @@ public void loadInto(MapSettingsController controller) {
controller.setShowDatasetTitle(drawDataSetTitle);
controller.setSpectrumSteps(spectrumSteps);
controller.setContours(contour);
controller.setMonochrome(monochrome);
controller.setColourGradient(Gradients.forName(colourPalette).orElse(Gradients.DEFAULT));

}

public SavedMapSettingsController storeFrom(MapSettingsController controller) {
Expand All @@ -32,7 +35,7 @@ public SavedMapSettingsController storeFrom(MapSettingsController controller) {
drawDataSetTitle = controller.getShowDatasetTitle();
spectrumSteps = controller.getSpectrumSteps();
contour = controller.getContours();
monochrome = controller.getMonochrome();
colourPalette = controller.getColourGradient().getName();

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.peakaboo.display.map.modes.MapModeRegistry;
import org.peakaboo.framework.cyclops.Coord;
import org.peakaboo.framework.cyclops.SISize;
import org.peakaboo.framework.cyclops.visualization.palette.Gradient;
import org.peakaboo.framework.cyclops.visualization.palette.Gradients;
import org.peakaboo.framework.cyclops.visualization.palette.PaletteColour;

import it.unimi.dsi.fastutil.ints.IntArrayList;
Expand All @@ -22,7 +24,7 @@ public class MapRenderSettings {
public String mapTitle = "";

public MapScaleMode scalemode = MapScaleMode.ABSOLUTE;
public boolean monochrome = false;
public Gradient gradient = Gradients.DEFAULT;
public boolean darkmode = false;
public boolean contours = false;
public int contourSteps = 15;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void draw(Coord<Integer> size, MapRenderData data, MapRenderSettings sett
backend.setSource(settings.getBg());
backend.fill();

Palette palette = new ColourStopPalette(settings.monochrome ? Gradients.MONOCHROME : Gradients.THERMAL);
Palette palette = new ColourStopPalette(settings.gradient);
List<Palette> paletteList = new ArrayList<>();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void draw(Coord<Integer> size, MapRenderData data, MapRenderSettings sett
map.setDrawingRequest(dr);

List<Palette> paletteList = new ArrayList<>();
paletteList.add(new ColourStopPalette(settings.monochrome ? Gradients.INV_MONOCHROME : Gradients.GEORGIA));
paletteList.add(new ColourStopPalette(settings.gradient));

List<AxisPainter> axisPainters = new ArrayList<>();
super.setupTitleAxisPainters(settings, axisPainters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void draw(Coord<Integer> size, MapRenderData data, MapRenderSettings sett

//if this is a valid ratio, make a real colour palette -- otherwise, just a black palette
if (validRatio) {
paletteList.add(new RatioPalette(settings.monochrome ? Gradients.RATIO_MONOCHROME : Gradients.RATIO_THERMAL));
paletteList.add(new RatioPalette(settings.gradient));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public enum PeakabooIcons implements IconSet {

MENU_VIEW,
MENU_ENERGY,
MENU_SETTINGS
MENU_SETTINGS,
MENU_PALETTE,

;

Expand Down
Loading

0 comments on commit 6101a5e

Please sign in to comment.