Skip to content

Instantly share code, notes, and snippets.

@rewfergu
Created October 31, 2013 20:53
Show Gist options
  • Save rewfergu/7256972 to your computer and use it in GitHub Desktop.
Save rewfergu/7256972 to your computer and use it in GitHub Desktop.
Colorize external SVG in Processing
class Blob {
PShape s, stroke, fills, shadow, accentOne, accentTwo, accentThree;
int baseColor = floor(random(100));
int x, y;
float hScale, vScale;
// constructor
Blob(int blob_x, int blob_y, int blob_w, int blob_h) {
x = blob_x;
y = blob_y;
s = loadShape("blob.svg");
hScale = blob_w / s.width;
vScale = blob_h / s.height;
stroke = s.getChild("stroke");
stroke.disableStyle();
stroke.scale(hScale, hScale);
fills = s.getChild("fill");
fills.disableStyle();
fills.scale(hScale, hScale);
shadow = s.getChild("shadow");
shadow.scale(hScale, hScale);
accentOne = s.getChild("accent1");
accentOne.scale(hScale, hScale);
accentOne.disableStyle();
accentTwo = s.getChild("accent2");
accentTwo.disableStyle();
accentTwo.scale(hScale, hScale);
accentThree = s.getChild("accent3");
accentThree.disableStyle();
accentThree.scale(hScale, hScale);
}
//draw blobs
void display() {
noStroke();
fill(baseColor, 50, 15);
shape(stroke, x, y);
fill(baseColor, 50, 80);
shape(fills, x, y);
fill(baseColor+5, 50, 50);
shape(accentOne, x, y);
fill(baseColor+10, 50, 50);
shape(accentTwo, x, y);
fill(baseColor-5, 50, 50);
shape(accentThree, x, y);
shape(shadow, x, y);
}
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
int baseColor = floor(random(100));
int canvasWidth = 1000;
int canvasHeight = 1000;
int gridSize = 200;
int cols = canvasWidth / gridSize;
int rows = canvasHeight / gridSize;
void setup() {
int rowCount = 0;
size(canvasWidth, canvasHeight);
smooth();
colorMode(HSB, 100);
fill(50, 10, 75);
rect(0,0,width,height);
for (int i = 0; i < cols*rows; i++) {
if (i > 1 && i%cols == 0) {
rowCount += gridSize;
}
Blob b = new Blob((i%cols)*gridSize, rowCount, gridSize, gridSize);
b.display();
}
//saveFrame("screen.jpg");
}
void draw() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment