diff --git a/engine/test/rgbscript/rgbscript_test.cpp b/engine/test/rgbscript/rgbscript_test.cpp index b771bbaf2..d3770e635 100644 --- a/engine/test/rgbscript/rgbscript_test.cpp +++ b/engine/test/rgbscript/rgbscript_test.cpp @@ -207,7 +207,7 @@ void RGBScript_Test::rgbMapStepCount() void RGBScript_Test::rgbMapColorArray() { RGBMap map; - RGBScript s = m_doc->rgbScriptsCache()->script("Alternate (2 Colors)"); + RGBScript s = m_doc->rgbScriptsCache()->script("Alternate"); QCOMPARE(s.evaluate(), true); QVector rawRgbColors = { QColor(Qt::red).rgb() & 0x00ffffff, diff --git a/resources/rgbscripts/CMakeLists.txt b/resources/rgbscripts/CMakeLists.txt index 2e6925a3c..21a8b2860 100644 --- a/resources/rgbscripts/CMakeLists.txt +++ b/resources/rgbscripts/CMakeLists.txt @@ -2,10 +2,7 @@ project(scripts) set(SCRIPT_FILES alternate.js - alternatecolorsdirect.js balls.js - ballscolors.js - ballscolorsdirect.js blinder.js circles.js circular.js @@ -20,13 +17,10 @@ set(SCRIPT_FILES gradient.js lines.js marquee.js - marqueecolorsdirect.js noise.js onebyone.js opposite.js plasma.js - plasmacolors.js - plasmacolorsdirect.js randomcolumn.js randomfillcolumn.js randomfillrow.js diff --git a/resources/rgbscripts/alternate.js b/resources/rgbscripts/alternate.js index 893336e49..be9aa487f 100644 --- a/resources/rgbscripts/alternate.js +++ b/resources/rgbscripts/alternate.js @@ -21,117 +21,18 @@ var testAlgo; (function() { - var colorPalette = new Object; - colorPalette.collection = new Array( - ["White", 0xFFFFFF], // 0 - ["Cream", 0xFFFF7F], // 1 - ["Pink", 0xFF7F7F], // 2 - ["Rose", 0x7F3F3F], // 3 - ["Coral", 0x7F3F1F], // 4 - ["Dim Red", 0x7F0000], // 5 - ["Red", 0xFF0000], // 6 - ["Orange", 0xFF3F00], // 7 - ["Dim Orange", 0x7F1F00], // 8 - ["Goldenrod", 0x7F3F00], // 9 - ["Gold", 0xFF7F00], // 10 - ["Yellow", 0xFFFF00], // 11 - ["Dim Yellow", 0x7F7F00], // 12 - ["Lime", 0x7FFF00], // 13 - ["Pale Green", 0x3F7F00], // 14 - ["Dim Green", 0x007F00], // 15 - ["Green", 0x00FF00], // 16 - ["Seafoam", 0x00FF3F], // 17 - ["Turquoise", 0x007F3F], // 18 - ["Teal", 0x007F7F], // 19 - ["Cyan", 0x00FFFF], // 20 - ["Electric Blue", 0x007FFF], // 21 - ["Blue", 0x0000FF], // 22 - ["Dim Blue", 0x00007F], // 23 - ["Pale Blue", 0x1F1F7F], // 24 - ["Indigo", 0x1F00BF], // 25 - ["Purple", 0x3F00BF], // 26 - ["Violet", 0x7F007F], // 27 - ["Magenta", 0xFF00FF], // 28 - ["Hot Pink", 0xFF003F], // 29 - ["Deep Pink", 0x7F001F], // 30 - ["OFF", 0x000000]); // 31 - - colorPalette.makeSubArray = function(_index) { - var _array = new Array(); - for (var i = 0; i < colorPalette.collection.length; i++) { - _array.push(colorPalette.collection[i][_index]); - } - return _array; - }; - colorPalette.names = colorPalette.makeSubArray(0); var algo = new Object; - algo.apiVersion = 2; + algo.apiVersion = 3; algo.name = "Alternate"; algo.author = "Hans-Jürgen Tappe"; var x = 0; var y = 0; - algo.acceptColors = 0; + algo.acceptColors = 2; algo.properties = new Array(); - algo.getColorIndex = function(_name) { - var idx = colorPalette.names.indexOf(_name); - if (idx === -1) { - idx = (colorPalette.collection.length - 1); - } - return idx; - }; - - algo.color1Index = algo.getColorIndex("Red"); - algo.properties.push("name:color1Index|type:list|display:Color 1|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor1Index|read:getColor1Name"); - algo.color2Index = algo.getColorIndex("Green"); - algo.properties.push("name:color2Index|type:list|display:Color 2|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor2Index|read:getColor2Name"); - - algo.getColorName = function(_index) { - if (_index < 0) { - _index = 0; - } - if (_index >= colorPalette.collection.length) { - _index = (colorPalette.collection.length - 1); - } - return colorPalette.collection[parseInt(_index, 10)][0]; - }; - algo.getColorValue = function(_index) { - if (_index < 0) { - _index = 0; - } - else if (_index >= colorPalette.collection.length) { - _index = (colorPalette.collection.length - 1); - } - return colorPalette.collection[parseInt(_index, 10)][1]; - }; - - algo.setColor1Index = function(_name) { - algo.color1Index = algo.getColorIndex(_name); - }; - algo.getColor1Name = function() { - return algo.getColorName(algo.color1Index); - }; - algo.getColor1Value = function() { - return algo.getColorValue(algo.color1Index); - }; - - algo.setColor2Index = function(_name) { - algo.color2Index = algo.getColorIndex(_name); - }; - algo.getColor2Name = function() { - return algo.getColorName(algo.color2Index); - }; - algo.getColor2Value = function() { - return algo.getColorValue(algo.color2Index); - }; - algo.align = 0; algo.properties.push("name:align|type:list|" + "display:Align (for even width)|values:Left,Centered,Split|" + @@ -203,17 +104,40 @@ var testAlgo; return algo.offset; }; + var util = new Object; + util.colorArray = new Array(algo.acceptColors); + + util.getRawColor = function (idx) { + var color = 0; + if (Array.isArray(util.colorArray) && util.colorArray.length > idx && util.colorArray[idx]) { + color = util.colorArray[idx]; + } + return color; + } + + algo.rgbMapSetColors = function(rawColors) + { + if (! Array.isArray(rawColors)) + return; + for (var i = 0; i < algo.acceptColors; i++) { + if (i < rawColors.length) + { + util.colorArray[i] = rawColors[i]; + } else { + util.colorArray[i] = 0; + } + } + } + algo.rgbMap = function(width, height, rgb, step) { var map = new Array(height); var colorSelectOne = (step === 1) ? false : true; var rowColorOne = colorSelectOne; var realBlockSize = algo.blockSize; + // Setup the rgb map for (y = 0; y < height; y++) { map[y] = new Array(width); - for (x = 0; x < width; x++) { - map[y][x] = 0; - } } var xMax = width; @@ -303,9 +227,9 @@ var testAlgo; } } if (colorSelectOne) { - map[y][x] = algo.getColor1Value(); + map[y][x] = util.getRawColor(0); } else { - map[y][x] = algo.getColor2Value(); + map[y][x] = util.getRawColor(1); } } } diff --git a/resources/rgbscripts/alternatecolorsdirect.js b/resources/rgbscripts/alternatecolorsdirect.js deleted file mode 100644 index be851b9d4..000000000 --- a/resources/rgbscripts/alternatecolorsdirect.js +++ /dev/null @@ -1,273 +0,0 @@ -/* - Q Light Controller Plus - alternatecolorsdirect.js - - Copyright (c) Hans-Jürgen Tappe - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0.txt - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -// Development tool access -var testAlgo; - -(function() { - - var algo = new Object; - algo.apiVersion = 3; - algo.name = "Alternate (2 Colors)"; - algo.author = "Hans-Jürgen Tappe"; - - var x = 0; - var y = 0; - - algo.acceptColors = 2; - algo.properties = new Array(); - - algo.align = 0; - algo.properties.push("name:align|type:list|" + - "display:Align (for even width)|values:Left,Centered,Split|" + - "write:setAlign|read:getAlign"); - // Left aligned is default. - algo.setAlign = function(_align) { - if (_align === "Centered") { - algo.align = 1; - } else if (_align === "Split") { - algo.align = 2; - } else { - algo.align = 0; - } - }; - algo.getAlign = function() { - if (algo.align === 1) { - return "Centered"; - } else if (algo.align === 2) { - return "Split"; - } else { - return "Left"; - } - }; - - algo.orientation = 0; - algo.properties.push("name:orientation|type:list|" + - "display:Orientation|values:Horizontal,Vertical,Interleaved|" + - "write:setOrientation|read:getOrientation"); - algo.setOrientation = function(_orientation) { - if (_orientation === "Vertical") { - algo.orientation = 1; - } else if (_orientation === "Interleaved") { - algo.orientation = 2; - } else { - algo.orientation = 0; - } - }; - algo.getOrientation = function() { - if (parseInt(algo.orientation, 10) === 1) { - return "Vertical"; - } else if (algo.orientation === 2) { - return "Interleaved"; - } else { - return "Horizontal"; - } - }; - - algo.blockSize = 1; - algo.properties.push("name:blockSize|type:range|" - + "display:Block Size / Split (>= 1)|" - + "values:1,32000|" - + "write:setBlockSize|read:getBlockSize"); - algo.setBlockSize = function(_size) { - algo.blockSize = parseInt(_size, 10); - }; - algo.getBlockSize = function() { - return algo.blockSize; - }; - - algo.offset = 0; - algo.properties.push("name:offset|type:range|" - + "display:Offset (>= 0)|" - + "values:0,32000|" - + "write:setOffset|read:getOffset"); - algo.setOffset = function(_size) { - algo.offset = parseInt(_size, 10); - }; - algo.getOffset = function() { - return algo.offset; - }; - - var util = new Object; - util.colorArray = new Array(algo.acceptColors); - - util.getRawColor = function (idx) { - var color = 0; - if (Array.isArray(util.colorArray) && util.colorArray.length > idx && ! isNaN(util.colorArray[idx])) { - color = util.colorArray[idx]; - } - return color; - } - - algo.rgbMapSetColors = function(rawColors) - { - if (! Array.isArray(rawColors)) - return; - for (var i = 0; i < algo.acceptColors; i++) { - if (i < rawColors.length) - { - util.colorArray[i] = rawColors[i]; - } else { - util.colorArray[i] = 0; - } - } - } - - algo.rgbMap = function(width, height, rgb, step) { - var map = new Array(height); - var colorSelectOne = (step === 1) ? false : true; - var rowColorOne = colorSelectOne; - var realBlockSize = algo.blockSize; - - // Setup the rgb map - for (y = 0; y < height; y++) { - map[y] = new Array(width); - } - - var xMax = width; - var yMax = height; - if (algo.align === 1) { - if (algo.orientation === 0 || algo.orientation === 2) { - // Centered mode - xMax = Math.ceil(width / 2); - } - if (algo.orientation === 1 || algo.orientation === 2) { - // Centered mode - yMax = Math.ceil(height / 2); - } - } - - if (algo.align === 2) { - // Split mode - if (algo.orientation === 0) { - // Horizontal - realBlockSize = width / algo.blockSize; - } else if (algo.orientation === 1) { - // Vertical - realBlockSize = height / algo.blockSize; - } else if (algo.orientation === 2) { - // Interleaved - realBlockSize = Math.min(width, height) / algo.blockSize; - } - } - - var effectiveStep; - var realBlockCount; - var lowRest; - var highRest; - var rest; - for (y = 0; y < yMax; y++) { - if (algo.orientation === 0) { - // Horizontal split; vertical lines - // Initialize vertical bars, each column the same - colorSelectOne = (step === 1) ? false : true; - } else if (algo.orientation === 1) { - // Horizontal Bars, count steps by row - effectiveStep = y + Math.round(step * realBlockSize) + algo.offset; - - // Initialize start color for each row. - realBlockCount = Math.floor(effectiveStep / realBlockSize); - lowRest = effectiveStep - realBlockCount * realBlockSize; - highRest = (realBlockCount + 1) * realBlockSize - effectiveStep; - rest = Math.min(lowRest, highRest); - if (rest < 0.5 || lowRest === 0.5) { - colorSelectOne = !colorSelectOne; - } - } else if (algo.orientation === 2) { - // Interleaved - var effectiveY = y + Math.floor(step * realBlockSize) + algo.offset; - - realBlockCount = Math.floor(effectiveY / realBlockSize); - lowRest = effectiveY - realBlockCount * realBlockSize; - highRest = (realBlockCount + 1) * realBlockSize - effectiveY; - rest = Math.min(lowRest, highRest); - if (rest < 0.5 || lowRest === 0.5) { - rowColorOne = !rowColorOne; - } - colorSelectOne = rowColorOne; - } - - for (x = 0; x < xMax; x++) { - if (algo.orientation === 0) { - // Horizontal split, vertical bars, count steps by column - effectiveStep = x + algo.offset; - realBlockCount = Math.floor(effectiveStep / realBlockSize); - lowRest = effectiveStep - realBlockCount * realBlockSize; - highRest = (realBlockCount + 1) * realBlockSize - effectiveStep; - rest = Math.min(lowRest, highRest); - if (rest < 0.5 || lowRest === 0.5) { - colorSelectOne = !colorSelectOne; - } - } else if (algo.orientation === 2) { - // vertical split, horizontal Bars, count steps by row and column - var effectiveX = x + Math.floor(step * realBlockSize) + algo.offset; - // Change color each step. - realBlockCount = Math.floor(effectiveX / realBlockSize); - lowRest = effectiveX - realBlockCount * realBlockSize; - highRest = (realBlockCount + 1) * realBlockSize - effectiveX; - rest = Math.min(lowRest, highRest); - if (rest < 0.5 || lowRest == 0.5) { - colorSelectOne = !colorSelectOne; - } - } - if (colorSelectOne) { - map[y][x] = util.getRawColor(0); - } else { - map[y][x] = util.getRawColor(1); - } - } - } - // Align centered - if (algo.align === 1) { - if (algo.orientation === 0) { - for (y = 0; y < yMax; y++) { - for (x = 0; x < xMax; x++) { - map[y][width - x - 1] = map[y][x]; - } - } - } else if (algo.orientation === 1) { - for (y = 0; y < yMax; y++) { - for (x = 0; x < xMax; x++) { - map[height - y - 1][x] = map[y][x]; - } - } - } else if (algo.orientation === 2) { - for (y = 0; y < yMax; y++) { - for (x = 0; x < xMax; x++) { - map[height - y - 1][x] = map[y][x]; - map[y][width - x - 1] = map[y][x]; - map[height - y - 1][width - x - 1] = map[y][x]; - } - } - } - } - - return map; - }; - - algo.rgbMapStepCount = function(width, height) { - // Only two steps; one for even pixels and another for odd pixels - return 2; - }; - - // Development tool access - testAlgo = algo; - - return algo; -})(); diff --git a/resources/rgbscripts/balls.js b/resources/rgbscripts/balls.js index f957953ce..fdfdc1e91 100644 --- a/resources/rgbscripts/balls.js +++ b/resources/rgbscripts/balls.js @@ -2,16 +2,16 @@ Q Light Controller Plus balls.js - Copyright (c) Tim Cullingworth + Copyright (c) Rob Nieuwenhuizen, Tim Cullingworth - Licensed under the Apache License, Version 2.0 (the "License"); + Licensed under the Apache License, Version 2.0 (the 'License'); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.txt Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, + distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. @@ -21,122 +21,149 @@ var testAlgo; ( - function() - { + function () { var algo = new Object; - algo.apiVersion = 2; + algo.apiVersion = 3; algo.name = "Balls"; - algo.author = "Tim Cullingworth"; - algo.acceptColors = 1; + algo.author = "Rob Nieuwenhuizen, Tim Cullingworth"; + algo.acceptColors = 5; algo.properties = new Array(); - algo.rstepcount = 0; - algo.gstepcount = 50; - algo.bstepcount = 100; - algo.presetSize = 1; - algo.properties.push("name:presetSize|type:range|display:Size|values:1,20|write:setSize|read:getSize"); + algo.properties.push( + "name:presetSize|type:range|display:Size|" + + "values:1,20|write:setSize|read:getSize"); algo.presetNumber = 5; - algo.properties.push("name:presetNumber|type:range|display:Number|values:1,50|write:setNumber|read:getNumber"); - algo.presetRandom = 1; - algo.properties.push("name:presetRandom|type:list|display:Random Colour|values:No,Yes|write:setRandom|read:getRandom"); - algo.presetCollision = 1; - algo.properties.push("name:presetCollision|type:list|display:Self Collision|values:No,Yes|write:setCollision|read:getCollision"); - var util = new Object; + algo.properties.push( + "name:presetNumber|type:range|display:Number|" + + "values:1,15|write:setNumber|read:getNumber"); + algo.presetCollision = 0; + algo.properties.push( + "name:presetCollision|type:list|display:Self Collision|" + + "values:No,Yes|write:setCollision|read:getCollision"); + algo.presetSize = 5; + algo.properties.push( + "name:presetIndex|type:list|display:Preset|" + + "values:User Defined,Random|" + + "write:setPreset|read:getPreset"); + algo.presetIndex = 0; + algo.initialized = false; + + var util = new Object; + util.colorArray = new Array(algo.acceptColors); - algo.setSize = function(_size) - { + algo.setSize = function (_size) { algo.presetSize = _size; }; - - algo.getSize = function() - { + algo.getSize = function () { return algo.presetSize; }; - algo.setNumber = function(_step) - { + algo.setNumber = function (_step) { algo.presetNumber = _step; algo.initialized = false; }; - - algo.getNumber = function() - { + algo.getNumber = function () { return algo.presetNumber; }; - - algo.setRandom = function(_random) - { - if (_random === "Yes") { algo.presetRandom = 0; } - else if (_random === "No") { algo.presetRandom = 1; } + algo.setCollision = function (_colision) { + if (_colision === "Yes") { algo.presetCollision = 0; } + else if (_colision === "No") { algo.presetCollision = 1; } }; - - algo.getRandom = function() - { - if (algo.presetRandom === 0) { return "Yes"; } - else if (algo.presetRandom === 1) { return "No"; } + algo.getCollision = function () { + if (algo.presetCollision === 0) { return "Yes"; } + else if (algo.presetCollision === 1) { return "No"; } }; - algo.setCollision = function(_colision) + util.getRawColor = function (idx) { + idx = idx % util.colorArray.length; + var color = util.colorArray[idx]; + return color; + } + + algo.setPreset = function(_preset) { - if (_colision === "Yes") { algo.presetCollision = 0; } - else if (_colision === "No") { algo.presetCollision = 1; } + algo.acceptColors = 0; + if (_preset === "User Defined") + { + algo.presetIndex = 0; + algo.acceptColors = 5; + util.colorArray = [ 0x00FF00, 0xFFAA00, 0x0000FF, 0xFFFF00, 0x00AAFF ]; + } + else if (_preset === "Random") + { + algo.presetIndex = 1; + util.colorArray = new Array(); + for (var i = 0; i < algo.presetNumber; i++) + { + do + { + var ballR = Math.round(Math.random() * 255); // Chose random + var ballG = Math.round(Math.random() * 255); // colour for + var ballB = Math.round(Math.random() * 255); // each Ball + } while ((ballR + ballG + ballB) < 356); // if it it to dim try again + util.colorArray[i] = (ballR << 16) + (ballG << 8) + ballB; + } + } + else { algo.presetIndex = 0; } + util.initialized = false; }; - algo.getCollision = function() + algo.getPreset = function() { - if (algo.presetCollision === 0) { return "Yes"; } - else if (algo.presetCollision === 1) { return "No"; } + if (algo.presetIndex === 0) { return "User Defined"; } + else if (algo.presetIndex === 1) { return "Random"; } + else { return "Rainbow"; } }; - - util.initialize = function(width, height) + + algo.rgbMapSetColors = function(rawColors) { + if (! Array.isArray(rawColors)) + return; + if (algo.acceptColors > 0) + util.colorArray = Array(); + for (var i = 0; i < algo.acceptColors; i++) { + var isNumber = (rawColors[i] === rawColors[i]); + var color = rawColors[i]; + if (i < rawColors.length && isNumber) + { + util.colorArray.push(color); + } + } + } + + util.initialize = function (width, height) { algo.ball = new Array(algo.presetNumber); algo.direction = new Array(algo.presetNumber); - algo.colour = new Array(algo.presetNumber); - for (var i = 0; i < algo.presetNumber; i++) - { + for (var i = 0; i < algo.presetNumber; i++) { var x = Math.random() * (width - 1); // set random start var y = Math.random() * (height - 1); // locations for balls algo.ball[i] = [y, x]; var yDirection = (Math.random() * 2) - 1; // and random directions var xDirection = (Math.random() * 2) - 1; algo.direction[i] = [yDirection, xDirection]; - do - { - var ballR = Math.round(Math.random() * 255); // Chose random - var ballG = Math.round(Math.random() * 255); // colour for - var ballB = Math.round(Math.random() * 255); // each Ball - } while ((ballR + ballG + ballB) < 356); // if it it to dim try again - algo.colour[i] = (ballR << 16) + (ballG << 8) + ballB; } - - algo.initialized = true; - return; + algo.initialized = true; + return; }; - algo.rgbMap = function(width, height, rgb, progstep) - { - if (algo.initialized === false) - { + algo.rgbMap = function (width, height, rgb, progstep) { + if (algo.initialized === false) { util.initialize(width, height); } - var map = new Array(height); // Clear map data - for (var y = 0; y < height; y++) - { - map[y] = new Array(); + var map = new Array(height); // Clear map data + for (var y = 0; y < height; y++) { + map[y] = new Array(); - for (var x = 0; x < width; x++) - { - map[y][x] = 0; - } + for (var x = 0; x < width; x++) { + map[y][x] = 0; + } } - for (var i = 0; i < algo.presetNumber; i++) // for each ball displayed - { - if (algo.presetRandom === 0) { rgb = algo.colour[i]; } // use RGB or ball random colour + for (var i = 0; i < algo.presetNumber; i++) { // for each ball displayed + rgb = util.getRawColor(i); // use RGB for ball random colour var r = (rgb >> 16) & 0x00FF; // split colour in to var g = (rgb >> 8) & 0x00FF; // separate parts var b = rgb & 0x00FF; @@ -146,13 +173,12 @@ var testAlgo; var mx = Math.floor(yx[1]); var boxSize = Math.round(algo.presetSize / 2); // area size to draw ball - for (var ry = my-boxSize; ry < my+boxSize+2; ry++) // area for faded edges - { - for (var rx = mx-boxSize; rx < mx+boxSize+2; rx++) // to display ball - { - if (rx < width && rx > -1 && ry < height && ry > -1) // if edges are off the map - { // dont draw - var pointRGB = map[ry][rx]; // get curent colour on the map + for (var ry = my - boxSize; ry < my + boxSize + 2; ry++) { // area for faded edges + + for (var rx = mx - boxSize; rx < mx + boxSize + 2; rx++) { // to display ball + + if (rx < width && rx > -1 && ry < height && ry > -1) { // if edges are off the map dont draw + var pointRGB = map[ry][rx]; // get curent colour on the map var pointr = (pointRGB >> 16) & 0x00FF;// so that colours mix and don't over var pointg = (pointRGB >> 8) & 0x00FF; // write. var pointb = pointRGB & 0x00FF; // splt rgb in to components @@ -161,7 +187,8 @@ var testAlgo; var ballb = b; var offx = rx - yx[1]; // calculate the off set differance of map location var offy = ry - yx[0]; // to the float location of the ball, using the hypotenuse - var hyp = 1 - (Math.sqrt( (offx * offx) + (offy * offy))/((algo.presetSize/2)+1)); + var hyp = 1 - (Math.sqrt((offx * offx) + (offy * offy)) / ((algo.presetSize / 2) + 1)); + if (hyp < 0) { hyp = 0; } // if the distance multiplyed by ball size is negative = 0 pointr += Math.round(ballr * hyp); // dim mapped ball colours by the distance from pointg += Math.round(ballg * hyp); // the ball center ( hyp = 1, full colour / 0, off) @@ -176,18 +203,16 @@ var testAlgo; } } } - if (algo.presetCollision === 0) // if colision detection is on - { + + if (algo.presetCollision === 0) { // if colision detection is on // Ball collision detection - for (var ti = 0; ti < algo.presetNumber; ti++) // check all balls - { - if (ti !== i) // but not the current one - { + for (var ti = 0; ti < algo.presetNumber; ti++) { // check all balls + + if (ti !== i) { // but not the current one var disy = (yx[0] + step[0]) - algo.ball[ti][0]; // calculate distance var disx = (yx[1] + step[1]) - algo.ball[ti][1]; // to current ball var dish = Math.sqrt((disx * disx) + (disy * disy)); - if (dish < (1.414) * (algo.presetSize/2)) // if to close - { + if (dish < (1.414) * (algo.presetSize / 2)) { // if to close var stepy = step[0]; // swap speed / direction of current ball var stepx = step[1]; // with ball that is to close algo.direction[i][0] = algo.direction[ti][0]; @@ -201,10 +226,10 @@ var testAlgo; // edge collision detection if (yx[0] <= 0 && step[0] < 0) { step[0] *= -1; } // top edge and moving up - else if (yx[0] >= height-1 && step[0] > 0) { step[0] *= -1; } // bottom edge and moving down + else if (yx[0] >= height - 1 && step[0] > 0) { step[0] *= -1; } // bottom edge and moving down if (yx[1] <= 0 && step[1] < 0) { step[1] *= -1; } // left edge and moving left - else if (yx[1] >= width-1 && step[1] > 0) { step[1] *= -1; } // right edge and moving right + else if (yx[1] >= width - 1 && step[1] > 0) { step[1] *= -1; } // right edge and moving right yx[0] += step[0]; // set ball's next location yx[1] += step[1]; @@ -212,12 +237,10 @@ var testAlgo; algo.ball[i] = yx; // update location algo.direction[i] = step; // and direction / speed } - return map; }; - algo.rgbMapStepCount = function(width, height) - { + algo.rgbMapStepCount = function (width, height) { // This make no difference to the script ;-) return 2; }; diff --git a/resources/rgbscripts/ballscolors.js b/resources/rgbscripts/ballscolors.js deleted file mode 100644 index 994cacfde..000000000 --- a/resources/rgbscripts/ballscolors.js +++ /dev/null @@ -1,317 +0,0 @@ -/* - Q Light Controller Plus - ballscolors.js - - Copyright (c) Rob Nieuwenhuizen - - Licensed under the Apache License, Version 2.0 (the 'License'); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0.txt - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an 'AS IS' BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Development tool access -var testAlgo; - -( - function () { - var colorPalette = new Object; - colorPalette.collection = new Array( - ["White" , 0xFFFFFF], // 0 - ["Cream" , 0xFFFF7F], // 1 - ["Pink" , 0xFF7F7F], // 2 - ["Rose" , 0x7F3F3F], // 3 - ["Coral" , 0x7F3F1F], // 4 - ["Dim Red" , 0x7F0000], // 5 - ["Red" , 0xFF0000], // 6 - ["Orange" , 0xFF3F00], // 7 - ["Dim Orange" , 0x7F1F00], // 8 - ["Goldenrod" , 0x7F3F00], // 9 - ["Gold" , 0xFF7F00], // 10 - ["Yellow" , 0xFFFF00], // 11 - ["Dim Yellow" , 0x7F7F00], // 12 - ["Lime" , 0x7FFF00], // 13 - ["Pale Green" , 0x3F7F00], // 14 - ["Dim Green" , 0x007F00], // 15 - ["Green" , 0x00FF00], // 16 - ["Seafoam" , 0x00FF3F], // 17 - ["Turquoise" , 0x007F3F], // 18 - ["Teal" , 0x007F7F], // 19 - ["Cyan" , 0x00FFFF], // 20 - ["Electric Blue", 0x007FFF], // 21 - ["Blue" , 0x0000FF], // 22 - ["Dim Blue" , 0x00007F], // 23 - ["Pale Blue" , 0x1F1F7F], // 24 - ["Indigo" , 0x1F00BF], // 25 - ["Purple" , 0x3F00BF], // 26 - ["Violet" , 0x7F007F], // 27 - ["Magenta" , 0xFF00FF], // 28 - ["Hot Pink" , 0xFF003F], // 29 - ["Deep Pink" , 0x7F001F], // 30 - ["Black" , 0x000000]); // 31 - - colorPalette.makeSubArray = function (_index) { - var _array = new Array(); - for (var i = 0; i < colorPalette.collection.length; i++) { - _array.push(colorPalette.collection[i][_index]); - } - return _array; - }; - colorPalette.names = colorPalette.makeSubArray(0); - - var algo = new Object; - algo.apiVersion = 2; - algo.name = "Balls (Colors)"; - algo.author = "Rob Nieuwenhuizen"; - algo.acceptColors = 0; - algo.properties = new Array(); - algo.presetSize = 1; - algo.properties.push("name:presetSize|type:range|display:Size|values:1,20|write:setSize|read:getSize"); - algo.presetNumber = 5; - algo.properties.push("name:presetNumber|type:range|display:Number|values:1,5|write:setNumber|read:getNumber"); - algo.presetCollision = 0; - algo.properties.push("name:presetCollision|type:list|display:Self Collision|values:No,Yes|write:setCollision|read:getCollision"); - algo.color1Index = 0; - algo.properties.push( - "name:color1Index|type:list|display:Color 1|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor1|read:getColor1"); - algo.color2Index = 6; - algo.properties.push( - "name:color2Index|type:list|display:Color 2|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor2|read:getColor2"); - algo.color3Index = 16; - algo.properties.push( - "name:color3Index|type:list|display:Color 3|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor3|read:getColor3"); - algo.color4Index = 22; - algo.properties.push( - "name:color4Index|type:list|display:Color 4|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor4|read:getColor4"); - algo.color5Index = 7; - algo.properties.push( - "name:color5Index|type:list|display:Color 5|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor5|read:getColor5"); - algo.presetSize = 5; - - algo.colorIndex = new Array( - algo.color1Index, - algo.color2Index, - algo.color3Index, - algo.color4Index, - algo.color5Index); - - var util = new Object; - algo.initialized = false; - - algo.setSize = function (_size) { - algo.presetSize = _size; - }; - algo.getSize = function () { - return algo.presetSize; - }; - - algo.setNumber = function (_step) { - algo.presetNumber = _step; - algo.initialized = false; - }; - algo.getNumber = function () { - return algo.presetNumber; - }; - algo.setCollision = function (_colision) { - if (_colision === "Yes") { algo.presetCollision = 0; } - else if (_colision === "No") { algo.presetCollision = 1; } - }; - algo.getCollision = function () { - if (algo.presetCollision === 0) { return "Yes"; } - else if (algo.presetCollision === 1) { return "No"; } - }; - - algo.setColor = function (_index, _preset) { - var i = colorPalette.names.indexOf(_preset); - if (i === -1) { - i = (colorPalette.collection.length - 1); - } - algo.colorIndex[_index] = i; - return algo.colorIndex[_index]; - }; - algo.getColor = function (_index) { - var i = algo.colorIndex[_index]; - if (i < 0) { i = 0; } - if (i >= colorPalette.collection.length) { - i = (colorPalette.collection.length - 1); - } - return colorPalette.collection[i][0]; - }; - - algo.setColor1 = function (_preset) { - algo.color1Index = algo.setColor(0, _preset); - algo.initialized = false; - }; - algo.getColor1 = function () { - return algo.getColor(0); - }; - - algo.setColor2 = function (_preset) { - algo.color2Index = algo.setColor(1, _preset); - algo.initialized = false; - }; - algo.getColor2 = function () { - return algo.getColor(1); - }; - - algo.setColor3 = function (_preset) { - algo.color3Index = algo.setColor(2, _preset); - algo.initialized = false; - }; - algo.getColor3 = function () { - return algo.getColor(2); - }; - - algo.setColor4 = function (_preset) { - algo.color4Index = algo.setColor(3, _preset); - algo.initialized = false; - }; - algo.getColor4 = function () { - return algo.getColor(3); - }; - - algo.setColor5 = function (_preset) { - algo.color5Index = algo.setColor(4, _preset); - algo.initialized = false; - }; - algo.getColor5 = function () { - return algo.getColor(4); - }; - - util.initialize = function (width, height) { - algo.ball = new Array(algo.presetNumber); - algo.direction = new Array(algo.presetNumber); - algo.colour = new Array(algo.presetNumber); - - for (var i = 0; i < algo.presetNumber; i++) { - var x = Math.random() * (width - 1); // set random start - var y = Math.random() * (height - 1); // locations for balls - algo.ball[i] = [y, x]; - var yDirection = (Math.random() * 2) - 1; // and random directions - var xDirection = (Math.random() * 2) - 1; - algo.direction[i] = [yDirection, xDirection]; - algo.colour[i] = colorPalette.collection[algo.colorIndex[i]][1]; - } - algo.initialized = true; - return; - }; - - algo.rgbMap = function (width, height, rgb, progstep) { - if (algo.initialized === false) { - util.initialize(width, height); - } - var map = new Array(height); // Clear map data - for (var y = 0; y < height; y++) { - map[y] = new Array(); - - for (var x = 0; x < width; x++) { - map[y][x] = 0; - } - } - - for (var i = 0; i < algo.presetNumber; i++) { // for each ball displayed - rgb = algo.colour[i]; // use RGB for ball random colour - var r = (rgb >> 16) & 0x00FF; // split colour in to - var g = (rgb >> 8) & 0x00FF; // separate parts - var b = rgb & 0x00FF; - var yx = algo.ball[i]; // ball's location, as float - var step = algo.direction[i]; // ball's direction / speed, as float - var my = Math.floor(yx[0]); // workout closest map location for ball - var mx = Math.floor(yx[1]); - var boxSize = Math.round(algo.presetSize / 2); // area size to draw ball - - for (var ry = my - boxSize; ry < my + boxSize + 2; ry++) { // area for faded edges - - for (var rx = mx - boxSize; rx < mx + boxSize + 2; rx++) { // to display ball - - if (rx < width && rx > -1 && ry < height && ry > -1) { // if edges are off the map dont draw - var pointRGB = map[ry][rx]; // get curent colour on the map - var pointr = (pointRGB >> 16) & 0x00FF;// so that colours mix and don't over - var pointg = (pointRGB >> 8) & 0x00FF; // write. - var pointb = pointRGB & 0x00FF; // splt rgb in to components - var ballr = r; - var ballg = g; - var ballb = b; - var offx = rx - yx[1]; // calculate the off set differance of map location - var offy = ry - yx[0]; // to the float location of the ball, using the hypotenuse - var hyp = 1 - (Math.sqrt((offx * offx) + (offy * offy)) / ((algo.presetSize / 2) + 1)); - - if (hyp < 0) { hyp = 0; } // if the distance multiplyed by ball size is negative = 0 - pointr += Math.round(ballr * hyp); // dim mapped ball colours by the distance from - pointg += Math.round(ballg * hyp); // the ball center ( hyp = 1, full colour / 0, off) - pointb += Math.round(ballb * hyp); // add the ball colour to the mapped location - if (pointr > 255) { pointr = 255; } // if addind the colours over saturates - if (pointg > 255) { pointg = 255; } // reduce it to the maximum - if (pointb > 255) { pointb = 255; } - - pointRGB = (pointr << 16) + (pointg << 8) + pointb; // combine colours - - map[ry][rx] = pointRGB; // set mapped point - } - } - } - - if (algo.presetCollision === 0) { // if colision detection is on - // Ball collision detection - for (var ti = 0; ti < algo.presetNumber; ti++) { // check all balls - - if (ti !== i) { // but not the current one - var disy = (yx[0] + step[0]) - algo.ball[ti][0]; // calculate distance - var disx = (yx[1] + step[1]) - algo.ball[ti][1]; // to current ball - var dish = Math.sqrt((disx * disx) + (disy * disy)); - if (dish < (1.414) * (algo.presetSize / 2)) { // if to close - var stepy = step[0]; // swap speed / direction of current ball - var stepx = step[1]; // with ball that is to close - algo.direction[i][0] = algo.direction[ti][0]; - algo.direction[i][1] = algo.direction[ti][1]; - algo.direction[ti][0] = stepy; - algo.direction[ti][1] = stepx; - } - } - } - } - - // edge collision detection - if (yx[0] <= 0 && step[0] < 0) { step[0] *= -1; } // top edge and moving up - else if (yx[0] >= height - 1 && step[0] > 0) { step[0] *= -1; } // bottom edge and moving down - - if (yx[1] <= 0 && step[1] < 0) { step[1] *= -1; } // left edge and moving left - else if (yx[1] >= width - 1 && step[1] > 0) { step[1] *= -1; } // right edge and moving right - - yx[0] += step[0]; // set ball's next location - yx[1] += step[1]; - - algo.ball[i] = yx; // update location - algo.direction[i] = step; // and direction / speed - } - return map; - }; - - algo.rgbMapStepCount = function (width, height) { - // This make no difference to the script ;-) - return 2; - }; - - // Development tool access - testAlgo = algo; - - return algo; - } -)(); diff --git a/resources/rgbscripts/ballscolorsdirect.js b/resources/rgbscripts/ballscolorsdirect.js deleted file mode 100644 index c4ba23057..000000000 --- a/resources/rgbscripts/ballscolorsdirect.js +++ /dev/null @@ -1,207 +0,0 @@ -/* - Q Light Controller Plus - ballscolorsdirect.js - - Copyright (c) Rob Nieuwenhuizen - - Licensed under the Apache License, Version 2.0 (the 'License'); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0.txt - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an 'AS IS' BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Development tool access -var testAlgo; - -( - function () { - var algo = new Object; - algo.apiVersion = 3; - algo.name = "Balls (5 Colors)"; - algo.author = "Rob Nieuwenhuizen"; - algo.acceptColors = 5; - algo.properties = new Array(); - algo.presetSize = 1; - algo.properties.push("name:presetSize|type:range|display:Size|values:1,20|write:setSize|read:getSize"); - algo.presetNumber = 5; - algo.properties.push("name:presetNumber|type:range|display:Number|values:1,15|write:setNumber|read:getNumber"); - algo.presetCollision = 0; - algo.properties.push("name:presetCollision|type:list|display:Self Collision|values:No,Yes|write:setCollision|read:getCollision"); - algo.presetSize = 5; - - algo.initialized = false; - - var util = new Object; - util.colorArray = new Array(algo.acceptColors); - - algo.setSize = function (_size) { - algo.presetSize = _size; - }; - algo.getSize = function () { - return algo.presetSize; - }; - - algo.setNumber = function (_step) { - algo.presetNumber = _step; - algo.initialized = false; - }; - algo.getNumber = function () { - return algo.presetNumber; - }; - algo.setCollision = function (_colision) { - if (_colision === "Yes") { algo.presetCollision = 0; } - else if (_colision === "No") { algo.presetCollision = 1; } - }; - algo.getCollision = function () { - if (algo.presetCollision === 0) { return "Yes"; } - else if (algo.presetCollision === 1) { return "No"; } - }; - - util.getRawColor = function (idx) { - var color = 0; - if (Array.isArray(util.colorArray) && util.colorArray.length > idx && ! isNaN(util.colorArray[idx])) { - color = util.colorArray[idx]; - } - return color; - } - - algo.rgbMapSetColors = function(rawColors) - { - if (! Array.isArray(rawColors)) - return; - for (var i = 0; i < algo.acceptColors; i++) { - if (i < rawColors.length) - { - util.colorArray[i] = rawColors[i]; - } else { - util.colorArray[i] = 0; - } - } - } - - util.initialize = function (width, height) { - algo.ball = new Array(algo.presetNumber); - algo.direction = new Array(algo.presetNumber); - - for (var i = 0; i < algo.presetNumber; i++) { - var x = Math.random() * (width - 1); // set random start - var y = Math.random() * (height - 1); // locations for balls - algo.ball[i] = [y, x]; - var yDirection = (Math.random() * 2) - 1; // and random directions - var xDirection = (Math.random() * 2) - 1; - algo.direction[i] = [yDirection, xDirection]; - } - algo.initialized = true; - return; - }; - - algo.rgbMap = function (width, height, rgb, progstep) { - if (algo.initialized === false) { - util.initialize(width, height); - } - - var map = new Array(height); // Clear map data - for (var y = 0; y < height; y++) { - map[y] = new Array(); - - for (var x = 0; x < width; x++) { - map[y][x] = 0; - } - } - - for (var i = 0; i < algo.presetNumber; i++) { // for each ball displayed - rgb = util.getRawColor(i % algo.acceptColors); // use RGB for ball random colour - var r = (rgb >> 16) & 0x00FF; // split colour in to - var g = (rgb >> 8) & 0x00FF; // separate parts - var b = rgb & 0x00FF; - var yx = algo.ball[i]; // ball's location, as float - var step = algo.direction[i]; // ball's direction / speed, as float - var my = Math.floor(yx[0]); // workout closest map location for ball - var mx = Math.floor(yx[1]); - var boxSize = Math.round(algo.presetSize / 2); // area size to draw ball - - for (var ry = my - boxSize; ry < my + boxSize + 2; ry++) { // area for faded edges - - for (var rx = mx - boxSize; rx < mx + boxSize + 2; rx++) { // to display ball - - if (rx < width && rx > -1 && ry < height && ry > -1) { // if edges are off the map dont draw - var pointRGB = map[ry][rx]; // get curent colour on the map - var pointr = (pointRGB >> 16) & 0x00FF;// so that colours mix and don't over - var pointg = (pointRGB >> 8) & 0x00FF; // write. - var pointb = pointRGB & 0x00FF; // splt rgb in to components - var ballr = r; - var ballg = g; - var ballb = b; - var offx = rx - yx[1]; // calculate the off set differance of map location - var offy = ry - yx[0]; // to the float location of the ball, using the hypotenuse - var hyp = 1 - (Math.sqrt((offx * offx) + (offy * offy)) / ((algo.presetSize / 2) + 1)); - - if (hyp < 0) { hyp = 0; } // if the distance multiplyed by ball size is negative = 0 - pointr += Math.round(ballr * hyp); // dim mapped ball colours by the distance from - pointg += Math.round(ballg * hyp); // the ball center ( hyp = 1, full colour / 0, off) - pointb += Math.round(ballb * hyp); // add the ball colour to the mapped location - if (pointr > 255) { pointr = 255; } // if addind the colours over saturates - if (pointg > 255) { pointg = 255; } // reduce it to the maximum - if (pointb > 255) { pointb = 255; } - - pointRGB = (pointr << 16) + (pointg << 8) + pointb; // combine colours - - map[ry][rx] = pointRGB; // set mapped point - } - } - } - - if (algo.presetCollision === 0) { // if colision detection is on - // Ball collision detection - for (var ti = 0; ti < algo.presetNumber; ti++) { // check all balls - - if (ti !== i) { // but not the current one - var disy = (yx[0] + step[0]) - algo.ball[ti][0]; // calculate distance - var disx = (yx[1] + step[1]) - algo.ball[ti][1]; // to current ball - var dish = Math.sqrt((disx * disx) + (disy * disy)); - if (dish < (1.414) * (algo.presetSize / 2)) { // if to close - var stepy = step[0]; // swap speed / direction of current ball - var stepx = step[1]; // with ball that is to close - algo.direction[i][0] = algo.direction[ti][0]; - algo.direction[i][1] = algo.direction[ti][1]; - algo.direction[ti][0] = stepy; - algo.direction[ti][1] = stepx; - } - } - } - } - - // edge collision detection - if (yx[0] <= 0 && step[0] < 0) { step[0] *= -1; } // top edge and moving up - else if (yx[0] >= height - 1 && step[0] > 0) { step[0] *= -1; } // bottom edge and moving down - - if (yx[1] <= 0 && step[1] < 0) { step[1] *= -1; } // left edge and moving left - else if (yx[1] >= width - 1 && step[1] > 0) { step[1] *= -1; } // right edge and moving right - - yx[0] += step[0]; // set ball's next location - yx[1] += step[1]; - - algo.ball[i] = yx; // update location - algo.direction[i] = step; // and direction / speed - } - return map; - }; - - algo.rgbMapStepCount = function (width, height) { - // This make no difference to the script ;-) - return 2; - }; - - // Development tool access - testAlgo = algo; - - return algo; - } -)(); diff --git a/resources/rgbscripts/devtool/devtool.js b/resources/rgbscripts/devtool/devtool.js index 8b64bafc8..f71515cd7 100644 --- a/resources/rgbscripts/devtool/devtool.js +++ b/resources/rgbscripts/devtool/devtool.js @@ -526,6 +526,8 @@ devtool.writeFunction = function(functionName, propertyName, value) { window.testAlgo[functionName](value); localStorage.setItem(propertyName, value); + devtool.initPixelColors(); + devtool.initColorValues(); devtool.updateStepCount(); } diff --git a/resources/rgbscripts/empty.js b/resources/rgbscripts/empty.js index 3be222b78..4d7f8f0e5 100644 --- a/resources/rgbscripts/empty.js +++ b/resources/rgbscripts/empty.js @@ -41,7 +41,7 @@ var testAlgo; */ util.getRawColor = function (idx) { var color = 0; - if (Array.isArray(util.colorArray) && util.colorArray.length > idx && ! isNaN(util.colorArray[idx])) { + if (Array.isArray(util.colorArray) && util.colorArray.length > idx && util.colorArray[idx]) { color = util.colorArray[idx]; } return color; diff --git a/resources/rgbscripts/marquee.js b/resources/rgbscripts/marquee.js index 033f0fb3a..0b7d5068b 100644 --- a/resources/rgbscripts/marquee.js +++ b/resources/rgbscripts/marquee.js @@ -21,59 +21,11 @@ var testAlgo; (function () { - var colorPalette = new Object(); - colorPalette.collection = new Array( - ["White" , 0xFFFFFF], - ["LightGrey" , 0xAAAAAA], - ["MediumGrey" , 0x999999], - ["DarkGrey" , 0x666666], - ["Cream" , 0xFFFF7F], - ["Pink" , 0xFF7F7F], - ["Rose" , 0x7F3F3F], - ["Coral" , 0x7F3F1F], - ["Dim Red" , 0x7F0000], - ["Red" , 0xFF0000], - ["Orange" , 0xFF3F00], - ["Dim Orange" , 0x7F1F00], - ["Goldenrod" , 0x7F3F00], - ["Gold" , 0xFF7F00], - ["Yellow" , 0xFFFF00], - ["Dim Yellow" , 0x7F7F00], - ["Lime" , 0x7FFF00], - ["Pale Green" , 0x3F7F00], - ["Dim Green" , 0x007F00], - ["Green" , 0x00FF00], - ["Seafoam" , 0x00FF3F], - ["Turquoise" , 0x007F3F], - ["Teal" , 0x007F7F], - ["Cyan" , 0x00FFFF], - ["Electric Blue", 0x007FFF], - ["Blue" , 0x0000FF], - ["Dim Blue" , 0x00007F], - ["Pale Blue" , 0x1F1F7F], - ["Indigo" , 0x1F00BF], - ["Purple" , 0x3F00BF], - ["Violet" , 0x7F007F], - ["Magenta" , 0xFF00FF], - ["Hot Pink" , 0xFF003F], - ["Deep Pink" , 0x7F001F], - ["Black" , 0x000000] - ); - - colorPalette.makeSubArray = function (_index) { - var _array = new Array(); - for (var i = 0; i < colorPalette.collection.length; i++) { - _array.push(colorPalette.collection[i][_index]); - } - return _array; - }; - colorPalette.names = colorPalette.makeSubArray(0); - var algo = new Object(); - algo.apiVersion = 2; + algo.apiVersion = 3; algo.name = "Marquee"; algo.author = "Branson Matheson"; - algo.acceptColors = 1; + algo.acceptColors = 2; algo.properties = new Array(); algo.edgeDepth = 2; algo.properties.push( @@ -87,14 +39,6 @@ var testAlgo; algo.properties.push( "name:marqueeCount|type:range|display:Marquee Spaces|values:1,100|write:setMarqueeCount|read:getMarqueeCount" ); - algo.marqueeColorIndex = 0; - algo.properties.push( - "name:marqueColor|type:list|display:Marquee Light Color|" + - "values:" + - colorPalette.names.toString() + - "|" + - "write:setMarqueeColorIndex|read:getMarqueeColorIndex" - ); var util = new Object(); util.initialized = false; @@ -102,6 +46,7 @@ var testAlgo; util.height = 0; util.featureColor = 0; util.step = algo.marqueeCount; + util.colorArray = new Array(algo.acceptColors); util.lights = new Array(); util.feature = new Array(); @@ -149,18 +94,32 @@ var testAlgo; return algo.marqueeCount; }; - algo.setMarqueeColorIndex = function (_preset) { - algo.marqueeColorIndex = colorPalette.names.indexOf(_preset); - util.initialized = false; - }; + util.getRawColor = function (idx) { + var color = 0; + if (Array.isArray(util.colorArray) && util.colorArray.length > idx && util.colorArray[idx]) { + color = util.colorArray[idx]; + } + return color; + } + + algo.rgbMapSetColors = function(rawColors) + { + if (! Array.isArray(rawColors)) + return; + for (var i = 0; i < algo.acceptColors; i++) { + if (i < rawColors.length) + { + util.colorArray[i] = rawColors[i]; + } else { + util.colorArray[i] = 0; + } + } + } - algo.getMarqueeColorIndex = function () { - return colorPalette.collection[algo.marqueeColorIndex][0]; - }; - util.initialize = function (width, height, rgb) { + util.initialize = function (width, height) { // initialize feature - util.featureColor = rgb; + util.featureColor = util.getRawColor(0); util.feature = new Array(); var maxDistance = Math.min(width, height) / 2; for (var y = 0; y < height; y++) { @@ -184,6 +143,8 @@ var testAlgo; if (distance <= algo.edgeDepth && distance <= maxDistance) { var percent = ((algo.edgeDepth - distance) / algo.edgeDepth) * 100; util.feature[y][x] = util.fadeColor(util.featureColor, percent); + } else { + util.feature[y][x] = 0; } } } @@ -242,7 +203,7 @@ var testAlgo; } // create light map add lights, go around the outside - var marqueeColor = colorPalette.collection[algo.marqueeColorIndex][1]; + var marqueeColor = util.getRawColor(1); var p = 0; // left for (y = 0; y < height; y++) { @@ -279,14 +240,14 @@ var testAlgo; return map; }; - algo.rgbMap = function (width, height, rgb, step) { + algo.rgbMap = function(width, height, rgb, step) { if ( util.initialized === false || - util.featureColor != rgb || + util.featureColor != util.getRawColor(0) || util.width !== width || util.height !== height ) { - util.initialize(width, height, rgb); + util.initialize(width, height); } var map = util.getNextStep(width, height); diff --git a/resources/rgbscripts/marqueecolorsdirect.js b/resources/rgbscripts/marqueecolorsdirect.js deleted file mode 100644 index fd3c34dc0..000000000 --- a/resources/rgbscripts/marqueecolorsdirect.js +++ /dev/null @@ -1,266 +0,0 @@ -/* - Q Light Controller Plus - marqueecolorsdirect.js - - Copyright (c) Branson Matheson - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0.txt - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Development tool access -var testAlgo; - -(function () { - var algo = new Object(); - algo.apiVersion = 3; - algo.name = "Marquee (2 Colors)"; - algo.author = "Branson Matheson"; - algo.acceptColors = 2; - algo.properties = new Array(); - algo.edgeDepth = 2; - algo.properties.push( - "name:depth|type:range|display:Depth|values:1,10000|write:setDepth|read:getDepth" - ); - algo.marquee = 0; - algo.properties.push( - "name:marquee|type:list|display:Marquee|values:None,Forward,Backward|write:setMarquee|read:getMarquee" - ); - algo.marqueeCount = 3; - algo.properties.push( - "name:marqueeCount|type:range|display:Marquee Spaces|values:1,100|write:setMarqueeCount|read:getMarqueeCount" - ); - - var util = new Object(); - util.initialized = false; - util.width = 0; - util.height = 0; - util.featureColor = 0; - util.step = algo.marqueeCount; - util.colorArray = new Array(algo.acceptColors); - - util.lights = new Array(); - util.feature = new Array(); - - algo.setDepth = function (_amount) { - algo.edgeDepth = parseInt(_amount, 10); - util.initialized = false; - }; - - algo.getDepth = function () { - return algo.edgeDepth; - }; - - algo.setMarquee = function (_marquee) { - if (_marquee === "None") { - algo.marquee = 0; - } - if (_marquee === "Forward") { - algo.marquee = 1; - } - if (_marquee === "Backward") { - algo.marquee = 2; - } - util.initialized = false; - }; - - algo.getMarquee = function () { - if (algo.marquee === 0) { - return "None"; - } - if (algo.marquee === 1) { - return "Forward"; - } - if (algo.marquee === 2) { - return "Backward"; - } - }; - - algo.setMarqueeCount = function (_amount) { - algo.marqueeCount = parseInt(_amount, 10); - util.initialized = false; - }; - - algo.getMarqueeCount = function () { - return algo.marqueeCount; - }; - - util.getRawColor = function (idx) { - var color = 0; - if (Array.isArray(util.colorArray) && util.colorArray.length > idx && ! isNaN(util.colorArray[idx])) { - color = util.colorArray[idx]; - } - return color; - } - - algo.rgbMapSetColors = function(rawColors) - { - if (! Array.isArray(rawColors)) - return; - for (var i = 0; i < algo.acceptColors; i++) { - if (i < rawColors.length) - { - util.colorArray[i] = rawColors[i]; - } else { - util.colorArray[i] = 0; - } - } - } - - - util.initialize = function (width, height) { - // initialize feature - util.featureColor = util.getRawColor(0); - util.feature = new Array(); - var maxDistance = Math.min(width, height) / 2; - for (var y = 0; y < height; y++) { - util.feature[y] = new Array(); - var y_distance = y; - if (y >= height / 2) { - y_distance = height - y - 1; - } - - for (var x = 0; x < width; x++) { - // write color - var distance = algo.edgeDepth + 1; - util.feature[y][x] = 0; - - var x_distance = x; - if (x >= width / 2) { - x_distance = width - x - 1; - } - - distance = Math.min(x_distance, y_distance); - if (distance <= algo.edgeDepth && distance <= maxDistance) { - var percent = ((algo.edgeDepth - distance) / algo.edgeDepth) * 100; - util.feature[y][x] = util.fadeColor(util.featureColor, percent); - } else { - util.feature[y][x] = 0; - } - } - } - - // initialize lights array: 2 heights, 2 widths, 4 duplicate corner pixels - // only if the dimensions have changes (not on color change) - if (util.width != width || util.height != height || util.initialized !== true) { - var length = height * 2 + width * 2 - 4; - util.lights = new Array(length); - var pointAmount = Math.floor(util.lights.length / (algo.marqueeCount + 1)); - var mediumDistance = length / pointAmount; - for (var i = 0; i < util.lights.length; i++) { - if (i % mediumDistance < 1) { - util.lights[i] = 1; - } else { - util.lights[i] = 0; - } - } - } - // for testing for change - util.width = width; - util.height = height; - util.initialized = true; - }; - - util.fadeColor = function (rgb, percent) { - var r = (rgb >> 16) & 0x00ff; - var g = (rgb >> 8) & 0x00ff; - var b = rgb & 0x00ff; - var newR = Math.round(r * (percent / 100)); - var newG = Math.round(g * (percent / 100)); - var newB = Math.round(b * (percent / 100)); - var newRGB = (newR << 16) + (newG << 8) + newB; - return newRGB; - }; - - util.getNextStep = function (width, height) { - var x = 0; - var y = 0; - var map = new Array(height); - for (y = 0; y <= height - 1; y++) { - map[y] = new Array(width); - for (x = 0; x <= width - 1; x++) { - map[y][x] = util.feature[y][x]; - } - } - - if (algo.marquee === 0) { return map } - - if (algo.marquee === 1) { - var first = util.lights.shift(); - util.lights.push(first); - } else if (algo.marquee === 2) { - var last = util.lights.pop(); - util.lights.unshift(last); - } - - // create light map add lights, go around the outside - var marqueeColor = util.getRawColor(1); - var p = 0; - // left - for (y = 0; y < height; y++) { - x = 0; - if (util.lights[p] === 1) { - map[y][x] = marqueeColor; - } - p += 1; - } - // bottom - for (x = 1; x < width; x++) { - y = height - 1; - if (util.lights[p] === 1) { - map[y][x] = marqueeColor; - } - p += 1; - } - // right - for (y = height - 2; y >= 0; y--) { - x = width - 1; - if (util.lights[p] === 1) { - map[y][x] = marqueeColor; - } - p += 1; - } - // top - for (x = width - 2; x >= 0; x--) { - y = 0; - if (util.lights[p] === 1) { - map[y][x] = marqueeColor; - } - p += 1; - } - return map; - }; - - algo.rgbMap = function(width, height, rgb, step) { - if ( - util.initialized === false || - util.featureColor != util.getRawColor(0) || - util.width !== width || - util.height !== height - ) { - util.initialize(width, height); - } - - var map = util.getNextStep(width, height); - return map; - }; - - algo.rgbMapStepCount = function (width, height) { - var size = Number(algo.marqueeCount); - return size - }; - - // Development tool access - testAlgo = algo; - - return algo; -})(); diff --git a/resources/rgbscripts/plasma.js b/resources/rgbscripts/plasma.js index ac9c0f994..7ef8cbccd 100644 --- a/resources/rgbscripts/plasma.js +++ b/resources/rgbscripts/plasma.js @@ -140,7 +140,12 @@ var testAlgo; for (var i = 0; i < util.colorArray.length; i++) { var sColor = util.colorArray[i]; - var eColor = util.colorArray[0]; + var eColor = util.colorArray[(i + 1) % util.colorArray.length]; + if (! sColor) + sColor = 0; + if (! eColor) + eColor = 0; + util.gradientData[gradIdx++] = sColor; var sr = (sColor >> 16) & 0x00FF; var sg = (sColor >> 8) & 0x00FF; @@ -244,6 +249,7 @@ var testAlgo; { return a + t * (b - a); } + // https://en.wikipedia.org/wiki/Gradient function grad(hash, x, y, z) { diff --git a/resources/rgbscripts/plasmacolors.js b/resources/rgbscripts/plasmacolors.js deleted file mode 100644 index 168d7d4c5..000000000 --- a/resources/rgbscripts/plasmacolors.js +++ /dev/null @@ -1,357 +0,0 @@ -/* - Q Light Controller Plus - plasmacolors.js - - Copyright (c) Nathan Durnan - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0.txt - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Development tool access -var testAlgo; - -( -function() -{ - var colorPalette = new Object; - colorPalette.collection = new Array( - ["White" , 0xFFFFFF], // 0 - ["Cream" , 0xFFFF7F], // 1 - ["Pink" , 0xFF7F7F], // 2 - ["Rose" , 0x7F3F3F], // 3 - ["Coral" , 0x7F3F1F], // 4 - ["Dim Red" , 0x7F0000], // 5 - ["Red" , 0xFF0000], // 6 - ["Orange" , 0xFF3F00], // 7 - ["Dim Orange" , 0x7F1F00], // 8 - ["Goldenrod" , 0x7F3F00], // 9 - ["Gold" , 0xFF7F00], // 10 - ["Yellow" , 0xFFFF00], // 11 - ["Dim Yellow" , 0x7F7F00], // 12 - ["Lime" , 0x7FFF00], // 13 - ["Pale Green" , 0x3F7F00], // 14 - ["Dim Green" , 0x007F00], // 15 - ["Green" , 0x00FF00], // 16 - ["Seafoam" , 0x00FF3F], // 17 - ["Turquoise" , 0x007F3F], // 18 - ["Teal" , 0x007F7F], // 19 - ["Cyan" , 0x00FFFF], // 20 - ["Electric Blue", 0x007FFF], // 21 - ["Blue" , 0x0000FF], // 22 - ["Dim Blue" , 0x00007F], // 23 - ["Pale Blue" , 0x1F1F7F], // 24 - ["Indigo" , 0x1F00BF], // 25 - ["Purple" , 0x3F00BF], // 26 - ["Violet" , 0x7F007F], // 27 - ["Magenta" , 0xFF00FF], // 28 - ["Hot Pink" , 0xFF003F], // 29 - ["Deep Pink" , 0x7F001F], // 30 - ["OFF" , 0x000000]); // 31 - - colorPalette.makeSubArray = function(_index) - { - var _array = new Array(); - for (var i = 0; i < colorPalette.collection.length; i++) - { - _array.push(colorPalette.collection[i][_index]); - } - return _array; - }; - colorPalette.names = colorPalette.makeSubArray(0); - - var algo = new Object; - algo.apiVersion = 2; - algo.name = "Plasma (Colors)"; - algo.author = "Nathan Durnan"; - algo.acceptColors = 0; - algo.properties = new Array(); - algo.rstepcount = 0; - algo.gstepcount = 50; - algo.bstepcount = 100; - algo.color1Index = 0; - algo.properties.push( - "name:color1Index|type:list|display:Color 1|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor1|read:getColor1"); - algo.color2Index = 6; - algo.properties.push( - "name:color2Index|type:list|display:Color 2|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor2|read:getColor2"); - algo.color3Index = 16; - algo.properties.push( - "name:color3Index|type:list|display:Color 3|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor3|read:getColor3"); - algo.color4Index = 22; - algo.properties.push( - "name:color4Index|type:list|display:Color 4|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor4|read:getColor4"); - algo.color5Index = 31; - algo.properties.push( - "name:color5Index|type:list|display:Color 5|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor5|read:getColor5"); - algo.presetSize = 5; - algo.properties.push( - "name:presetSize|type:range|display:Size|" + - "values:1,20|write:setSize|read:getSize"); - algo.ramp = 15; - algo.properties.push( - "name:ramp|type:range|display:Ramp|" + - "values:10,30|write:setRamp|read:getRamp"); - algo.stepsize = 25; - algo.properties.push( - "name:stepsize|type:range|display:Speed|" + - "values:1,50|write:setStep|read:getStep"); - algo.colorIndex = new Array( - algo.color1Index, - algo.color2Index, - algo.color3Index, - algo.color4Index, - algo.color5Index); - - var util = new Object; - util.initialized = false; - util.gradientData = new Array(); - util.colorArray = new Array(); - - algo.setColor = function(_index, _preset) - { - var i = colorPalette.names.indexOf(_preset); - if (i === -1) { - i = (colorPalette.collection.length - 1); - } - algo.colorIndex[_index] = i; - return algo.colorIndex[_index]; - }; - - algo.getColor = function(_index) - { - var i = algo.colorIndex[_index]; - if (i < 0) { i = 0; } - if (i >= colorPalette.collection.length) { - i = (colorPalette.collection.length - 1); - } - return colorPalette.collection[i][0]; - }; - - algo.setColor1 = function(_preset) - { - algo.color1Index = algo.setColor(0, _preset); - util.initialize(); - }; - algo.getColor1 = function() - { - return algo.getColor(0); - }; - - algo.setColor2 = function(_preset) - { - algo.color2Index = algo.setColor(1, _preset); - util.initialize(); - }; - algo.getColor2 = function() - { - return algo.getColor(1); - }; - - algo.setColor3 = function(_preset) - { - algo.color3Index = algo.setColor(2, _preset); - util.initialize(); - }; - algo.getColor3 = function() - { - return algo.getColor(2); - }; - - algo.setColor4 = function(_preset) - { - algo.color4Index = algo.setColor(3, _preset); - util.initialize(); - }; - algo.getColor4 = function() - { - return algo.getColor(3); - }; - - algo.setColor5 = function(_preset) - { - algo.color5Index = algo.setColor(4, _preset); - util.initialize(); - }; - algo.getColor5 = function() - { - return algo.getColor(4); - }; - - algo.setSize = function(_size) - { - algo.presetSize = _size; - util.initialize(); - }; - algo.getSize = function() - { - return algo.presetSize; - }; - - algo.setRamp = function(_ramp) - { - algo.ramp = _ramp; - util.initialize(); - }; - algo.getRamp = function() - { - return algo.ramp; - }; - - algo.setStep = function(_step) - { - algo.stepsize = _step; - util.initialize(); - }; - algo.getStep = function() - { - return algo.stepsize; - }; - - util.initialize = function() - { - // calculate the gradient for the selected preset - // with the given width - var gradIdx = 0; - util.gradientData = new Array(); - util.colorArray = new Array(); - for (var j = 0; j < algo.colorIndex.length; j++) - { - util.colorArray[j] = colorPalette.collection[algo.colorIndex[j]][1]; - } - for (var i = 0; i < util.colorArray.length; i++) - { - var sColor = util.colorArray[i]; - var eColor = util.colorArray[i + 1]; - if (eColor == undefined) { - eColor = util.colorArray[0]; - } - util.gradientData[gradIdx++] = sColor; - var sr = (sColor >> 16) & 0x00FF; - var sg = (sColor >> 8) & 0x00FF; - var sb = sColor & 0x00FF; - var er = (eColor >> 16) & 0x00FF; - var eg = (eColor >> 8) & 0x00FF; - var eb = eColor & 0x00FF; - - var stepR = ((er - sr) / 300); - var stepG = ((eg - sg) / 300); - var stepB = ((eb - sb) / 300); - - for (var s = 1; s < 300; s++) - { - var gradR = Math.floor(sr + (stepR * s)) & 0x00FF; - var gradG = Math.floor(sg + (stepG * s)) & 0x00FF; - var gradB = Math.floor(sb + (stepB * s)) & 0x00FF; - var gradRGB = (gradR << 16) + (gradG << 8) + gradB; - util.gradientData[gradIdx++] = gradRGB; - } - } - util.initialized = true; - }; - - function fade(t) { return t * t * t * (t * (t * 6 - 15) + 10); } - function lerp( t, a, b) { return a + t * (b - a); } - function grad(hash, x, y, z) { - var h = hash & 15; // CONVERT LO 4 BITS OF HASH CODE - var u = h<8 ? x : y, // INTO 12 GRADIENT DIRECTIONS. - v = h<4 ? y : h===12||h===14 ? x : z; - return ((h&1) === 0 ? u : -u) + ((h&2) === 0 ? v : -v); - } - function scale(n) { return (1 + n)/2; } - - // This is a port of Ken Perlin's Java code. The - // original Java code is at http://cs.nyu.edu/%7Eperlin/noise/. - // Note that in this version, a number from 0 to 1 is returned. - util.noise = function(x, y, z) - { - var p = new Array(512); - var permutation = [ 151,160,137,91,90,15,131,13,201,95,96,53,194,233, 7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190, 6,148,247,120,234,75, 0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20, 125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229, 122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54, 65,25,63,161,1, 216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100, 109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212, 207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152, 2,44,154, 163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232, 178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,49,192,214, 31,181,199,106,157,184, 84,204,176,115, 121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180]; - - for (var i=0; i < 256 ; i++) { - p[256+i] = p[i] = permutation[i]; - } - var X = Math.floor(x) & 255, // FIND UNIT CUBE THAT - Y = Math.floor(y) & 255, // CONTAINS POINT. - Z = Math.floor(z) & 255; - x -= Math.floor(x); // FIND RELATIVE X,Y,Z - y -= Math.floor(y); // OF POINT IN CUBE. - z -= Math.floor(z); - var u = fade(x), // COMPUTE FADE CURVES - v = fade(y), // FOR EACH OF X,Y,Z. - w = fade(z); - var A = p[X ]+Y, AA = p[A]+Z, AB = p[A+1]+Z, // HASH COORDINATES OF - B = p[X+1]+Y, BA = p[B]+Z, BB = p[B+1]+Z; // THE 8 CUBE CORNERS, - - return scale(lerp(w, lerp(v, lerp(u, grad(p[AA ], x , y , z ), // AND ADD - grad(p[BA ], x-1, y , z )), // BLENDED - lerp(u, grad(p[AB ], x , y-1, z ), // RESULTS - grad(p[BB ], x-1, y-1, z ))), // FROM 8 - lerp(v, lerp(u, grad(p[AA+1], x , y , z-1 ), // CORNERS - grad(p[BA+1], x-1, y , z-1 )), // OF CUBE - lerp(u, grad(p[AB+1], x , y-1, z-1 ), - grad(p[BB+1], x-1, y-1, z-1 ))))); - }; - - algo.rgbMap = function(width, height, rgb, step) - { - if (util.initialized === false) { - util.initialize(); - } - var size = algo.presetSize/2; // set a scaling value - var speed = Math.pow(100 , (algo.stepsize / 50)); // create a more uniform speed control - algo.bstepcount += (speed / 500); - algo.bstepcount = (algo.bstepcount % 256); // A rolling step count for the noise function - var square = width>height ? width : height; // keep the patten square - - var map = new Array(height); - for (var y = 0; y < height; y++) - { - map[y] = new Array(); - - for (var x = 0; x < width; x++) - { - var nx = x / square; // Normalize nx & ny to 0 - 1 - var ny = y / square; - var n = util.noise( size*nx, size*ny, algo.bstepcount); - var gradStep = Math.round( Math.pow(n , (algo.ramp/10)) * util.gradientData.length); - map[y][x] = util.gradientData[gradStep]; - } - } - - return map; - }; - - algo.rgbMapStepCount = function(width, height) - { - if (util.initialized === false) { - util.initialize(); - } - return width * height; // This make no difference to the script ;-) - }; - - // Development tool access - testAlgo = algo; - - return algo; -} -)(); diff --git a/resources/rgbscripts/plasmacolorsdirect.js b/resources/rgbscripts/plasmacolorsdirect.js deleted file mode 100644 index c53fad83f..000000000 --- a/resources/rgbscripts/plasmacolorsdirect.js +++ /dev/null @@ -1,287 +0,0 @@ -/* - Q Light Controller Plus - plasmacolorsdirect.js - - Copyright (c) Nathan Durnan - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0.txt - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Development tool access -var testAlgo; - -( - function() - { - var algo = new Object; - algo.apiVersion = 3; - algo.name = "Plasma (5 Colors)"; - algo.author = "Nathan Durnan"; - algo.acceptColors = 5; - algo.properties = new Array(); - algo.rstepcount = 0; - algo.gstepcount = 50; - algo.bstepcount = 100; - algo.presetSize = 5; - algo.properties.push( - "name:presetSize|type:range|display:Size|" + - "values:1,20|write:setSize|read:getSize"); - algo.ramp = 15; - algo.properties.push( - "name:ramp|type:range|display:Ramp|" + - "values:10,30|write:setRamp|read:getRamp"); - algo.stepsize = 25; - algo.properties.push( - "name:stepsize|type:range|display:Speed|" + - "values:1,50|write:setStep|read:getStep"); - - var util = new Object; - util.initialized = false; - util.gradientData = new Array(); - util.colorArray = new Array(algo.acceptColors); - - algo.setSize = function(_size) - { - algo.presetSize = _size; - util.initialized = false; - }; - - algo.getSize = function() - { - return algo.presetSize; - }; - - algo.setRamp = function(_ramp) - { - algo.ramp = _ramp; - util.initialized = false; - }; - - algo.getRamp = function() - { - return algo.ramp; - }; - - algo.setStep = function(_step) - { - algo.stepsize = _step; - util.initialized = false; - }; - - algo.getStep = function() - { - return algo.stepsize; - }; - - util.getRawColor = function (idx) { - var color = 0; - if (Array.isArray(util.colorArray) && util.colorArray.length > idx && ! isNaN(util.colorArray[idx])) { - color = util.colorArray[idx]; - } - return color; - } - - algo.rgbMapSetColors = function(rawColors) - { - if (! Array.isArray(rawColors)) - return; - for (var i = 0; i < algo.acceptColors; i++) { - if (i < rawColors.length) - { - util.colorArray[i] = rawColors[i]; - } else { - util.colorArray[i] = 0; - } - } - util.initialized = false; - } - - - util.initialize = function() - { - // calculate the gradient for the selected preset - // with the given width - var gradIdx = 0; - util.gradientData = new Array(); - for (var i = 0; i < util.colorArray.length; i++) - { - var sColor = util.colorArray[i]; - var eColor = util.colorArray[0]; - if (i < util.colorArray.length - 1) { - eColor = util.colorArray[i + 1]; - } - util.gradientData[gradIdx++] = sColor; - var sr = (sColor >> 16) & 0x00FF; - var sg = (sColor >> 8) & 0x00FF; - var sb = sColor & 0x00FF; - var er = (eColor >> 16) & 0x00FF; - var eg = (eColor >> 8) & 0x00FF; - var eb = eColor & 0x00FF; - - var stepR = ((er - sr) / 300); - var stepG = ((eg - sg) / 300); - var stepB = ((eb - sb) / 300); - - for (var s = 1; s < 300; s++) - { - var gradR = Math.floor(sr + (stepR * s)) & 0x00FF; - var gradG = Math.floor(sg + (stepG * s)) & 0x00FF; - var gradB = Math.floor(sb + (stepB * s)) & 0x00FF; - var gradRGB = (gradR << 16) + (gradG << 8) + gradB; - util.gradientData[gradIdx++] = gradRGB; - } - } - util.initialized = true; - }; - - // This is a port of Ken Perlin's Java code. The - // original Java code is at http://cs.nyu.edu/%7Eperlin/noise/. - // Note that in this version, a number from 0 to 1 is returned. - util.noise = function(x, y, z) - { - var p = new Array(512); - var permutation = [ // 256 members - 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, - 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, - 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, - 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, - 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, - 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, - 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, - 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, - 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, - 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, - 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, - 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, - 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, - 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, - 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, - 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, - 78, 66, 215, 61, 156, 180 - ]; - - // initialize symmetrical permutation array(512) - for (var i = 0; i < 256; i++) { - p[i] = permutation[i]; - p[256 + i] = permutation[i]; - } - // Find unit cube that contains point. - var X = Math.floor(x) & 255; - var Y = Math.floor(y) & 255; - var Z = Math.floor(z) & 255; - // Find relative x,y,z of point in cube. - x -= Math.floor(x); - y -= Math.floor(y); - z -= Math.floor(z); - // Compute fade curves for each of y, y, z - var u = fade(x); - var v = fade(y); - var w = fade(z); - // Hash coordinates of the 8 cube corners, - var A = p[X] + Y; - var AA = p[A] + Z; - var AB = p[A + 1] + Z; - var B = p[X + 1] + Y; - var BA = p[B] + Z; - var BB = p[B + 1] + Z; - - // And add blended results from8 corners of cube - var rawNoise = lerp(w, - lerp(v, lerp(u, grad(p[AA ], x , y , z ), - grad(p[BA ], x-1, y , z )), - lerp(u, grad(p[AB ], x , y - 1, z ), - grad(p[BB ], x-1, y - 1, z ))), - lerp(v, lerp(u, grad(p[AA + 1], x , y , z - 1), - grad(p[BA + 1], x-1, y , z - 1)), - lerp(u, grad(p[AB + 1], x , y - 1, z - 1), - grad(p[BB + 1], x-1, y - 1, z - 1))) - ); - // Scale to range between 0 and 1 - var noise = scale(rawNoise); - return noise; - }; - // Fade function for values between 0 and 1 - function fade(t) - { - // https://www.geogebra.org/calculator - // f(t)=t^(3) (t (t*6-15)+10) - var fade = t * t * t * (t * (t * 6 - 15) + 10); - return fade; - } - // https://en.wikipedia.org/wiki/Linear_interpolation - function lerp(t, a, b) - { - return a + t * (b - a); - } - // https://en.wikipedia.org/wiki/Gradient - function grad(hash, x, y, z) - { - // CONVERT TO 4 BITS OF HASH CODE - var h = hash & 0x0000000f; - // INTO 12 GRADIENT DIRECTIONS. - var u = (h < 8) ? x : y; - var v = (h < 4) ? y : (h === 12 || h === 14) ? x : z; - return (((h & 1) === 0) ? u : -1 * u) + (((h & 2) === 0) ? v : -1 * v); - } - function scale(n) - { - var scaled = (1 + n) / 2; - return scaled; - } - - algo.rgbMap = function(width, height, rgb, step) - { - if (util.initialized === false) - { - util.initialize(); - } - - // set a scaling value - var size = algo.presetSize / 2; - // create a more uniform speed control - var speed = Math.pow(100, (algo.stepsize / 50)); - algo.bstepcount += (speed / 500); - // A rolling step count for the noise function - algo.bstepcount = (algo.bstepcount % 256); - // keep the patten square - var square = (width > height) ? width : height; - - var map = new Array(height); - for (var y = 0; y < height; y++) - { - map[y] = new Array(); - - for (var x = 0; x < width; x++) - { - var nx = x / square; // Normalize nx & ny to 0 - 1 - var ny = y / square; - var n = util.noise(size * nx, size * ny, algo.bstepcount); - var gradStep = Math.round(Math.pow(n, (algo.ramp / 10)) * util.gradientData.length); - map[y][x] = util.gradientData[gradStep]; - } - } - - return map; - }; - - algo.rgbMapStepCount = function(width, height) - { - return 2; // This make no difference to the script ;-) - }; - - // Development tool access - testAlgo = algo; - - return algo; - } -)(); diff --git a/resources/rgbscripts/rgbscripts.pro b/resources/rgbscripts/rgbscripts.pro index 71190322a..a50c51388 100644 --- a/resources/rgbscripts/rgbscripts.pro +++ b/resources/rgbscripts/rgbscripts.pro @@ -4,10 +4,7 @@ TEMPLATE = subdirs TARGET = scripts scripts.files += alternate.js -scripts.files += alternatecolorsdirect.js scripts.files += balls.js -scripts.files += ballscolors.js -scripts.files += ballscolorsdirect.js scripts.files += blinder.js scripts.files += circles.js scripts.files += circular.js @@ -22,13 +19,10 @@ scripts.files += flyingobjects.js scripts.files += gradient.js scripts.files += lines.js scripts.files += marquee.js -scripts.files += marqueecolorsdirect.js scripts.files += noise.js scripts.files += onebyone.js scripts.files += opposite.js scripts.files += plasma.js -scripts.files += plasmacolors.js -scripts.files += plasmacolorsdirect.js scripts.files += randomcolumn.js scripts.files += randomfillcolumn.js scripts.files += randomfillrow.js