Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intensity to height converter with better artistic style #699

Merged
merged 7 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.marginallyclever</groupId>
<artifactId>Makelangelo</artifactId>
<version>7.41.0</version>
<version>7.41.3</version>
<name>Makelangelo</name>
<description>Makelangelo Software is a Java program that prepares art for CNC plotters. It is especially designed for the Makelangelo Robot.
It pairs really well with Marlin-polargraph, the code in the brain of the robot that receives instructions and moves the motors.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,36 @@
* @since 7.40.3
*/
public class Converter_IntensityToHeight extends ImageConverter {
// vertical distance between lines
private static int spacing = 2;
private static int maxHeight = 10;
// horizontal distance between samples. more samples = more detail.
private static int sampleRate = 5;
// max height of the wave will be +/-(waveIntensity/2)
private static int waveIntensity = 30;

public Converter_IntensityToHeight() {
super();

SelectSlider selectSize = new SelectSlider("size",Translator.get("Converter_IntensityToHeight.spacing"), 20,1,getSpacing());
SelectSlider selectMaxHeight = new SelectSlider("maxHeight",Translator.get("Converter_IntensityToHeight.maxHeight"),20,1,getMaxHeight());
SelectSlider selectSampleRate = new SelectSlider("sampleRate",Translator.get("Converter_IntensityToHeight.sampleRate"),20,1,getSampleRate());
SelectSlider selectWaveIntensity = new SelectSlider("waveIntensity",Translator.get("Converter_IntensityToHeight.waveIntensity"),50,-50,getWaveIntensity());

add(selectSize);
add(selectMaxHeight);
add(selectSampleRate);
add(selectWaveIntensity);

selectSize.addPropertyChangeListener(evt->{
setSpacing((int) evt.getNewValue());
fireRestart();
});
selectMaxHeight.addPropertyChangeListener(evt->{
setMaxHeight((int) evt.getNewValue());
fireRestart();
});
selectSampleRate.addPropertyChangeListener(evt->{
setSampleRate((int) evt.getNewValue());
fireRestart();
});
selectWaveIntensity.addPropertyChangeListener(evt->{
setWaveIntensity((int) evt.getNewValue());
fireRestart();
});
}

@Override
Expand All @@ -63,11 +66,11 @@ public void setSampleRate(int value) {
sampleRate = Math.max(1,value);
}

public int getMaxHeight() {
return maxHeight;
public int getWaveIntensity(){
return waveIntensity;
}
public void setMaxHeight(int value) {
maxHeight = Math.max(1,value);
public void setWaveIntensity(int value){
waveIntensity = value;
}

protected void convertLine(TransformedImage img, double sampleSpacing, double halfStep, Point2D a, Point2D b) {
Expand All @@ -83,11 +86,10 @@ protected void convertLine(TransformedImage img, double sampleSpacing, double ha
// read a block of the image and find the average intensity in this block
double z = img.sample( x - sampleSpacing, y - halfStep, x + sampleSpacing, y + halfStep);
// scale the intensity value
double scale_z = z / 255.0f;
scale_z = (scale_z-0.5)*2.0;
double scale_z = 1 - z / 255.0f;
//scale_z *= scale_z; // quadratic curve
double pulseSize = halfStep * scale_z;
double py=y + pulseSize;
double pulseSize = waveIntensity * scale_z;
double py=y + pulseSize - waveIntensity/2.0f;
if(first) {
turtle.jumpTo(x, py);
first = false;
Expand Down Expand Up @@ -128,7 +130,7 @@ public void start(Paper paper, TransformedImage image) {
a.set(xRight,y);
b.set(xLeft,y);
}
convertLine(img,sampleRate,maxHeight,a,b);
convertLine(img,sampleRate,sampleRate/2.0,a,b);
}

fireConversionFinished();
Expand Down
26 changes: 13 additions & 13 deletions src/main/resources/languages/english.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
<!DOCTYPE language>
<language>

<!--
<!--
To facilitate the validation and avoid duplicated or empty key (//language/string/key) ,
please try to get language_no_dup_key.xsd from https://github.com/MarginallyClever/Makelangelo-software/blob/b1f418fc63d70f24288d490dccadc97d97a775e9/src/test/resources/translator/language_no_dup_key.xsd
and change the begining of the file with :

<?xml version="1.0" encoding="UTF-8"?>
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="language_no_dup_key.xsd" >

-->
<meta>
<name>English</name>
<author>Dan Royer ([email protected])</author>
</meta>
<string><key>BorderName</key><value>Outline paper</value></string>
<meta>
<name>English</name>
<author>Dan Royer ([email protected])</author>
</meta>

<string><key>BorderName</key><value>Outline paper</value></string>
<string><key>Generator_TruchetTiles.Name</key><value>Truchet Tiles</value></string>
<string><key>Generator_TruchetTiles.LineSpacing</key><value>Space between lines (mm)</value></string>
<string><key>Generator_TruchetTiles.LinesPerTile</key><value>Lines per tile</value></string>
Expand Down Expand Up @@ -261,9 +261,9 @@

<string><key>TurtleGenerators.LearnMore.Link.Text</key><value>Learn more</value></string>
<string><key>LoadScratch3.foreverNotAllowed</key><value>Forever loops are forever forbidden.</value></string>
<string><key>SaveGCode.splitGCodeTitle</key><value>Many colors detected</value></string>
<string><key>SaveGCode.splitGCodeTitle</key><value>Many colors detected</value></string>

<string><key>Converter_CMYK_Circles.name</key><value>CMYK circles</value></string>
<string><key>Converter_CMYK_Circles.name</key><value>CMYK circles</value></string>
<string><key>Converter_CMYK_Circles.maxCircleSize</key><value>max circle size</value></string>

<string><key>Converter_EdgeDetection.name</key><value>Edge detection</value></string>
Expand Down Expand Up @@ -387,6 +387,6 @@

<string><key>Converter_IntensityToHeight.name</key><value>Intensity to height</value></string>
<string><key>Converter_IntensityToHeight.spacing</key><value>Wave spacing</value></string>
<string><key>Converter_IntensityToHeight.maxHeight</key><value>Wave height</value></string>
<string><key>Converter_IntensityToHeight.sampleRate</key><value>Sample rate</value></string>
</language>
<string><key>Converter_IntensityToHeight.waveIntensity</key><value>Wave intensity</value></string>
</language>
Loading