Reputation: 5
I am wondering if there is a simple way to draw a series of random ellipses (or other things) within a complex vector shape (say, a letterform) using basil.js or indesign scripting. I figured out how to place random sized and colored ellipses within a larger ellipse by using if statements and checking the distance of my random ellipses from the center fo the larger ellipse. But I can't for the life of me figure out a way to get my script to check and see if the random ellipses I am drawing fall within a more complex shape. Any help would be appreciated!
So this is what I have working as far as placing random ellipses within a larger ellipse:
And here is my code for that:
function stippleCircle(mR, rR, xP, yP, num){
for(i=0; i<num; i++){
noStroke();
println("stip " + i);
var eRad = mR; //maximum ellipse radius
var ranRad = rR //radius for small ellipses
var xPos = xP; //x position of large ellipse
var yPos = yP; //y position of large ellipse
var eRad = 0;
var xRan = random(xPos - eRad, xPos + eRad);
var yRan = random(yPos - eRad, yPos + eRad);
if(xRan <= xPos && yRan <= yPos){
if((xPos-xRan) * (xPos-xRan) + (yRan-yPos) * (yRan-yPos) <= eRad * eRad){
fill(100, 0, 0, 0); //C
var myEllipse = ellipse(xRan, yRan, ranRad, ranRad);
}
}else if(xRan > xPos && yRan <= yPos){
if((xRan-xPos) * (xRan-xPos) + (yRan-yPos) * (yRan-yPos) <= eRad * eRad){
fill(0, 100, 0, 0); //M
var myEllipse = ellipse(xRan, yRan, ranRad, ranRad);
}
}else if(xRan > xPos && yRan > yPos){
if((xRan-xPos) * (xRan-xPos) + (yPos-yRan) * (yPos-yRan) <= eRad * eRad){
fill(0, 0, 100, 0); //Y
var myEllipse = ellipse(xRan, yRan, ranRad, ranRad);
}
}else if(xRan <= xPos && yRan > yPos){
if((xPos-xRan) * (xPos-xRan) + (yPos-yRan) * (yPos-yRan) <= eRad * eRad){
fill(0, 0, 0, 100);
var myEllipse = ellipse(xRan, yRan, ranRad, ranRad);
}
}
blendMode(myEllipse, BlendMode.SOFT_LIGHT);
opacity(myEllipse, 70);
}
But how would I go about doing something similar with a more complex shape? The example below is illustrating this with the letter P and would likely use pathsToPoints() or something like that. Is this even possible? Maybe I should start with a vector shape that is simpler than a letter but more complex than an ellipse.
Upvotes: 0
Views: 177