Skip to content

Commit

Permalink
Added Export window, tweaks and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tiggerbiggo committed Oct 31, 2018
1 parent 0b0c8f6 commit 9754bdb
Show file tree
Hide file tree
Showing 17 changed files with 880 additions and 205 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ imgs/
*.prim
*.jar
*.bat
*.zip
*.zip
log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public static byte[] writeByteArray(BufferedImage[] imgSequence) {
return writeByteArray(imgSequence, BufferedImage.TYPE_INT_RGB, 0, true);
}

public static void writeImage(BufferedImage img, File out) throws IOException {
ImageIO.write(img, out.getName().substring(out.getName().lastIndexOf('.')+1), out);
}

/**
* Reads in all images from a directory in an arbitrary order.
*
Expand Down Expand Up @@ -266,7 +270,8 @@ public static File fromRelative(String rel){
new ExtensionFilter("PNG file", "*.png"),
new ExtensionFilter("JPEG file", "*.jpeg, *.jpg"),
new ExtensionFilter("TIFF file", "*.tiff, *.tif"),
new ExtensionFilter("BMP file", "*.bmp")
new ExtensionFilter("BMP file", "*.bmp"),
new ExtensionFilter("All files", "*.*")
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,16 @@ public static int getMin(Color in) {
return Math.min(in.getRed(), Math.min(in.getGreen(), in.getBlue()));
}

/**
* Given a Color, multiplies all components by the multiplier. Clamps result between 0 and 255.
* @param in The color to multiply
* @param toMul The number to multiply each component by
* @return The result color, or null if in was null
*/
public static Color multiply(Color in, double toMul){
public static Color multiply(Color A, Color B){
double r, g, b;
r = (B.getRed() / 255d);
g = (B.getGreen() / 255d);
b = (B.getBlue() / 255d);

return new Color(
Math.min(255, Math.max((int)(in.getRed() * toMul), 0)),
Math.min(255, Math.max((int)(in.getGreen() * toMul), 0)),
Math.min(255, Math.max((int)(in.getBlue() * toMul), 0))
Math.min(255, Math.max((int)(A.getRed() * r), 0)),
Math.min(255, Math.max((int)(A.getGreen() * g), 0)),
Math.min(255, Math.max((int)(A.getBlue() * b), 0))
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//Unfinished class, do not use.

package com.tiggerbiggo.prima.primaplay.node.implemented.io;

import com.tiggerbiggo.prima.primaplay.graphics.ColorTools;
import com.tiggerbiggo.prima.primaplay.node.core.NodeInOut;
import java.awt.Color;
import java.util.function.BiFunction;
import java.util.function.Function;

public class ColorEditNode{//} extends NodeInOut {


//@Override
public String getName() {
return null;
}

//@Override
public String getDescription() {
return null;
}
}

/*enum ColorAction{
ADD("Add", new BiFunction<Color, Color, Color>() {
@Override
public Color apply(Color color, Color color2) {
return ColorTools.;
}
}),
SUB,
MUL,
DIV;
String name;
BiFunction<Color, Color, Color> func;
ColorAction(String _name, BiFunction<Color, Color, Color> _func){
func = _func;
name = _name;
}
public Color transform(Color A, Color B){
return func.apply(A, B);
}
@Override
public String toString() {
return name;
}
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Color[] get(RenderParams p) {
}

for(int i=0; i<toReturn.length; i++){
toReturn[i] = ColorTools.multiply(toReturn[i], multiplier);
//toReturn[i] = ColorTools.multiply(toReturn[i], multiplier); TODO: BORKED
}
return toReturn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import com.tiggerbiggo.prima.primaplay.graphics.ColorConvertType;
import com.tiggerbiggo.prima.primaplay.graphics.SafeImage;
import com.tiggerbiggo.prima.primaplay.node.core.NodeInOut;
import com.tiggerbiggo.prima.primaplay.node.link.type.ColorOutputLink;
import com.tiggerbiggo.prima.primaplay.node.link.type.ImageInputLink;
import com.tiggerbiggo.prima.primaplay.node.link.type.VectorInputLink;
import com.tiggerbiggo.prima.primaplay.node.link.type.VectorOutputLink;
import com.tiggerbiggo.prima.primaplay.node.link.type.defaults.MapGenDefaultLink;
import com.tiggerbiggo.utils.calculation.Vector2;
import java.awt.Color;

Expand All @@ -21,28 +23,36 @@ public class ImageConvertNode extends NodeInOut{
private VectorInputLink pos;
private ImageInputLink img;

private VectorOutputLink out;
private VectorOutputLink vecOut;
private ColorOutputLink colOut;

public ImageConvertNode(){
pos = new VectorInputLink();
pos = new MapGenDefaultLink();
img = new ImageInputLink();
addInput(pos, img);

out = new VectorOutputLink() {
vecOut = new VectorOutputLink() {
@Override
public Vector2 get(RenderParams p) {
SafeImage currentImage = img.get(p);

Vector2 position = pos.get(p);

Color sample = currentImage.getColor(currentImage.denormVector(position));
Color sample = colOut.get(p);

return new Vector2(
convertX.convertColor(sample),
convertY.convertColor(sample));
}
};
addOutput(out);

colOut = new ColorOutputLink() {
@Override
public Color get(RenderParams p) {
SafeImage currentImage = img.get(p);

Vector2 position = pos.get(p);

return currentImage.getColor(currentImage.denormVector(position));
}
};
addOutput(vecOut, colOut);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.tiggerbiggo.prima.primaplay.node.implemented.io;

import ch.hephaistos.utilities.loki.util.annotations.TransferGrid;
import com.tiggerbiggo.prima.primaplay.core.RenderParams;
import com.tiggerbiggo.prima.primaplay.node.core.NodeInOut;
import com.tiggerbiggo.prima.primaplay.node.link.type.VectorInputLink;
import com.tiggerbiggo.prima.primaplay.node.link.type.VectorOutputLink;
import com.tiggerbiggo.prima.primaplay.node.link.type.defaults.MapGenDefaultLink;
import com.tiggerbiggo.utils.calculation.SimplexNoise;
import com.tiggerbiggo.utils.calculation.Vector2;

public class NoiseNode extends NodeInOut{

@TransferGrid
double z;

@TransferGrid
NoiseType type;

VectorInputLink mapIn;
VectorOutputLink out;

public NoiseNode() {
z = 0;
type = NoiseType.SIMPLEX;

mapIn = new MapGenDefaultLink();
addInput(mapIn);

out = new VectorOutputLink() {
@Override
public Vector2 get(RenderParams p) {
switch(type){
case WHITE:
return new Vector2(Math.random(), Math.random());
case SIMPLEX:
double n = SimplexNoise.noise(mapIn.get(p), z);
return new Vector2(n);
}
return Vector2.ZERO;
}
};
addOutput(out);
}

@Override
public String getName() {
return "Noise Node";
}

@Override
public String getDescription() {
return "Generates different kinds of random noise";
}
}
enum NoiseType{
WHITE,
SIMPLEX
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public Node getFXNode(ChangeListener listener) {
if(picker == null) {
c = new Color(r, g, b);
picker = new ColorPicker(ColorTools.toFXColor(c));
picker.getStyleClass().add("no-border");
}

picker.setOnAction(new EventHandler<ActionEvent>() {
Expand All @@ -81,9 +82,11 @@ public void handle(ActionEvent event) {

GUITools.setAllAnchors(picker, 0);

AnchorPane pane = new AnchorPane(picker);
pane.setMinWidth(200);
pane.setMinHeight(40);
return pane;
AnchorPane p = new AnchorPane(picker);

p.setMinWidth(50);
p.setMinHeight(50);

return p;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.tiggerbiggo.prima.primaplay.node.link.type.defaults;

import com.tiggerbiggo.prima.primaplay.core.RenderParams;
import com.tiggerbiggo.prima.primaplay.node.link.type.VectorInputLink;
import com.tiggerbiggo.utils.calculation.Vector2;

public class MapGenDefaultLink extends VectorInputLink {
@Override
public Vector2 defaultValue(RenderParams p) {
return new Vector2(
p.x() * (1d / p.width()),
p.y() * (1d / p.height())
);
}
}
Loading

0 comments on commit 9754bdb

Please sign in to comment.