cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
See how to use to use Text Explorer to glean valuable information from text data at April 25 webinar.
Choose Language Hide Translation Bar
View Original Published Thread

Craige_Hales
Super User
Factory Art

Not-quite-random art generator.  Notice the paint function's use of matrix indexing to avoid an explicit JSL loop to set a vertical line of pixels, more-or-less perpendicular to the path of the brush.  M selects the pixels and blend1 & blend2 make the center of the wide brush stroke opaque and the edges more transparent.  (Off-shoot of another project, inspired in part by Dynamic Image Generation with Python – SWHarden.com.)

FactoryArt - YouTube

12551_pastedImage_1.png

Window( "x" ) << closewindow;

scale = 4;

brows = 1080 * scale;

bcols = 1920 * scale;

red = J( brows, bcols, 0 );

green = J( brows, bcols, 0 );

blue = J( brows, bcols, 0 );

imageno = 0;

paint = Function( {row, col, color, drow},

    {m = Max( 1, Min( brows, row - drow ) ) :: Min( brows, Max( 1, row + drow ) ), r, g, b, blend1 = ((1 :: Max( 1, Floor( N Cols( m ) / 2 ) ))

     || If( N Cols( m ) > 1,

        (Ceiling( N Cols( m ) / 2 ) :: 1),

        []

    ))` / Ceiling( N Cols( m ) / 2 ), blend2 = 1 - blend1},

    {r, g, b} = Color To RGB( color );

    Try(

        red[m, col] = (red[m, col] :* blend2 + r * blend1);

        green[m, col] = (green[m, col] :* blend2 + g * blend1);

        blue[m, col] = (blue[m, col] :* blend2 + b * blend1);

    ,

        Show( exception_msg, row, col, r, blend1, blend2, drow, m );

        Stop();

    );

);

stripe = Function( {amp1, reps1, phase1, reps2, phase2, row, h1, h2, mindr, maxdr},

    {ic, ir, fract, dr, color},

    reps1 *= 2 * Pi();

    reps2 *= 2 * Pi();

    phase1 *= 2 * Pi();

    phase2 *= 2 * Pi();

    amp1 *= scale;

    mindr *= scale;

    maxdr *= scale;

    For( ic = 1, ic <= bcols, ic++,

        fract = ic / bcols;

        ir = row + amp1 * Sin( phase1 + reps1 * fract );

        dr = Interpolate( Sin( phase2 + reps2 * fract ), -1, mindr, 1, maxdr );

        color = HLS Color( Interpolate( fract, 0, h1, 1, h2 ), .5, 1 );

        paint( ir, ic, color, dr );

        If( Mod( ic, 512 ) == 0,

            Wait( .01 );

            img = New Image( "rgb", {red, green, blue} );

            img << scale( .5 );

            img << saveimage( "\VBOXSVR\windowsShare\painter\pics\p" || Right( Char( imageno++ ), 6, "0" ) || ".jpg", "jpg" );

        );

       

    );

);

picture = Function( {nstripes},

    {istripe, fract, hue1, hue2},

    For( istripe = 1, istripe <= nstripes, istripe++,

        Show( istripe );

        fract = istripe / nstripes;

        nfract = 1 - fract;

        thisrow = Random Integer( brows / 200, brows - brows / 200 );

        rfract = thisrow / brows;

        hue1 = Random Uniform( .8 * rfract + .3, .8 * rfract + .3 );

        If( hue1 > 1, hue1 -= 1 );// alow h1 wrap around

        hue2 = hue1 + Random Uniform( 0, .2 );

        If( hue2 > 1, hue2 = 1 );// prevent wrap around for h2

        stripe(

            Interpolate( fract, 0, 50, 1, 10 ), // amp1

            Random Uniform( .1, .4 ), // rep1

            Random Uniform( 0, 1 ), //phase

            Random Uniform( 0, .2 ), // rep2

            Random Uniform( 0, 1 ), // phase2

            thisrow, // target row

            hue1,

            hue2,

            5, // min delta

            Random Integer( 5 + 25 * nfract, 50 + 150 * nfract ) // max delta

        );

    )

);

picture( 100 );

Wait( 0 );

img = New Image( "rgb", {red, green, blue} );

img << scale( .5 );

img << saveimage( "\VBOXSVR\windowsShare\painter\pics\p" || Right( Char( imageno++ ), 6, "0" ) || ".jpg", "jpg" );

New Window( "x", img );