使用Indeesign脚本和 /或Basil.js在复杂的矢量形状中绘制随机形状

发布于 2025-01-22 21:02:18 字数 2209 浏览 5 评论 0 原文

我想知道是否有一种简单的方法可以使用Basil.js或Indesign脚本来绘制复杂矢量形状(例如信函形式)内的一系列随机椭圆(或其他内容)。我想出了如何通过使用if语句并检查我的随机椭圆的距离与较大椭圆形的中心的距离,从而将随机尺寸和彩色椭圆放在较大的椭圆中。但是我一生无法找到一种方法,让我的脚本检查我所绘制的随机椭圆是否属于更复杂的形状。任何帮助将不胜感激!

因此,这就是我在将随机椭圆放置在较大椭圆中的工作:

这是我的代码:

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);
}

但是,我该如何处理更复杂的形状类似的事情?下面的示例用字母P说明了这一点,可能会使用PathStopoints()或类似的内容。这甚至可能吗?也许我应该从比字母更简单但比椭圆更复杂的矢量形状开始。

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.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文