Skip to content

Commit

Permalink
Boxxy style
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Feb 7, 2025
1 parent 5950ea3 commit 344ce5d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
package com.marginallyclever.makelangelo.donatelloimpl.nodes.points;

import com.marginallyclever.donatello.ports.InputImage;
import com.marginallyclever.makelangelo.donatelloimpl.ports.InputTurtle;
import com.marginallyclever.makelangelo.donatelloimpl.ports.OutputTurtle;
import com.marginallyclever.makelangelo.turtle.Turtle;
import com.marginallyclever.nodegraphcore.Node;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
* Place a pattern on a path.
* Place a pattern on a path. Modulate the pattern by the image.
*/
public class PatternAtPoints extends Node {
private final InputTurtle pattern = new InputTurtle("pattern");
private final InputPoints listOfPoints = new InputPoints("points");
private final InputImage inputImage = new InputImage("image");
private final OutputTurtle output = new OutputTurtle("output");

public PatternAtPoints() {
super("PatternAtPoints");
addVariable(pattern);
addVariable(listOfPoints);
addVariable(inputImage);
addVariable(output);
}

Expand All @@ -25,16 +31,32 @@ public void update() {
Turtle result = new Turtle();
Turtle myPattern = pattern.getValue();
ListOfPoints points = listOfPoints.getValue();
BufferedImage image = inputImage.getValue();
var w = image.getWidth();
var h = image.getHeight();

if(points.isEmpty()) {
setComplete(100);
output.send(result);
return;
}

double min = 0.1;
double max = 2.0;

setComplete(0);
int total = points.size();
int i=0;
for(var p : points) {
Turtle stamp = new Turtle(myPattern);
if(p.x>=0 && p.x<w && p.y>=0 && p.y<h) {
// inside image
var c = new Color(image.getRGB((int)p.x,(int)p.y));
// get intensity of c as a value 0....1
var intensity = 1.0-(c.getBlue()+c.getGreen()+c.getRed())/(3.0*255.0);
var i2 = min + intensity * (max-min);
stamp.scale(i2,i2);
}
stamp.translate(p.x,p.y);
result.add(stamp);
setComplete((100*i++/total));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public NGon() {
super("NGon");
addVariable(radius);
addVariable(steps);
addVariable(angle);
addVariable(contents);
}

Expand Down

0 comments on commit 344ce5d

Please # to comment.