/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Here are a few parameters that you can change to modify the behavior of the patterm // Feel free to modify the values, don't change the variable names // Density of the covered pattern // For example,density of 1 places patters such that if they were aligned one next to another // they would cover all pixels. Keep in mind that since the patterns overlap, you will see gaps. var density = 2 // use a value between 0.1 to 10. The default is 2. // You include random scaling of the patter // If you don't want any variation, set both to 1 var patternScaleFrom = 0.7 // use a values between 0.1 and 3 . The default is 0.5. var patternScaleTo = 1 // use a values between 0.1 and 3 , larger or equal to patternScaleFrom. The default is 1. // Shoud we skip random rotation? var skipRotation = true // the default is false - we are not skipping rotations /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // You can modify the code below but keep in mind that as with any scripting // you can break things. Keep a backup copy. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // We could use Math.random but then we do not have control over the seed // Object rand rand.seed = Math.random()*123456 function rand() { rand.seed = (rand.seed*9301+49297) % 233280; return rand.seed/(233280.0); } /////////////////////////////////////////////////////////////////////////// // get size of the output area var outputSize = RenderAPI.getParameter(kpsSize) // Get pattern and its size var pattern = RenderAPI.getParameter(kpsPattern) var patternSize = pattern.getParameter(kpsSize) // scale up if the patternsize is 1 to avoid long loop var scale = 1 if (patternSize.x == 1 && patternSize.y == 1) { scale = 20 patternSize *= scale skipRotation = true // 1x1 patterns that are scaled up do not rotate gracefully } // place elements at random locations and size var spanWidth = patternSize.x * 0.35 //pattern.setParameter (kpsColorBlendMode, kpsBlendMultiply) pattern.setParameter (kpsPatternBlendMode, kpsBlendDarken) //pattern.setParameter (kpsColorBlendMode, kpsBlendLinearLight) // determine the number approximately based on size of the element and filled area var num = (outputSize.x + outputSize.y) *spanWidth * 20 / (patternSize.x * patternSize.y) * density if (num < 1) num = 1 num *= (spanWidth / patternSize.x * 2.5) * 2 / patternScaleFrom // / patternScaleFrom for (var n = 0; n < num; n++) { RenderAPI.pushMatrix() // determine which edge switch (Math.floor (rand() * 4)) { case 0: // top edge px = 0; py = 0; dx = 1; dy = 0; length = outputSize.x; angle = 270 break; case 1: // bottom edge px = outputSize.x; py = outputSize.y; dx = -1; dy = 0; length = outputSize.x; angle = 90; break; case 2: // left edge px = 0; py = outputSize.y; dx = 0; dy = -1; length = outputSize.y; angle = 180 break; case 3: // right edge px = outputSize.x; py = 0; dx = 0; dy = 1; length = outputSize.y; angle = 0 break; } var r = rand() var w = spanWidth * Math.pow(r, 2); var localScale = scale * (patternScaleFrom + (patternScaleTo - patternScaleFrom) * (1 - (w / spanWidth)) ) var spanAlong = length + (patternSize.x * Math.abs(dx) + patternSize.y * Math.abs(dy)) * localScale var l = spanAlong * rand(); var x = px + dx * l - dy * w var y = py + dy * l + dx * w; RenderAPI.translate(x, y) RenderAPI.scale(localScale, localScale) if (!skipRotation) { var rotate = 360/30 * Math.floor(rand() * 30) // 30 distinct rotations RenderAPI.rotate(rotate) } RenderAPI.rotate (angle) //var rc = colorRandomness // color randomness //var br = 1 - brightnessRandomness + rand()*brightnessRandomness // brightness //RenderAPI.Color (kFillColor, br *(1 - rc + rand()*rc), br*(1 - rc + rand()*rc), br*(1 - rc + rand()*rc)) pattern.render(RenderAPI) RenderAPI.popMatrix() }