Geomerative and intersection
in
Contributed Library Questions
•
1 year ago
I am trying to make a sketch that will create a vector texture ontop of an SVG and output another shape that becomes the intersection of the two.
Here is some code as an example.
Remember to add your own SVG file and adjust the filename.
I used a simple object with one color shape on one layer.
- import geomerative.*;
- RShape shp2;
- RShape shp3;
- RShape Shading;
- int type = 0;
- void setup() {
- size(600, 600);
- smooth();
- RG.init(this);
- shp2 = RG.loadShape("face.svg");
- }
- void makeShading(int value, int type) {
- background(255);
- float inc = map(value, 0, 255, 2, 100);
- Shading = RShape.createLine(0, 0, 1, 1);
- switch(type)
- {
- case 0:
- for (int v = 0; v < width; v+=inc) {
- Shading.setFill(false);
- Shading.addShape(RShape.createLine(v, 1, v, height-1));
- }
- break;
- case 1:
- for (int v = 0; v < width*2; v+=inc) {
- Shading.addShape(RShape.createLine(v, 0, 0, v));
- }
- break;
- case 2:
- for (int v = 0; v < width*2; v+=inc) {
- Shading.addShape(RShape.createCircle(width/2, height/2, v));
- }
- break;
- case 3:
- for (int v = 0; v < height; v+=inc) {
- Shading.addShape(RShape.createLine(0, v, width, v));
- }
- break;
- }
- Shading.addClose();
- }
- void mousePressed() {
- type++;
- if (type>3) {
- type =0;
- }
- }
- void draw() {
- makeShading((int) map(mouseX, 0, width, 0, 255), type);
- noFill();
- stroke( 100, 0, 0 );
- //RG.shape(Shading);
- // RG.shape(shp2);
- stroke( 0 );
- shp3 = RG.intersection(Shading, shp2);
- RG.shape(shp3);
- }
1