Added the posterization feature into the density preview

This commit is contained in:
Sandy Noble 2016-01-17 22:37:24 +00:00
parent 74636289e5
commit dba8bb5b2a
6 changed files with 51 additions and 18 deletions

View File

@ -535,7 +535,7 @@ class DisplayMachine extends Machine
p = scaleToScreen(p); p = scaleToScreen(p);
stroke(strokeColour); stroke(strokeColour);
vertex(p.x, p.y); vertex(p.x, p.y);
//ellipse(p.x, p.y, 3, 3); // ellipse(p.x, p.y, 3, 3);
} }
else else
{ {
@ -719,7 +719,12 @@ class DisplayMachine extends Machine
// scale em, danno. // scale em, danno.
PVector scaledPos = scaleToScreen(cartesianPos); PVector scaledPos = scaleToScreen(cartesianPos);
noStroke(); noStroke();
fill(cartesianPos.z);
// Posterize the density value
int reduced = int(map(cartesianPos.z, 1, 255, 1, densityPreviewPosterize)+0.5);
int brightness = int(map(reduced, 1, densityPreviewPosterize, 1, 255));
fill(brightness);
switch (getDensityPreviewStyle()) switch (getDensityPreviewStyle())
{ {
case DENSITY_PREVIEW_ROUND: case DENSITY_PREVIEW_ROUND:
@ -727,20 +732,20 @@ class DisplayMachine extends Machine
break; break;
case DENSITY_PREVIEW_ROUND_SIZE: case DENSITY_PREVIEW_ROUND_SIZE:
fill(0); fill(0);
previewRoundPixel(scaledPos, map(cartesianPos.z, 1, 255, pixelSize, 1)); previewRoundPixel(scaledPos, map(brightness, 1, densityPreviewPosterize, pixelSize, 1));
break; break;
case DENSITY_PREVIEW_DIAMOND: case DENSITY_PREVIEW_DIAMOND:
previewDiamondPixel(scaledPos, pixelSize, pixelSize, cartesianPos.z); previewDiamondPixel(scaledPos, pixelSize, pixelSize, brightness);
break; break;
case DENSITY_PREVIEW_NATIVE: case DENSITY_PREVIEW_NATIVE:
previewNativePixel(scaledPos, pixelSize, cartesianPos.z); previewNativePixel(scaledPos, pixelSize, brightness);
break; break;
case DENSITY_PREVIEW_NATIVE_SIZE: case DENSITY_PREVIEW_NATIVE_SIZE:
previewNativePixel(scaledPos, map(cartesianPos.z, 1, 255, pixelSize, 1), 50); previewNativePixel(scaledPos, map(brightness, 1, densityPreviewPosterize, pixelSize, 1), 50);
break; break;
case DENSITY_PREVIEW_NATIVE_ARC: case DENSITY_PREVIEW_NATIVE_ARC:
previewRoundPixel(scaledPos, pixelSize*0.8); previewRoundPixel(scaledPos, pixelSize*0.8);
previewNativeArcPixel(scaledPos, pixelSize, cartesianPos.z); previewNativeArcPixel(scaledPos, pixelSize, brightness);
break; break;
default: default:
previewRoundPixel(scaledPos, pixelSize); previewRoundPixel(scaledPos, pixelSize);

View File

@ -21,7 +21,7 @@ ControlFrameSimple addDrawPixelsControlFrame(String theName, int theWidth, int t
p.dispose(); p.dispose();
f.dispose(); f.dispose();
} }
} }
); );
f.setResizable( true ); f.setResizable( true );
f.setVisible( true ); f.setVisible( true );

View File

@ -738,4 +738,11 @@ void button_mode_cycleDensityPreviewStyle()
} }
} }
void numberbox_mode_changeDensityPreviewPosterize(int value) {
if (value < 1) value = 1;
else if (value > 255) value = 255;
densityPreviewPosterize = value;
}

View File

@ -521,6 +521,14 @@ Map<String, Controller> initialiseNumberboxValues(Map<String, Controller> map)
{ {
n.setValue(densityPreviewStyle); n.setValue(densityPreviewStyle);
} }
else if (MODE_CHANGE_DENSITY_PREVIEW_POSTERIZE.equals(key))
{
n.setValue(densityPreviewPosterize);
n.setMin(1);
n.setMax(255);
n.setDecimalPrecision(1);
n.setMultiplier(0.1);
}
} }
} }
return map; return map;
@ -694,6 +702,7 @@ List<String> getControlNamesForInputPanel()
controlNames.add(MODE_CHANGE_SAMPLE_AREA); controlNames.add(MODE_CHANGE_SAMPLE_AREA);
controlNames.add(MODE_CHOOSE_CHROMA_KEY_COLOUR); controlNames.add(MODE_CHOOSE_CHROMA_KEY_COLOUR);
controlNames.add(MODE_CHANGE_PIXEL_SCALING); controlNames.add(MODE_CHANGE_PIXEL_SCALING);
controlNames.add(MODE_CHANGE_DENSITY_PREVIEW_POSTERIZE);
controlNames.add(MODE_CYCLE_DENSITY_PREVIEW_STYLE); controlNames.add(MODE_CYCLE_DENSITY_PREVIEW_STYLE);
controlNames.add(MODE_RENDER_PIXEL_DIALOG); controlNames.add(MODE_RENDER_PIXEL_DIALOG);
@ -984,6 +993,8 @@ Map<String, String> buildControlLabels()
result.put(MODE_ADJUST_PREVIEW_CORD_OFFSET, "Cord offset"); result.put(MODE_ADJUST_PREVIEW_CORD_OFFSET, "Cord offset");
result.put(MODE_CYCLE_DENSITY_PREVIEW_STYLE, "Cycle preview style"); result.put(MODE_CYCLE_DENSITY_PREVIEW_STYLE, "Cycle preview style");
result.put(MODE_CHANGE_DENSITY_PREVIEW_POSTERIZE, "Pixel posterize");
@ -1132,6 +1143,8 @@ Set<String> buildControlNames()
result.add(MODE_ADJUST_PREVIEW_CORD_OFFSET); result.add(MODE_ADJUST_PREVIEW_CORD_OFFSET);
result.add(MODE_CYCLE_DENSITY_PREVIEW_STYLE); result.add(MODE_CYCLE_DENSITY_PREVIEW_STYLE);
result.add(MODE_CHANGE_DENSITY_PREVIEW_POSTERIZE);
return result; return result;
} }

View File

@ -199,13 +199,13 @@ void sendTestPenWidth()
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(testPenWidthCommand) sb.append(testPenWidthCommand)
.append(int(gridSize)) .append(int(gridSize))
.append(",") .append(",")
.append(df.format(testPenWidthStartSize)) .append(df.format(testPenWidthStartSize))
.append(",") .append(",")
.append(df.format(testPenWidthEndSize)) .append(df.format(testPenWidthEndSize))
.append(",") .append(",")
.append(df.format(testPenWidthIncrementSize)) .append(df.format(testPenWidthIncrementSize))
.append(",END"); .append(",END");
addToCommandQueue(sb.toString()); addToCommandQueue(sb.toString());
} }

View File

@ -57,7 +57,7 @@ import java.awt.BorderLayout;
import java.lang.reflect.Method; import java.lang.reflect.Method;
int majorVersionNo = 2; int majorVersionNo = 2;
int minorVersionNo = 1; int minorVersionNo = 2;
int buildNo = 1; int buildNo = 1;
String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo; String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo;
@ -342,6 +342,8 @@ static final String MODE_ADJUST_PREVIEW_CORD_OFFSET = "numberbox_mode_previewCor
static final String MODE_CYCLE_DENSITY_PREVIEW_STYLE = "button_mode_cycleDensityPreviewStyle"; static final String MODE_CYCLE_DENSITY_PREVIEW_STYLE = "button_mode_cycleDensityPreviewStyle";
static final String MODE_CHANGE_DENSITY_PREVIEW_POSTERIZE = "numberbox_mode_changeDensityPreviewPosterize";
PVector statusTextPosition = new PVector(300.0, 12.0); PVector statusTextPosition = new PVector(300.0, 12.0);
@ -387,6 +389,7 @@ static final int DENSITY_PREVIEW_NATIVE_SIZE = 5;
static final int DEFAULT_DENSITY_PREVIEW_STYLE = DENSITY_PREVIEW_NATIVE; static final int DEFAULT_DENSITY_PREVIEW_STYLE = DENSITY_PREVIEW_NATIVE;
int densityPreviewStyle = DEFAULT_DENSITY_PREVIEW_STYLE; int densityPreviewStyle = DEFAULT_DENSITY_PREVIEW_STYLE;
int densityPreviewPosterize = 255;
static final byte COORD_MODE_NATIVE_STEPS = 0; static final byte COORD_MODE_NATIVE_STEPS = 0;
static final byte COORD_MODE_NATIVE_MM = 1; static final byte COORD_MODE_NATIVE_MM = 1;
@ -537,7 +540,8 @@ void setup()
parentPapplet = this; parentPapplet = this;
RG.init(this); RG.init(this);
RG.setPolygonizer(RG.ADAPTATIVE); RG.setPolygonizer(RG.UNIFORMLENGTH);
// RG.setPolygonizer(RG.ADAPTATIVE);
try try
{ {
@ -600,6 +604,7 @@ void setup()
addEventListeners(); addEventListeners();
frameRate(8); frameRate(8);
noLoop();
} }
void fitDisplayMachineToWindow() { void fitDisplayMachineToWindow() {
@ -679,6 +684,7 @@ void windowResized()
} }
void draw() void draw()
{ {
if (getCurrentTab() == TAB_NAME_INPUT) { if (getCurrentTab() == TAB_NAME_INPUT) {
drawImagePage(); drawImagePage();
} }
@ -1949,6 +1955,8 @@ void previewQueue(boolean forceRebuild)
{ {
println("regenerating preview queue."); println("regenerating preview queue.");
previewCommandList.clear(); previewCommandList.clear();
for (String command : commandQueue) for (String command : commandQueue)
{ {
if (command.startsWith(CMD_CHANGELENGTHDIRECT) || command.startsWith(CMD_CHANGELENGTH) || command.startsWith(CMD_DRAWPIXEL)) if (command.startsWith(CMD_CHANGELENGTHDIRECT) || command.startsWith(CMD_CHANGELENGTH) || command.startsWith(CMD_DRAWPIXEL))
@ -1962,8 +1970,8 @@ void previewQueue(boolean forceRebuild)
String bLenStr = splitted[2]; String bLenStr = splitted[2];
PVector endPoint = new PVector(Integer.parseInt(aLenStr)+previewCordOffset, Integer.parseInt(bLenStr)+previewCordOffset); PVector endPoint = new PVector(Integer.parseInt(aLenStr)+previewCordOffset, Integer.parseInt(bLenStr)+previewCordOffset);
endPoint = getDisplayMachine().asCartesianCoords(endPoint);
endPoint = getDisplayMachine().inMM(endPoint); endPoint = getDisplayMachine().inMM(endPoint);
endPoint = getDisplayMachine().asCartesianCoords(endPoint);
pv.x = endPoint.x; pv.x = endPoint.x;
pv.y = endPoint.y; pv.y = endPoint.y;