--- /dev/null
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
--- /dev/null
+"use strict";\r
+\r
+/* By Joe Wreschnig\r
+ Placed in the public domain.\r
+\r
+ This code is designed for use with Perlenspiel, by Brian Moriarty,\r
+ which is released under the terms of the GNU LGPL version 3 or\r
+ later.\r
+*/\r
+\r
+var LEVEL_SELECT = 0;\r
+var LEVEL_IN = 1;\r
+var LEVEL_LOST = 2;\r
+var LEVEL_WON = 3;\r
+var GAME_WON = 4;\r
+\r
+var bead_change = [];\r
+var sounds = [];\r
+\r
+var LEVEL_IDX = [\r
+ [7, 8, 9],\r
+ [4, 5, 6],\r
+ [1, 2, 3]\r
+];\r
+\r
+var LEVEL_POS = [\r
+ null,\r
+ [0, 2], [1, 2], [2, 2],\r
+ [0, 1], [1, 1], [2, 1],\r
+ [0, 0], [1, 0], [2, 0]\r
+]; \r
+\r
+var state = LEVEL_SELECT;\r
+\r
+var max_level = 1;\r
+var current_level = 1;\r
+var count = 0;\r
+\r
+function QueueChange(bead, sound) {\r
+ if (sound == null)\r
+ sound = [];\r
+ bead_change.push(bead)\r
+ sounds.push(sound);\r
+}\r
+\r
+function Shuffle(a) {\r
+ for (var i = a.length - 1; i >= 1; --i) {\r
+ var j = PS.Random(i) - 1;\r
+ var tmp = a[j];\r
+ a[j] = a[i];\r
+ a[i] = tmp;\r
+ }\r
+ return a;\r
+}\r
+\r
+function Choose(a) {\r
+ return a[PS.Random(a.length) - 1];\r
+}\r
+\r
+function CheckExact(pos) {\r
+ for (var n = 1; n <= 9; ++n) {\r
+ var x = LEVEL_POS[n][0];\r
+ var y = LEVEL_POS[n][1];\r
+ var on = PS.BeadColor(x, y) != PS.COLOR_WHITE;\r
+ var should = pos.indexOf(n) >= 0;\r
+ if ((on && !should) || (!on && should)) {\r
+ return false;\r
+ }\r
+ }\r
+ return true;\r
+};\r
+\r
+function FollowMeStart(x, y) {\r
+ count = 0;\r
+ PS.BeadColor(PS.Random(3) - 1, PS.Random(3) - 1, PS.COLOR_BLACK);\r
+};\r
+\r
+function FollowMePress(x, y) {\r
+ if (PS.BeadColor(x, y) == PS.COLOR_BLACK) {\r
+ PS.BeadColor(x, y, PS.COLOR_WHITE);\r
+ count++;\r
+ if (count >= 4) {\r
+ Win();\r
+ } else {\r
+ PS.BeadColor(PS.Random(3) - 1, PS.Random(3) - 1, PS.COLOR_BLACK);\r
+ PS.AudioPlay(PS.Xylophone(count == 3 ? 14 : 13), 0.5);\r
+ }\r
+ } else {\r
+ Mistake();\r
+ count = 0;\r
+ }\r
+};\r
+\r
+function EnumerateStart() {\r
+};\r
+\r
+function EnumeratePress(x, y) {\r
+ for (var n = 1; n < LEVEL_IDX[y][x]; ++n) {\r
+ if (PS.BeadColor(LEVEL_POS[n][0], LEVEL_POS[n][1]) != PS.COLOR_BLACK) {\r
+ Mistake();\r
+ return;\r
+ }\r
+ }\r
+ if (PS.BeadColor(x, y) == PS.COLOR_BLACK) {\r
+ Mistake();\r
+ } else {\r
+ PS.BeadColor(x, y, PS.COLOR_BLACK);\r
+ if (LEVEL_IDX[y][x] == 9)\r
+ Win();\r
+ else if (LEVEL_IDX[y][x] == 3)\r
+ PS.AudioPlay(PS.Xylophone(15), 0.5);\r
+ else if (LEVEL_IDX[y][x] == 6)\r
+ PS.AudioPlay(PS.Xylophone(16), 0.5);\r
+ else if (LEVEL_IDX[y][x] > 6)\r
+ PS.AudioPlay(PS.Xylophone(15), 0.5);\r
+ else if (LEVEL_IDX[y][x] > 3)\r
+ PS.AudioPlay(PS.Xylophone(14), 0.5);\r
+ else\r
+ PS.AudioPlay(PS.Xylophone(13), 0.5);\r
+ }\r
+};\r
+\r
+var repeatorder = [];\r
+function RepeatStart() {\r
+ PS.Clock(45);\r
+ repeatorder = Shuffle([1, 2, 3, 4, 5, 6, 7, 8, 9]).slice(0, 6);\r
+ for (var n = 0; n < repeatorder.length; ++n) {\r
+ QueueChange([[PS.COLOR_BLACK, repeatorder[n]]],\r
+ [PS.Xylophone(2 + n)]);\r
+ }\r
+};\r
+\r
+function RepeatPress(x, y) {\r
+ var n = repeatorder.shift();\r
+ if (LEVEL_IDX[y][x] == n) {\r
+ PS.BeadColor(x, y, PS.COLOR_GREEN);\r
+ if (repeatorder.length == 0) {\r
+ Win();\r
+ } else {\r
+ PS.AudioPlay(PS.Xylophone(9 + repeatorder.length), 0.5);\r
+ PS.AudioPlay(PS.Xylophone(9 + repeatorder.length), 0.5);\r
+ }\r
+ } else {\r
+ Mistake();\r
+ }\r
+};\r
+\r
+var missing_valid = [];\r
+function TickMissingStart() {\r
+ PS.Clock(45);\r
+ var d = {};\r
+ missing_valid = [];\r
+ repeatorder = Shuffle([1, 2, 3, 4, 5, 6, 7, 8, 9]).slice(0, 6);\r
+ repeatorder = Shuffle(repeatorder.concat(repeatorder));\r
+ for (var n = 0; n < repeatorder.length; ++n) {\r
+ if (d[repeatorder[n]]) {\r
+ QueueChange([[PS.COLOR_WHITE, repeatorder[n]]],\r
+ [PS.Xylophone(15 - n)]);\r
+ } else {\r
+ d[repeatorder[n]] = true;\r
+ QueueChange([[PS.COLOR_RED, repeatorder[n]]],\r
+ [PS.Xylophone(13 + n)]);\r
+ }\r
+ }\r
+ for (var n = 1; n <= 9; ++n)\r
+ if (repeatorder.indexOf(n) < 0)\r
+ missing_valid.push(n);\r
+ count = 0;\r
+};\r
+\r
+function TickMissingPress(x, y) {\r
+ if (missing_valid.indexOf(LEVEL_IDX[y][x]) < 0) {\r
+ Mistake();\r
+ } else {\r
+ PS.BeadColor(x, y, PS.COLOR_BLACK);\r
+ if (CheckExact(missing_valid)) {\r
+ Win();\r
+ } else {\r
+ count++;\r
+ PS.AudioPlay(PS.Xylophone(count == 2 ? 14 : 13), 0.5);\r
+ }\r
+ }\r
+};\r
+\r
+var third_row;\r
+\r
+function ThreeRowGenerate() {\r
+ third_row = Shuffle(Choose([\r
+ [1, 2, 3], [4, 5, 6], [7, 8, 9],\r
+ [1, 4, 7], [2, 5, 8], [3, 6, 9],\r
+ [1, 5, 9], [3, 5, 7]]));\r
+ QueueChange([[PS.COLOR_BLACK, third_row[0]]], [PS.Xylophone(13)]);\r
+ QueueChange([[PS.COLOR_BLACK, third_row[1]]], [PS.Xylophone(13)]);\r
+}\r
+\r
+function ThreeRowStart() {\r
+ count = 0;\r
+ PS.Clock(45);\r
+ ThreeRowGenerate();\r
+};\r
+\r
+function ThreeRowPress(x, y) {\r
+ if (LEVEL_IDX[y][x] == third_row[2]) {\r
+ count++;\r
+ PS.BeadColor(x, y, PS.COLOR_BLACK);\r
+ PS.Clock(PS.Clock());\r
+ if (count >= 3) {\r
+ Win();\r
+ } else {\r
+ PS.AudioPlay(PS.Xylophone(14), 0.5);\r
+ QueueChange([[PS.COLOR_GREEN, third_row[2]],\r
+ [PS.COLOR_GREEN, third_row[1]],\r
+ [PS.COLOR_GREEN, third_row[0]]],\r
+ [PS.Xylophone(34)]);\r
+ QueueChange([[PS.COLOR_WHITE, third_row[2]],\r
+ [PS.COLOR_WHITE, third_row[1]],\r
+ [PS.COLOR_WHITE, third_row[0]]]);\r
+ ThreeRowGenerate();\r
+ }\r
+ } else {\r
+ count = 0;\r
+ Mistake();\r
+ }\r
+};\r
+\r
+var sudoku_row;\r
+function SudokuRowGenerate() {\r
+ sudoku_row = Shuffle(Choose([[1, 8, 6], [4, 8, 3], [4, 2, 9], [7, 2, 6]]));\r
+ QueueChange([[PS.COLOR_RED, sudoku_row[0]]],\r
+ [PS.Xylophone(3)]);\r
+ QueueChange([[PS.COLOR_RED, sudoku_row[1]]],\r
+ [PS.Xylophone(2)]);\r
+};\r
+\r
+function SudokuStart() {\r
+ count = 0;\r
+ PS.Clock(45);\r
+ SudokuRowGenerate();\r
+}\r
+\r
+function SudokuPress(x, y) {\r
+ if (LEVEL_IDX[y][x] == sudoku_row[2]) {\r
+ count++;\r
+ PS.BeadColor(x, y, PS.COLOR_BLACK);\r
+ if (count >= 3) {\r
+ Win();\r
+ } else {\r
+ PS.AudioPlay(PS.Xylophone(13), 0.5);\r
+ QueueChange([[PS.COLOR_GREEN, sudoku_row[2]],\r
+ [PS.COLOR_GREEN, sudoku_row[1]],\r
+ [PS.COLOR_GREEN, sudoku_row[0]]],\r
+ [PS.Xylophone(14)]);\r
+ QueueChange([[PS.COLOR_WHITE, sudoku_row[2]],\r
+ [PS.COLOR_WHITE, sudoku_row[1]],\r
+ [PS.COLOR_WHITE, sudoku_row[0]]]);\r
+ SudokuRowGenerate();\r
+ }\r
+ } else {\r
+ count = 0;\r
+ Mistake();\r
+ }\r
+};\r
+\r
+function DigitsStart() {\r
+ PS.Clock(40);\r
+ QueueChange([[PS.COLOR_BLACK, 1]], ["perc_hihat_closed"]);\r
+ QueueChange([[PS.COLOR_WHITE, 1],\r
+ [PS.COLOR_BLACK, 4]], ["perc_hihat_closed"]);\r
+ QueueChange([[PS.COLOR_WHITE, 4],\r
+ [PS.COLOR_BLACK, 7]], ["perc_hihat_closed"]);\r
+ QueueChange([[PS.COLOR_WHITE, 7]]);\r
+ QueueChange([]);\r
+ QueueChange([[PS.COLOR_BLACK, 2],\r
+ [PS.COLOR_BLACK, 5],\r
+ [PS.COLOR_BLACK, 8]],\r
+ [PS.Xylophone(13)]);\r
+ QueueChange([[PS.COLOR_GREEN, 2],\r
+ [PS.COLOR_GREEN, 5],\r
+ [PS.COLOR_GREEN, 8]],\r
+ [PS.Xylophone(14)]);\r
+ QueueChange([[PS.COLOR_WHITE, 2],\r
+ [PS.COLOR_WHITE, 5],\r
+ [PS.COLOR_WHITE, 8]]);\r
+ count = 4;\r
+};\r
+\r
+function DigitsPress(x, y) {\r
+ if (PS.BeadColor(x, y) == PS.COLOR_WHITE) {\r
+ PS.BeadColor(x, y, PS.COLOR_BLACK);\r
+ } else {\r
+ PS.BeadColor(x, y, PS.COLOR_WHITE);\r
+ }\r
+\r
+ if (count == 4 && ApproveIfExact([7, 9, 4, 5, 6, 3]))\r
+ count = 7;\r
+ if (count == 7 && (CheckExact([7, 8, 9, 6, 3])\r
+ || CheckExact([7, 8, 9, 6, 2]))) {\r
+ Win();\r
+ return;\r
+ }\r
+\r
+ if (PS.BeadColor(x, y) == PS.COLOR_WHITE) {\r
+ PS.AudioPlay(PS.Xylophone(10), 0.5);\r
+ } else {\r
+ PS.AudioPlay(PS.Xylophone(13), 0.3);\r
+ }\r
+\r
+};\r
+\r
+function ShapesStart() {\r
+ PS.Clock(40);\r
+ QueueChange([[PS.COLOR_BLACK, 1]], [PS.Xylophone(13)]);\r
+ QueueChange([[PS.COLOR_GREEN, 1]], [PS.Xylophone(14)]);\r
+ QueueChange([[PS.COLOR_BLACK, 1]]);\r
+ QueueChange([[PS.COLOR_BLACK, 4]], [PS.Xylophone(13)]);\r
+ QueueChange([[PS.COLOR_BLACK, 7]], [PS.Xylophone(13)]);\r
+\r
+ QueueChange([[PS.COLOR_GREEN, 1],\r
+ [PS.COLOR_GREEN, 4],\r
+ [PS.COLOR_GREEN, 7]],\r
+ [PS.Xylophone(14)]);\r
+ QueueChange([[PS.COLOR_BLACK, 1],\r
+ [PS.COLOR_BLACK, 4],\r
+ [PS.COLOR_BLACK, 7]]);\r
+ count = 3;\r
+};\r
+\r
+function ShapesPress(x, y) {\r
+ if (PS.BeadColor(x, y) == PS.COLOR_WHITE) {\r
+ PS.BeadColor(x, y, PS.COLOR_BLACK);\r
+ } else {\r
+ PS.BeadColor(x, y, PS.COLOR_WHITE);\r
+ }\r
+\r
+ if (count == 3 && (ApproveIfExact([1, 4, 7, 2, 5, 3], PS.COLOR_BLACK)\r
+ || ApproveIfExact([1, 4, 7, 8, 5, 3], PS.COLOR_BLACK))) {\r
+ count = 4;\r
+ if (PS.BeadColor(x, y) == PS.COLOR_WHITE)\r
+ PS.AudioPlay(PS.Xylophone(10), 0.3);\r
+ else\r
+ PS.AudioPlay(PS.Xylophone(13), 0.5);\r
+ } else if (count == 4 && CheckExact([1, 2, 3, 4, 5, 6, 7, 8, 9]))\r
+ Win();\r
+ else {\r
+ if (PS.BeadColor(x, y) == PS.COLOR_WHITE)\r
+ PS.AudioPlay(PS.Xylophone(10), 0.3);\r
+ else\r
+ PS.AudioPlay(PS.Xylophone(13), 0.5);\r
+ }\r
+};\r
+\r
+function DieStart() {\r
+ PS.Clock(40);\r
+ QueueChange([[PS.COLOR_BLACK, 5]], [PS.Xylophone(13)]);\r
+ QueueChange([[PS.COLOR_GREEN, 5]], [PS.Xylophone(14)]);\r
+ QueueChange([[PS.COLOR_WHITE, 5]]);\r
+ QueueChange([[PS.COLOR_BLACK, 1]], [PS.Xylophone(13)]);\r
+ QueueChange([[PS.COLOR_BLACK, 9]], [PS.Xylophone(13)]);\r
+ QueueChange([[PS.COLOR_GREEN, 1],\r
+ [PS.COLOR_GREEN, 9]], [PS.Xylophone(14)]);\r
+ QueueChange([[PS.COLOR_WHITE, 1],\r
+ [PS.COLOR_WHITE, 9]]);\r
+ count = 3;\r
+};\r
+\r
+function ApproveIfExact(a, color) {\r
+ if (color == null)\r
+ color = PS.COLOR_WHITE;\r
+ if (CheckExact(a)) {\r
+ var green = [];\r
+ var white = [];\r
+ for (var n = 0; n < a.length; ++n) {\r
+ green.push([PS.COLOR_GREEN, a[n]]);\r
+ white.push([color, a[n]]);\r
+ }\r
+ QueueChange(green, [PS.Xylophone(14)]);\r
+ QueueChange(white);\r
+ PS.Clock(PS.Clock());\r
+ if (PS.StatusText() != "…")\r
+ PS.StatusText("…");\r
+ return true;\r
+ } else {\r
+ return false;\r
+ }\r
+};\r
+\r
+function DiePress(x, y) {\r
+ if (PS.BeadColor(x, y) == PS.COLOR_WHITE) {\r
+ PS.BeadColor(x, y, PS.COLOR_BLACK);\r
+ } else {\r
+ PS.BeadColor(x, y, PS.COLOR_WHITE);\r
+ }\r
+ switch (count) {\r
+ case 3:\r
+ if (ApproveIfExact([1, 5, 9]) || ApproveIfExact([7, 5, 3]))\r
+ count = 4;\r
+ break;\r
+ case 4:\r
+ if (ApproveIfExact([1, 3, 7, 9]))\r
+ count = 5;\r
+ break;\r
+ case 5:\r
+ if (ApproveIfExact([1, 3, 5, 7, 9]))\r
+ count = 6;\r
+ break;\r
+ case 6:\r
+ if (CheckExact([1, 2, 3, 7, 8, 9])\r
+ || CheckExact([1, 4, 7, 3, 6, 9])) {\r
+ Win();\r
+ return;\r
+ }\r
+ }\r
+\r
+ if (PS.BeadColor(x, y) == PS.COLOR_WHITE) {\r
+ PS.AudioPlay(PS.Xylophone(14), 0.5);\r
+ } else {\r
+ PS.AudioPlay(PS.Xylophone(13), 0.3);\r
+ }\r
+};\r
+\r
+var LEVELS = [\r
+ null,\r
+ [FollowMeStart, FollowMePress],\r
+ [ThreeRowStart, ThreeRowPress],\r
+ [EnumerateStart, EnumeratePress],\r
+ [RepeatStart, RepeatPress],\r
+ [TickMissingStart, TickMissingPress],\r
+ [SudokuStart, SudokuPress],\r
+ [ShapesStart, ShapesPress],\r
+ [DieStart, DiePress],\r
+ [DigitsStart, DigitsPress],\r
+];\r
+\r
+function Reset(color) {\r
+ if (max_level < 10 && PS.StatusText() != "?")\r
+ PS.StatusText("?");\r
+ if (max_level == 10 && PS.StatusText() != ".")\r
+ PS.StatusText(".");\r
+\r
+ PS.Clock(0);\r
+ bead_change = [];\r
+ PS.BeadColor(PS.ALL, PS.ALL, color);\r
+}\r
+\r
+function Win() {\r
+ Reset(PS.COLOR_GREEN);\r
+ state = LEVEL_WON;\r
+ current_level += 1;\r
+ if (max_level < current_level) {\r
+ max_level = current_level;\r
+ if (max_level == 10) {\r
+ setTimeout(function() {\r
+ PS.AudioPlay(PS.Xylophone(25), 0.5)\r
+ }, 0);\r
+ setTimeout(function() {\r
+ PS.AudioPlay(PS.Xylophone(30), 0.5)\r
+ }, 500);\r
+ setTimeout(function() {\r
+ PS.AudioPlay(PS.Xylophone(30), 0.5)\r
+ }, 600);\r
+ setTimeout(function() {\r
+ PS.AudioPlay(PS.Xylophone(31), 0.5)\r
+ }, 1000);\r
+ setTimeout(function() {\r
+ PS.AudioPlay(PS.Xylophone(37), 0.5)\r
+ }, 1300);\r
+ } else {\r
+ PS.AudioPlay(PS.Xylophone(34), 0.5);\r
+ PS.AudioPlay(PS.Xylophone(38), 0.5);\r
+ PS.AudioPlay(PS.Xylophone(39), 0.5);\r
+ }\r
+ } else {\r
+ PS.AudioPlay(PS.Xylophone(34), 0.5);\r
+ PS.AudioPlay(PS.Xylophone(38), 0.5);\r
+ PS.AudioPlay(PS.Xylophone(39), 0.5);\r
+ }\r
+};\r
+\r
+function Mistake() {\r
+ Reset(PS.COLOR_RED);\r
+ PS.AudioPlay(PS.Xylophone(2), 0.5);\r
+ PS.AudioPlay(PS.Xylophone(8), 0.5);\r
+ PS.AudioPlay(PS.Xylophone(22), 0.5);\r
+ PS.StatusText("X");\r
+ state = LEVEL_LOST;\r
+};\r
+\r
+PS.Init = function (options) {\r
+ var path = window.location.href;\r
+ PS.AudioPath(path.substr(0, path.lastIndexOf("/")) + "/audio/");\r
+ PS.GridSize(3, 3);\r
+ LevelSelect();\r
+ PS.StatusText("?");\r
+ for (var i = 1; i < 39; ++i)\r
+ PS.AudioLoad(PS.Xylophone(i));\r
+ PS.AudioLoad("perc_hihat_closed");\r
+};\r
+\r
+function StartLevel(level) {\r
+ if (level > max_level)\r
+ return;\r
+ PS.AudioPlay(PS.Xylophone(1), 0.5);\r
+ Reset(PS.COLOR_WHITE);\r
+ current_level = level;\r
+ LEVELS[current_level][0]();\r
+ state = LEVEL_IN;\r
+};\r
+\r
+function LevelSelect() {\r
+ Reset(PS.COLOR_WHITE);\r
+ for (var n = 1; n <= 9; ++n) {\r
+ var x = LEVEL_POS[n][0];\r
+ var y = LEVEL_POS[n][1];\r
+ if (n == max_level)\r
+ PS.BeadColor(x, y, PS.COLOR_VIOLET);\r
+ else if (n < max_level)\r
+ PS.BeadColor(x, y, PS.COLOR_BLUE);\r
+ }\r
+ if (max_level == 10)\r
+ PS.BeadColor(PS.ALL, PS.ALL, PS.COLOR_BLUE);\r
+ state = LEVEL_SELECT;\r
+};\r
+\r
+PS.Click = function (x, y, data, options) {\r
+ if (PS.Clock() > 0 && bead_change.length)\r
+ return;\r
+ switch (state) {\r
+ case LEVEL_SELECT:\r
+ StartLevel(LEVEL_IDX[y][x]);\r
+ break;\r
+ case LEVEL_IN:\r
+ LEVELS[current_level][1](x, y);\r
+ break;\r
+ case LEVEL_WON:\r
+ LevelSelect();\r
+ break;\r
+ case LEVEL_LOST:\r
+ StartLevel(current_level);\r
+ break;\r
+ case GAME_WON:\r
+ break;\r
+ }\r
+};\r
+\r
+PS.Release = function (x, y, data, options) {\r
+};\r
+\r
+PS.Enter = function (x, y, data, options) {\r
+ if (state == LEVEL_SELECT && PS.BeadColor(x, y) != PS.COLOR_WHITE) {\r
+ PS.AudioPlay( "fx_click" , 0.5);\r
+ }\r
+};\r
+\r
+PS.Leave = function (x, y, data, options) {\r
+};\r
+\r
+PS.KeyDown = function (key, shift, ctrl, options) {\r
+ if (ctrl && key == 32) {\r
+ Win();\r
+ LevelSelect();\r
+ }\r
+ switch (key) {\r
+ case PS.KEYPAD_1: case 49: PS.Click(0, 2); break;\r
+ case PS.KEYPAD_2: case 50: PS.Click(1, 2); break;\r
+ case PS.KEYPAD_3: case 51: PS.Click(2, 2); break;\r
+ case PS.KEYPAD_4: case 52: PS.Click(0, 1); break;\r
+ case PS.KEYPAD_5: case 53: PS.Click(1, 1); break;\r
+ case PS.KEYPAD_6: case 54: PS.Click(2, 1); break;\r
+ case PS.KEYPAD_7: case 55: PS.Click(0, 0); break;\r
+ case PS.KEYPAD_8: case 56: PS.Click(1, 0); break;\r
+ case PS.KEYPAD_9: case 57: PS.Click(2, 0); break;\r
+ case PS.KEY_ESCAPE: LevelSelect(); break;\r
+ }\r
+};\r
+\r
+PS.KeyUp = function (key, shift, ctrl, options) {\r
+};\r
+\r
+PS.Wheel = function (dir, options) {\r
+};\r
+\r
+PS.Tick = function (options) {\r
+ var beads = bead_change.shift();\r
+ if (beads) {\r
+ if (PS.StatusText() != "…")\r
+ PS.StatusText("…");\r
+ for (var n = 0; n < beads.length; ++n) {\r
+ var bead = beads[n];\r
+ var x = LEVEL_POS[bead[1]][0];\r
+ var y = LEVEL_POS[bead[1]][1];\r
+ PS.BeadColor(x, y, bead[0]);\r
+ }\r
+ }\r
+\r
+ var sound = sounds.shift();\r
+ if (sound) {\r
+ for (var n = 0; n < sound.length; ++n) {\r
+ PS.AudioPlay(sound[n], 0.5);\r
+ }\r
+ }\r
+\r
+ if (bead_change.length == 0 && PS.StatusText() != "?")\r
+ PS.StatusText("?");\r
+};\r
--- /dev/null
+<!DOCTYPE HTML>
+<html lang="en">
+ <head>
+ <title>123456789 - a game for Ludum Dare 26</title>
+ <meta charset="utf-8" />
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
+ <meta name="description" content="123456789, a small puzzle game written for the Ludum Dare 26 game-making challenge." />
+ <meta name="author" content="Joe Wreschnig" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <link rel="stylesheet" type="text/css" href="ps2.3.css">
+ <script type="text/javascript" src="ps2.3.js"></script>
+ </head>
+ <body onload="PS.Sys(); if (('ontouchstart' in window) || window.navigator.msMaxTouchPoints > 0) { document.getElementById('restart').style.display = 'block'; }">
+ <script type="text/javascript" src="game.js"></script>
+ <div id="restart" style="position: absolute; left: 0; bottom: 1em; width: 100%; text-align: center; display: none;">
+ <button onClick="LevelSelect();" style="width: 20%;">Restart</button>
+ </div>
+ </body>
+</html>
--- /dev/null
+/*\r
+Perlenspiel is a scheme by Professor Moriarty (bmoriarty@wpi.edu).\r
+Perlenspiel is Copyright © 2009-12 Worcester Polytechnic Institute.\r
+This file is part of Perlenspiel.\r
+\r
+Perlenspiel is free software: you can redistribute it and/or modify\r
+it under the terms of the GNU Lesser General Public License as published\r
+by the Free Software Foundation, either version 3 of the License, or\r
+(at your option) any later version.\r
+\r
+Perlenspiel is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+GNU Lesser General Public License for more details.\r
+\r
+You may have received a copy of the GNU Lesser General Public License\r
+along with Perlenspiel. If not, see <http://www.gnu.org/licenses/>.\r
+*/\r
+\r
+body\r
+{\r
+ color: #000000;\r
+ background-color: #FFFFFF;\r
+ width: 512px;\r
+ margin: 0 auto;\r
+ font-family: Arial, Helvetica, sans-serif;\r
+}\r
+\r
+#main\r
+{\r
+ -webkit-user-select: none;\r
+ -khtml-user-select: none;\r
+ -moz-user-select: none;\r
+ -o-user-select: none;\r
+ user-select: none; \r
+}\r
+\r
+#sts\r
+{\r
+ width: 480px;\r
+ font-size: 18pt;\r
+ text-align: center;\r
+ border: 0;\r
+ margin-top: 32px;\r
+ margin-bottom: 16px;\r
+}\r
+\r
+#dbg\r
+{\r
+ display: none;\r
+}\r
+\r
+#mon\r
+{\r
+ text-align: left;\r
+}\r
+\r
+#ftr\r
+{\r
+ color: #000000;\r
+ width: 480px;\r
+ font-size: 9pt;\r
+ text-align: center;\r
+}\r
--- /dev/null
+(function(){var a,b,c,d;a=0;b=["ms","moz","webkit","o"];for(c=0;c<(b.length&&!window.requestAnimationFrame);c+=1){d=b[c];window.requestAnimationFrame=window[d+"RequestAnimationFrame"];window.cancelAnimationFrame=window[d+"CancelAnimationFrame"]||window[d+"CancelRequestAnimationFrame"];}if(!window.requestAnimationFrame){window.requestAnimationFrame=function(f,h){var g,i,j;g=new Date().getTime();i=Math.max(0,16-(g-a));j=window.setTimeout(function(){f(g+i);},i);a=g+i;return j;};}if(!window.cancelAnimationFrame){window.cancelAnimationFrame=function(e){window.clearTimeout(e);};}}());var PS={ERROR:"ERROR",DEFAULT:"DEFAULT",CURRENT:"CURRENT",ALL:"ALL",EMPTY:"EMPTY",CVS_W:480,MAIN_ID:"mn",STS_ID:"sts",CVS_ID:"cvs",FTR_ID:"ftr",DBG_ID:"dbg",MON_ID:"mon",G_MAX:32,D_G_W:8,D_G_H:8,D_B_RGB:0,D_B_R:0,D_B_G:0,D_B_B:0,D_BG_RGB:16777215,D_BG_R:255,D_BG_G:255,D_BG_B:255,D_BDR_RGB:8421504,D_BDR_R:128,D_BDR_G:128,D_BDR_B:128,D_BDR_W:1,D_GL_RGB:16777215,D_GL_R:255,D_GL_G:255,D_GL_B:255,D_FL_RGB:16777215,D_FL_R:255,D_FL_G:255,D_FL_B:255,D_ALPHA:100,D_FPS:17,RSHIFT:256*256,GSHIFT:256,FL_STEP:10,FL_INTERVAL:5,KEY_RATE:6,APP:"Perlenspiel",D_ST_RGB:0,D_ST_R:0,D_ST_G:0,D_ST_B:0,D_AUDIO_PATH:"http://users.wpi.edu/~bmoriarty/ps/audio/",MAX_VOL:1,D_VOL:0.5,D_LOOP:false,AudioCurrentPath:"",AUDIO_MAX_CH:32,CH_EMPTY:0,CH_LOADING:1,CH_READY:2,CH_PLAYING:3,CH_PAUSED:4,AudioChannels:[],ChannelsUsed:0,AudioContext:null,COLOR_BLACK:0,COLOR_WHITE:16777215,COLOR_GRAY_LIGHT:12632256,COLOR_GRAY:8421504,COLOR_GRAY_DARK:4210752,COLOR_RED:16711680,COLOR_ORANGE:16744448,COLOR_YELLOW:16776960,COLOR_GREEN:65280,COLOR_BLUE:255,COLOR_INDIGO:4194559,COLOR_VIOLET:8388863,COLOR_MAGENTA:16711935,COLOR_CYAN:65535,KEY_TAB:9,KEY_ESCAPE:27,KEY_PAGE_UP:1001,KEY_PAGE_DOWN:1002,KEY_END:1003,KEY_HOME:1004,ARROW_LEFT:1005,ARROW_UP:1006,ARROW_RIGHT:1007,ARROW_DOWN:1008,KEY_INSERT:1009,KEY_DELETE:1010,KEYPAD_0:96,KEYPAD_1:97,KEYPAD_2:98,KEYPAD_3:99,KEYPAD_4:100,KEYPAD_5:101,KEYPAD_6:102,KEYPAD_7:103,KEYPAD_8:104,KEYPAD_9:105,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,FORWARD:1,BACKWARD:-1,Grid:null,DebugWindow:null,ImageCanvas:null,BlitCanvas:null,BlitContext:null,LoaderList:[],LoaderCnt:0,MouseX:-1,MouseY:-1,LastX:-1,LastY:-1,Pressed:[],Holding:[],KeyDelay:0,HoldShift:false,HoldCtrl:false,OverCanvas:false,DebugFocus:false,FlashDelay:0,UserDelay:0,UserClock:0,FooterColor:0,FooterDelay:300,D_ST_STEP_UP:5,D_ST_STEP_DOWN:5,Status:"",StatusHue:0,StatusRed:0,StatusGreen:0,StatusBlue:0,STS_FPS:12,STS_REG:5,D_STS_UP:60,D_STS_DOWN:60,D_STS_DELAY:120,StatusUp:true,StatusUpRate:60,StatusUpDelay:5,StatusUpStep:0,StatusUpPhase:0,StatusDown:false,StatusDownRate:0,StatusDownDelay:5,StatusDownStep:0,StatusDownPhase:0,StatusDelayRate:120,StatusDelay:0,Init:null,Click:null,Release:null,Enter:null,Leave:null,KeyDown:null,KeyUp:null,Wheel:null,Tick:null,MAJ:2,MIN:3,REV:9};PS.TypeOf=function(b){var a;a=typeof b;if(a==="object"){if(b){if(b instanceof Array){a="array";}}else{a="null";}}return a;};PS.Context=function(){var b,a;a=null;b=document.getElementById(PS.CVS_ID);if(b&&b.getContext){a=b.getContext("2d");}return a;};PS.ValidRGB=function(a,b){if(typeof a!=="number"){PS.Oops(b+"rgb parameter not a number");return -1;}a=Math.floor(a);if(a<0){PS.Oops(b+"rgb parameter negative");return -1;}if(a>16777215){PS.Oops(b+"rgb parameter out of range");return -1;}return a;};PS.UnmakeRGB=function(b){var c,g,d,a,f,e;c="[PS.UnmakeRGB] ";if(typeof b!=="number"){return PS.Oops(c+"RGB parameter not a number");}b=Math.floor(b);if(b<0){return PS.Oops(c+"RGB parameter negative");}if(b>16777215){return PS.Oops(c+"RGB parameter out of range");}g=b/PS.RSHIFT;g=Math.floor(g);f=g*PS.RSHIFT;d=(b-f)/PS.GSHIFT;d=Math.floor(d);e=d*PS.GSHIFT;a=b-f-e;return{r:g,g:d,b:a};};PS.ColorParams=function(k,j,h,l){var a,i,c,m,e,f,d;a=false;i=PS.TypeOf(j);if(i==="number"){if(h===undefined){if((j<0)||(j>16777215)){PS.Oops(k+"multiplexed rgb value out of range");return null;}j=Math.floor(j);c=j/PS.RSHIFT;c=Math.floor(c);f=c*PS.RSHIFT;e=(j-f)/PS.GSHIFT;e=Math.floor(e);d=e*PS.GSHIFT;m=j-f-d;a=true;}else{c=j;e=h;m=l;if(m===undefined){PS.Oops(k+"b parameter missing in rgb triplet");return null;}}}else{if(i==="object"){c=j.r;if(c===undefined){PS.Oops(k+"r element missing in rgb table");return null;}e=j.g;if(e===undefined){PS.Oops(k+"g element missing in rgb table");return null;}m=j.b;if(m===undefined){PS.Oops(k+"b element missing in rgb table");return null;}}else{if(i==="array"){if(j.length<3){PS.Oops(k+"rgb array length invalid");return null;}c=j[0];e=j[1];m=j[2];}else{PS.Oops(k+"Invalid color parameter");return null;}}}if(!a){if(typeof c!=="number"){PS.Oops(k+"red value is not a number");return null;}c=Math.floor(c);if((c<0)&&(c>255)){PS.Oops(k+"red value out of range ["+c+"]");return null;}if(typeof e!=="number"){PS.Oops(k+"green value is not a number");return null;}e=Math.floor(e);if((e<0)&&(e>255)){PS.Oops(k+"green value out of range ["+e+"]");return null;}if(typeof m!=="number"){PS.Oops(k+"blue value is not a number");return null;}m=Math.floor(m);if((m<0)&&(m>255)){PS.Oops(k+"blue value out of range ["+m+"]");return null;}}return{r:c,g:e,b:m};};PS.Dissolve=function(c,b,a){var d;if((a<=0)||(c===b)){return c;}if(a>=100){return b;}if(c>b){d=c-b;d=(a*d)/100;d=Math.floor(d);return(c-d);}d=b-c;d=(a*d)/100;d=Math.floor(d);return(c+d);};PS.InitBead=function(c,e,d,b){var a;a={};a.left=c;a.right=c+d;a.top=e;a.bottom=e+d;a.size=d;a.visible=true;a.empty=true;a.red=PS.D_B_R;a.green=PS.D_B_G;a.blue=PS.D_B_B;a.color="rgb("+a.red+","+a.green+","+a.blue+")";a.colorNow=a.color;a.alpha=PS.D_ALPHA;a.alphaRed=PS.D_B_R;a.alphaGreen=PS.D_B_G;a.alphaBlue=PS.D_B_B;a.glyph=0;a.glyphStr="";a.glyphRed=PS.D_GL_R;a.glyphGreen=PS.D_GL_G;a.glyphBlue=PS.D_GL_B;a.glyphColor="rgb("+PS.D_GL_R+","+PS.D_GL_G+","+PS.D_GL_B+")";a.flash=true;a.flashPhase=0;a.flashRed=PS.D_FL_R;a.flashGreen=PS.D_FL_G;a.flashBlue=PS.D_FL_B;a.flashColor="rgb("+PS.D_FL_R+","+PS.D_FL_G+","+PS.D_FL_B+")";a.borderWidth=PS.D_BDR_W;a.borderRed=PS.D_BDR_R;a.borderGreen=PS.D_BDR_G;a.borderBlue=PS.D_BDR_B;a.borderAlpha=PS.D_ALPHA;a.borderColor="rgb("+PS.D_BDR_R+","+PS.D_BDR_G+","+PS.D_BDR_B+")";a.data=0;a.audio=null;a.volume=PS.D_VOL;a.loop=PS.D_LOOP;a.exec=null;a.off=document.createElement("canvas");a.off.width=d;a.off.height=d;a.off.backgroundColor=b;a.offContext=a.off.getContext("2d");a.offContext.font=Math.floor(d/2)+"pt sans-serif";a.offContext.textAlign="center";a.offContext.textBaseline="middle";return a;};PS.Bead=function(b){var c,a,g,f,d,e;c=PS.Grid.context;g=0;f=0;d=b.size;a=b.offContext;e=b.borderWidth;if(e>0){a.fillStyle=b.borderColor;a.fillRect(0,0,d,d);g+=e;f+=e;d-=(e+e);}if(b.empty){a.fillStyle=PS.Grid.bgColor;}else{a.fillStyle=b.colorNow;}a.fillRect(g,f,d,d);if(b.glyph>0){a.fillStyle=b.glyphColor;a.fillText(b.glyphStr,PS.Grid.glyphX,PS.Grid.glyphY);}c.drawImage(b.off,b.left,b.top);};PS.EraseBead=function(a){var b,c,f,e,d;b=PS.Grid.context;f=a.left;e=a.top;c=a.size;d=a.borderWidth;if(d>0){b.fillStyle=a.borderColor;b.fillRect(f,e,c,c);f+=d;e+=d;c-=(d+d);}b.fillStyle=PS.Grid.bgColor;b.fillRect(f,e,c,c);};PS.InitGrid=function(a,h){var f,e,c,d,b,g;f={};f.context=PS.Context();if(!f.context){return null;}f.x=a;f.y=h;f.count=a*h;if(a>=h){f.beadSize=d=Math.floor(PS.CVS_W/a);f.width=d*a;f.height=d*h;f.left=0;}else{f.beadSize=d=Math.floor(PS.CVS_W/h);f.width=d*a;f.height=d*h;f.left=Math.floor((PS.CVS_W-f.width)/2);}f.top=0;f.right=f.left+f.width;f.bottom=f.top+f.height;f.bgRed=PS.D_BG_R;f.bgGreen=PS.D_BG_G;f.bgBlue=PS.D_BG_B;f.bgColor="rgb("+f.bgRed+","+f.bgGreen+","+f.bgBlue+")";f.borderRed=PS.D_BDR_R;f.borderGreen=PS.D_BDR_G;f.borderBlue=PS.D_BDR_B;f.borderColor="rgb("+f.borderRed+","+f.borderGreen+","+f.borderBlue+")";f.borderMax=Math.floor((d-8)/2);f.pointing=-1;f.flash=true;f.flashList=[];f.glyphX=Math.floor(d/2);f.glyphY=Math.floor((d/7)*4);f.glyphSize=Math.floor(d/2)+"pt sans-serif";f.beads=[];g=f.top;for(c=0;c<h;c+=1){b=f.left;for(e=0;e<a;e+=1){f.beads.push(PS.InitBead(b,g,d,f.bgColor));b+=d;}g+=d;}return f;};PS.DrawGrid=function(){var b,d,c,a;b=PS.Grid.beads;d=PS.Grid.count;for(c=0;c<d;c+=1){a=b[c];if(a.visible){PS.Bead(a);}else{PS.EraseBead(a);}}};PS.CheckX=function(a,b){if(typeof a!=="number"){PS.Oops(b+"x parameter not a number");return false;}a=Math.floor(a);if(a<0){PS.Oops(b+"x parameter negative");return false;}if(a>=PS.Grid.x){PS.Oops(b+"x parameter exceeds grid width");return false;}return true;};PS.CheckY=function(b,a){if(typeof b!=="number"){PS.Oops(a+"y parameter not a number");return false;}b=Math.floor(b);if(b<0){PS.Oops(a+"y parameter negative");return false;}if(b>=PS.Grid.y){PS.Oops(a+"y parameter exceeds grid height");return false;}return true;};PS.GridSize=function(a,g){var f,e,d,c,b;f="[PS.GridSize] ";if(a===PS.DEFAULT){a=PS.D_G_W;}else{if(typeof a!=="number"){return PS.Oops(f+"Width param not a number");}a=Math.floor(a);if(a<1){PS.Oops(f+"Width parameter < 1");a=1;}else{if(a>PS.G_MAX){PS.Oops(f+"Width parameter > "+PS.G_MAX);a=PS.G_MAX;}}}if(g===PS.DEFAULT){g=PS.D_G_H;}else{if(typeof g!=="number"){return PS.Oops(f+"Height param not a number");}g=Math.floor(g);if(g<1){PS.Oops(f+"Height parameter < 1");g=1;}else{if(g>PS.G_MAX){PS.Oops(f+"Height parameter > "+PS.G_MAX);g=PS.G_MAX;}}}if(PS.Grid){c=PS.Grid.beads;if(c){d=PS.Grid.count;for(e=0;e<d;e+=1){c[e]=null;}}PS.Grid.beads=null;PS.Grid.flashList=null;PS.Grid=null;}PS.Grid=PS.InitGrid(a,g);if(!PS.Grid){return PS.Oops(f+"Grid initialization failed");}PS.MouseX=-1;PS.MouseY=-1;PS.LastX=-1;PS.LastY=-1;if(PS.Grid){b=document.getElementById(PS.CVS_ID);if(b){b.height=PS.Grid.height;PS.DrawGrid();}}return true;};PS.GridBGColor=function(m,i,o){var n,l,c,f,h,p,j,a,d,k;n="[PS.GridBGColor] ";l=(PS.Grid.bgRed*PS.RSHIFT)+(PS.Grid.bgGreen*PS.GSHIFT)+PS.Grid.bgBlue;if((m===undefined)||(m===PS.CURRENT)){return l;}if(m===PS.DEFAULT){m=PS.D_BG_RGB;f=PS.D_BG_R;h=PS.D_BG_G;p=PS.D_BG_B;}else{c=PS.ColorParams(n,m,i,o);if(!c){return PS.ERROR;}f=c.r;h=c.g;p=c.b;}PS.Grid.bgRed=f;PS.Grid.bgGreen=h;PS.Grid.bgBlue=p;PS.Grid.bgColor="rgb("+f+","+h+","+p+")";k=document.body;k.style.backgroundColor=PS.Grid.bgColor;k=document.getElementById(PS.FTR_ID);if(k){if(f>127){j=0;}else{j=255;}if(h>127){a=0;}else{a=255;}if(p>127){d=0;}else{d=255;}PS.FooterColor="rgb("+j+","+a+","+d+")";k.style.color=PS.FooterColor;}k=document.getElementById(PS.STS_ID);if(k){k.style.backgroundColor=PS.Grid.bgColor;}k=document.getElementById(PS.CVS_ID);if(k){k.width=PS.CVS_W;PS.DrawGrid();}return m;};PS.MakeRGB=function(f,e,a){var d,c;d="[PS.MakeRGB] ";if(typeof f!=="number"){return PS.Oops(d+"R parameter not a number");}f=Math.floor(f);if(f<0){f=0;}else{if(f>255){f=255;}}if(typeof e!=="number"){return PS.Oops(d+"G parameter not a number");}e=Math.floor(e);if(e<0){e=0;}else{if(e>255){e=255;}}if(typeof a!=="number"){return PS.Oops(d+"B parameter not a number");}a=Math.floor(a);if(a<0){a=0;}else{if(a>255){a=255;}}c=(f*PS.RSHIFT)+(e*PS.GSHIFT)+a;return c;};PS.XBShow=function(b,e,c){var d,a;d=b+(e*PS.Grid.x);a=PS.Grid.beads[d];if((c===undefined)||(c===PS.CURRENT)||(c===a.visible)){return a.visible;}a.visible=c;if(c){if(PS.Grid.flash&&a.flash){PS.FlashStart(b,e);}else{a.colorNow=a.color;PS.Bead(a);}}else{PS.EraseBead(a);}return c;};PS.BeadShow=function(a,f,b){var e,d,c;e="[PS.BeadShow] ";if((b!==undefined)&&(b!==PS.CURRENT)){if((b===PS.DEFAULT)||b){b=true;}else{b=false;}}if(a===PS.ALL){if(f===PS.ALL){for(c=0;c<PS.Grid.y;c+=1){for(d=0;d<PS.Grid.x;d+=1){b=PS.XBShow(d,c,b);}}}else{if(!PS.CheckY(f,e)){b=PS.ERROR;}else{for(d=0;d<PS.Grid.x;d+=1){b=PS.XBShow(d,f,b);}}}}else{if(f===PS.ALL){if(!PS.CheckX(a,e)){return PS.ERROR;}for(c=0;c<PS.Grid.y;c+=1){b=PS.XBShow(a,c,b);}}else{if(!PS.CheckX(a,e)||!PS.CheckY(f,e)){b=PS.ERROR;}else{b=PS.XBShow(a,f,b);}}}return b;};PS.XBHue=function(d,k,e,j,h,c){var f,a;f=d+(k*PS.Grid.x);a=PS.Grid.beads[f];if((e===undefined)||(e===PS.CURRENT)){if(a.empty){return PS.EMPTY;}return(a.red*PS.RSHIFT)+(a.green*PS.GSHIFT)+a.blue;}if(e===PS.EMPTY){a.empty=true;}else{a.empty=false;a.red=j;a.green=h;a.blue=c;if(a.alpha<PS.D_ALPHA){a.alphaRed=PS.Dissolve(PS.Grid.bgRed,j,a.alpha);a.alphaGreen=PS.Dissolve(PS.Grid.bgGreen,h,a.alpha);a.alphaBlue=PS.Dissolve(PS.Grid.bgBlue,c,a.alpha);a.color="rgb("+a.alphaRed+","+a.alphaGreen+","+a.alphaBlue+")";}else{a.alphaRed=j;a.alphaGreen=h;a.alphaBlue=c;a.color="rgb("+j+","+h+","+c+")";}}if(a.visible){if(PS.Grid.flash&&a.flash){PS.FlashStart(d,k);}else{a.colorNow=a.color;PS.Bead(a);}}return e;};PS.BeadColor=function(o,l,k,h,n){var m,a,c,d,p,f,e;m="[PS.BeadColor] ";if((k===PS.DEFAULT)||(k===PS.EMPTY)){k=PS.EMPTY;c=d=p=undefined;}else{if((k!==undefined)&&(k!==PS.CURRENT)){a=PS.ColorParams(m,k,h,n);if(!a){return PS.ERROR;}c=a.r;d=a.g;p=a.b;}}if(o===PS.ALL){if(l===PS.ALL){for(e=0;e<PS.Grid.y;e+=1){for(f=0;f<PS.Grid.x;f+=1){k=PS.XBHue(f,e,k,c,d,p);}}}else{if(!PS.CheckY(l,m)){k=PS.ERROR;}else{for(f=0;f<PS.Grid.x;f+=1){k=PS.XBHue(f,l,k,c,d,p);}}}}else{if(l===PS.ALL){if(!PS.CheckX(o,m)){return PS.ERROR;}for(e=0;e<PS.Grid.y;e+=1){k=PS.XBHue(o,e,k,c,d,p);}}else{if(!PS.CheckX(o,m)||!PS.CheckY(l,m)){k=PS.ERROR;}else{k=PS.XBHue(o,l,k,c,d,p);}}}return k;};PS.XBAlpha=function(c,f,d){var e,b;e=c+(f*PS.Grid.x);b=PS.Grid.beads[e];if((d===undefined)||(d===PS.CURRENT)||(d===b.alpha)){return b.alpha;}b.alpha=d;if(b.alpha<PS.D_ALPHA){b.alphaRed=PS.Dissolve(PS.Grid.bgRed,b.red,d);b.alphaGreen=PS.Dissolve(PS.Grid.bgGreen,b.green,d);b.alphaBlue=PS.Dissolve(PS.Grid.bgBlue,b.blue,d);b.color="rgb("+b.alphaRed+","+b.alphaGreen+","+b.alphaBlue+")";}else{b.alphaRed=b.red;b.alphaGreen=b.green;b.alphaBlue=b.blue;b.color="rgb("+b.red+","+b.green+","+b.blue+")";}if(b.visible&&!b.empty){if(PS.Grid.flash&&b.flash){PS.FlashStart(c,f);}else{b.colorNow=b.color;PS.Bead(b);}}return d;};PS.BeadAlpha=function(b,g,c){var f,e,d;f="[PS.BeadAlpha] ";if(c!==undefined){if(typeof c!=="number"){return PS.Oops(f+"alpha param is not a number");}c=Math.floor(c);if(c===PS.DEFAULT){c=PS.D_ALPHA;}else{if(c!==PS.CURRENT){if(c<0){c=0;}else{if(c>PS.D_ALPHA){c=PS.D_ALPHA;}}}}}if(b===PS.ALL){if(g===PS.ALL){for(d=0;d<PS.Grid.y;d+=1){for(e=0;e<PS.Grid.x;e+=1){c=PS.XBAlpha(e,d,c);}}}else{if(!PS.CheckY(g,f)){c=PS.ERROR;}else{for(e=0;e<PS.Grid.x;e+=1){c=PS.XBAlpha(e,g,c);}}}}else{if(g===PS.ALL){if(!PS.CheckX(b,f)){return PS.ERROR;}for(d=0;d<PS.Grid.y;d+=1){c=PS.XBAlpha(b,d,c);}}else{if(!PS.CheckX(b,f)||!PS.CheckY(g,f)){c=PS.ERROR;}else{c=PS.XBAlpha(b,g,c);}}}return c;};PS.XBBWidth=function(b,e,d){var c,a;c=b+(e*PS.Grid.x);a=PS.Grid.beads[c];if((d===undefined)||(d===PS.CURRENT)){return a.borderWidth;}a.borderWidth=d;if(a.visible){PS.Bead(a);}return d;};PS.BeadBorderWidth=function(a,f,e){var d,c,b;d="[PS.BeadBorderWidth] ";if(e===PS.DEFAULT){e=PS.D_BDR_W;}else{if((e!==undefined)&&(e!==PS.CURRENT)){if(typeof e!=="number"){return PS.Oops(d+"width param is not a number");}e=Math.floor(e);if(e<0){e=0;}else{if(e>PS.Grid.borderMax){e=PS.Grid.borderMax;}}}}if(a===PS.ALL){if(f===PS.ALL){for(b=0;b<PS.Grid.y;b+=1){for(c=0;c<PS.Grid.x;c+=1){e=PS.XBBWidth(c,b,e);}}}else{if(!PS.CheckY(f,d)){e=PS.ERROR;}else{for(c=0;c<PS.Grid.x;c+=1){e=PS.XBBWidth(c,f,e);}}}}else{if(f===PS.ALL){if(!PS.CheckX(a,d)){return PS.ERROR;}for(b=0;b<PS.Grid.y;b+=1){e=PS.XBBWidth(a,b,e);}}else{if(!PS.CheckX(a,d)||!PS.CheckY(f,d)){e=PS.ERROR;}else{e=PS.XBBWidth(a,f,e);}}}return e;};PS.XBBColor=function(d,k,e,j,h,c){var f,a;f=d+(k*PS.Grid.x);a=PS.Grid.beads[f];if((e===undefined)||(e===PS.CURRENT)){return(a.borderRed*PS.RSHIFT)+(a.borderGreen*PS.GSHIFT)+a.borderBlue;}a.borderRed=j;a.borderGreen=h;a.borderBlue=c;if(a.borderAlpha<PS.D_ALPHA){j=PS.Dissolve(PS.Grid.bgRed,j,a.borderAlpha);h=PS.Dissolve(PS.Grid.bgGreen,h,a.borderAlpha);c=PS.Dissolve(PS.Grid.bgBlue,c,a.borderAlpha);}a.borderColor="rgb("+j+","+h+","+c+")";if(a.visible){PS.Bead(a);}return e;};PS.BeadBorderColor=function(o,l,k,h,n){var m,a,c,d,p,f,e;m="[PS.BeadBorderColor] ";if(k===PS.DEFAULT){k=PS.D_BDR_RGB;c=PS.D_BDR_R;d=PS.D_BDR_G;p=PS.D_BDR_B;}else{if((k!==undefined)&&(k!==PS.CURRENT)){a=PS.ColorParams(m,k,h,n);if(!a){return PS.ERROR;}c=a.r;d=a.g;p=a.b;}}if(o===PS.ALL){if(l===PS.ALL){for(e=0;e<PS.Grid.y;e+=1){for(f=0;f<PS.Grid.x;f+=1){k=PS.XBBColor(f,e,k,c,d,p);}}}else{if(!PS.CheckY(l,m)){k=PS.ERROR;}else{for(f=0;f<PS.Grid.x;f+=1){k=PS.XBBColor(f,l,k,c,d,p);}}}}else{if(l===PS.ALL){if(!PS.CheckX(o,m)){return PS.ERROR;}for(e=0;e<PS.Grid.y;e+=1){k=PS.XBBColor(o,e,k,c,d,p);}}else{if(!PS.CheckX(o,m)||!PS.CheckY(l,m)){k=PS.ERROR;}else{k=PS.XBBColor(o,l,k,c,d,p);}}}return k;};PS.XBBAlpha=function(e,l,f){var h,d,k,j,c;h=e+(l*PS.Grid.x);d=PS.Grid.beads[h];if((f===undefined)||(f===PS.CURRENT)||(f===d.borderAlpha)){return d.borderAlpha;}d.borderAlpha=f;if(f<PS.D_ALPHA){k=PS.Dissolve(PS.Grid.bgRed,d.borderRed,f);j=PS.Dissolve(PS.Grid.bgGreen,d.borderGreen,f);c=PS.Dissolve(PS.Grid.bgBlue,d.borderBlue,f);d.borderColor="rgb("+k+","+j+","+c+")";}else{d.borderColor="rgb("+d.borderRed+","+d.borderGreen+","+d.borderBlue+")";}if(d.visible){PS.Bead(d);}return f;};PS.BeadBorderAlpha=function(b,g,c){var f,e,d;f="[PS.BeadBorderAlpha] ";if(c!==undefined){if(typeof c!=="number"){return PS.Oops(f+"alpha param is not a number");}c=Math.floor(c);if(c===PS.DEFAULT){c=PS.D_ALPHA;}else{if(c!==PS.CURRENT){if(c<0){c=0;}else{if(c>PS.D_ALPHA){c=PS.D_ALPHA;}}}}}if(b===PS.ALL){if(g===PS.ALL){for(d=0;d<PS.Grid.y;d+=1){for(e=0;e<PS.Grid.x;e+=1){c=PS.XBBAlpha(e,d,c);}}}else{if(!PS.CheckY(g,f)){c=PS.ERROR;}else{for(e=0;e<PS.Grid.x;e+=1){c=PS.XBBAlpha(e,g,c);}}}}else{if(g===PS.ALL){if(!PS.CheckX(b,f)){return PS.ERROR;}for(d=0;d<PS.Grid.y;d+=1){c=PS.XBBAlpha(b,d,c);}}else{if(!PS.CheckX(b,f)||!PS.CheckY(g,f)){c=PS.ERROR;}else{c=PS.XBBAlpha(b,g,c);}}}return c;};PS.XBGlyph=function(b,e,d){var c,a;c=b+(e*PS.Grid.x);a=PS.Grid.beads[c];if((d===undefined)||(d===PS.CURRENT)||(d===a.glyph)){return a.glyph;}a.glyph=d;a.glyphStr=String.fromCharCode(d);if(a.visible){if(PS.Grid.flash&&a.flash){PS.FlashStart(b,e);}else{a.colorNow=a.color;PS.Bead(a);}}return d;};PS.BeadGlyph=function(a,h,f){var e,d,c,b;e="[PS.BeadGlyph] ";d=typeof f;if(d!=="undefined"){if(d==="string"){if(f.length<1){return PS.Oops(e+"glyph param is empty string");}f=f.charCodeAt(0);}else{if(d==="number"){f=Math.floor(f);if(f===PS.DEFAULT){f=0;}else{if(f!==PS.CURRENT){if(f<0){f=0;}}}}else{return PS.Oops(e+"glyph param not a string or number");}}}if(a===PS.ALL){if(h===PS.ALL){for(b=0;b<PS.Grid.y;b+=1){for(c=0;c<PS.Grid.x;c+=1){f=PS.XBGlyph(c,b,f);}}}else{if(!PS.CheckY(h,e)){f=PS.ERROR;}else{for(c=0;c<PS.Grid.x;c+=1){f=PS.XBGlyph(c,h,f);}}}}else{if(h===PS.ALL){if(!PS.CheckX(a,e)){return PS.ERROR;}for(b=0;b<PS.Grid.y;b+=1){f=PS.XBGlyph(a,b,f);}}else{if(!PS.CheckX(a,e)||!PS.CheckY(h,e)){f=PS.ERROR;}else{f=PS.XBGlyph(a,h,f);}}}return f;};PS.XBGColor=function(d,k,e,j,h,c){var f,a;f=d+(k*PS.Grid.x);a=PS.Grid.beads[f];if((e===undefined)||(e===PS.CURRENT)){return(a.glyphRed*PS.RSHIFT)+(a.glyphGreen*PS.GSHIFT)+a.glyphBlue;}a.glyphRed=j;a.glyphGreen=h;a.glyphBlue=c;if(a.alpha<PS.D_ALPHA){j=PS.Dissolve(PS.Grid.bgRed,j,a.alpha);h=PS.Dissolve(PS.Grid.bgGreen,h,a.alpha);c=PS.Dissolve(PS.Grid.bgBlue,c,a.alpha);}a.glyphColor="rgb("+j+","+h+","+c+")";if(a.visible&&(a.glyph>0)){PS.Bead(a);}return e;};PS.BeadGlyphColor=function(o,l,k,h,n){var m,a,c,d,p,f,e;m="[PS.BeadGlyphColor] ";if(k===PS.DEFAULT){k=PS.D_GL_RGB;c=PS.D_GL_R;d=PS.D_GL_G;p=PS.D_GL_B;}else{if((k!==undefined)&&(k!==PS.CURRENT)){a=PS.ColorParams(m,k,h,n);if(!a){return PS.ERROR;}c=a.r;d=a.g;p=a.b;}}if(o===PS.ALL){if(l===PS.ALL){for(e=0;e<PS.Grid.y;e+=1){for(f=0;f<PS.Grid.x;f+=1){k=PS.XBGColor(f,e,k,c,d,p);}}}else{if(!PS.CheckY(l,m)){k=PS.ERROR;}else{for(f=0;f<PS.Grid.x;f+=1){k=PS.XBGColor(f,l,k,c,d,p);}}}}else{if(l===PS.ALL){if(!PS.CheckX(o,m)){return PS.ERROR;}for(e=0;e<PS.Grid.y;e+=1){k=PS.XBGColor(o,e,k,c,d,p);}}else{if(!PS.CheckX(o,m)||!PS.CheckY(l,m)){k=PS.ERROR;}else{k=PS.XBGColor(o,l,k,c,d,p);}}}return k;};PS.XBFlash=function(b,e,c){var d,a;d=b+(e*PS.Grid.x);a=PS.Grid.beads[d];if((c===undefined)||(c===PS.CURRENT)){return a.flash;}a.flash=c;return c;};PS.BeadFlash=function(a,f,b){var e,d,c;e="[PS.BeadFlash] ";if((b!==undefined)&&(b!==PS.CURRENT)){if(b===PS.DEFAULT){b=true;}else{if(b){b=true;}else{b=false;}}}if(a===PS.ALL){if(f===PS.ALL){for(c=0;c<PS.Grid.y;c+=1){for(d=0;d<PS.Grid.x;d+=1){b=PS.XBFlash(d,c,b);}}}else{if(!PS.CheckY(f,e)){b=PS.ERROR;}else{for(d=0;d<PS.Grid.x;d+=1){b=PS.XBFlash(d,f,b);}}}}else{if(f===PS.ALL){if(!PS.CheckX(a,e)){return PS.ERROR;}for(c=0;c<PS.Grid.y;c+=1){b=PS.XBFlash(a,c,b);}}else{if(!PS.CheckX(a,e)||!PS.CheckY(f,e)){b=PS.ERROR;}else{b=PS.XBFlash(a,f,b);}}}return b;};PS.XBFColor=function(d,k,e,j,h,c){var f,a;f=d+(k*PS.Grid.x);a=PS.Grid.beads[f];if((e===undefined)||(e===PS.CURRENT)){return(a.flashRed*PS.RSHIFT)+(a.flashGreen*256)+a.flashBlue;}a.flashRed=j;a.flashGreen=h;a.flashBlue=c;a.flashColor="rgb("+j+","+h+","+c+")";return e;};PS.BeadFlashColor=function(o,l,k,h,n){var m,c,d,p,a,f,e;m="[PS.BeadFlashColor] ";if(k===PS.DEFAULT){k=PS.D_FL_RGB;c=PS.D_FL_R;d=PS.D_FL_G;p=PS.D_FL_B;}else{if((k!==undefined)&&(k!==PS.CURRENT)){a=PS.ColorParams(m,k,h,n);if(!a){return PS.ERROR;}c=a.r;d=a.g;p=a.b;}}if(o===PS.ALL){if(l===PS.ALL){for(e=0;e<PS.Grid.y;e+=1){for(f=0;f<PS.Grid.x;f+=1){k=PS.XBFColor(f,e,k,c,d,p);}}}else{if(!PS.CheckY(l,m)){k=PS.ERROR;}else{for(f=0;f<PS.Grid.x;f+=1){k=PS.XBFColor(f,l,k,c,d,p);}}}}else{if(l===PS.ALL){if(!PS.CheckX(o,m)){return PS.ERROR;}for(e=0;e<PS.Grid.y;e+=1){k=PS.XBFColor(o,e,k,c,d,p);}}else{if(!PS.CheckX(o,m)||!PS.CheckY(l,m)){k=PS.ERROR;}else{k=PS.XBFColor(o,l,k,c,d,p);}}}return k;};PS.XBData=function(b,e,d){var c,a;c=b+(e*PS.Grid.x);a=PS.Grid.beads[c];if(d!==undefined){a.data=d;}return a.data;};PS.BeadData=function(a,f,e){var d,c,b;d="[PS.BeadData] ";if(a===PS.ALL){if(f===PS.ALL){for(b=0;b<PS.Grid.y;b+=1){for(c=0;c<PS.Grid.x;c+=1){e=PS.XBData(c,b,e);}}}else{if(!PS.CheckY(f,d)){e=PS.ERROR;}else{for(c=0;c<PS.Grid.x;c+=1){e=PS.XBData(c,f,e);}}}}else{if(f===PS.ALL){if(!PS.CheckX(a,d)){return PS.ERROR;}for(b=0;b<PS.Grid.y;b+=1){e=PS.XBData(a,b,e);}}else{if(!PS.CheckX(a,d)||!PS.CheckY(f,d)){e=PS.ERROR;}else{e=PS.XBData(a,f,e);}}}return e;};PS.XBAudio=function(b,f,e,d){var c,a;c=b+(f*PS.Grid.x);a=PS.Grid.beads[c];if((e!==undefined)&&(e!==PS.CURRENT)){a.audio=e;}if((d!==undefined)&&(d!==PS.CURRENT)){a.volume=d;}return a.audio;};PS.BeadAudio=function(a,g,f,e){var d,c,b;d="[PS.BeadAudio] ";if((f!==undefined)&&(f!==PS.CURRENT)){if(f===PS.DEFAULT){f=null;}else{if(typeof f!=="string"){return PS.Oops(d+"Audio param is not a string");}if(f.length<1){f=null;}}}if((e!==undefined)&&(e!==PS.CURRENT)){if(e===PS.DEFAULT){e=PS.D_VOL;}else{if(typeof e!=="number"){return PS.Oops(d+"Volume param not a number");}if(e<0){e=0;}else{if(e>PS.MAX_VOL){e=PS.MAX_VOL;}}}}if(a===PS.ALL){if(g===PS.ALL){for(b=0;b<PS.Grid.y;b+=1){for(c=0;c<PS.Grid.x;c+=1){f=PS.XBAudio(c,b,f,e);}}}else{if(!PS.CheckY(g,d)){f=PS.ERROR;}else{for(c=0;c<PS.Grid.x;c+=1){f=PS.XBAudio(c,g,f,e);}}}}else{if(g===PS.ALL){if(!PS.CheckX(a,d)){return PS.ERROR;}for(b=0;b<PS.Grid.y;b+=1){f=PS.XBAudio(a,b,f,e);}}else{if(!PS.CheckX(a,d)||!PS.CheckY(g,d)){f=PS.ERROR;}else{f=PS.XBAudio(a,g,f,e);}}}return f;};PS.XBFunc=function(b,e,c){var d,a;d=b+(e*PS.Grid.x);a=PS.Grid.beads[d];if((c!==undefined)&&(c!==PS.CURRENT)){a.exec=c;}return a.exec;};PS.BeadFunction=function(a,f,b){var e,d,c;e="[PS.BeadFunction] ";if((b!==undefined)||(b!==PS.CURRENT)){if(b===PS.DEFAULT){b=null;}else{if(typeof b!=="function"){return PS.Oops(e+"exec param not a valid function");}}}if(a===PS.ALL){if(f===PS.ALL){for(c=0;c<PS.Grid.y;c+=1){for(d=0;d<PS.Grid.x;d+=1){b=PS.XBFunc(d,c,b);}}}else{if(!PS.CheckY(f,e)){b=PS.ERROR;}else{for(d=0;d<PS.Grid.x;d+=1){b=PS.XBFunc(d,f,b);}}}}else{if(f===PS.ALL){if(!PS.CheckX(a,e)){return PS.ERROR;}for(c=0;c<PS.Grid.y;c+=1){b=PS.XBFunc(a,c,b);}}else{if(!PS.CheckX(a,e)||!PS.CheckY(f,e)){b=PS.ERROR;}else{b=PS.XBFunc(a,f,b);}}}return b;};PS.XBTouch=function(b,d){var c,a;c=b+(d*PS.Grid.x);a=PS.Grid.beads[c];if(typeof a.audio==="string"){PS.AudioPlay(a.audio,a.volume,null,PS.CURRENT,undefined);}if(typeof a.exec==="function"){a.exec(b,d,a.data);}PS.Click(b,d,a.data);};PS.BeadTouch=function(a,e){var d,c,b;d="[PS.BeadTouch] ";if(a===PS.ALL){if(e===PS.ALL){for(b=0;b<PS.Grid.y;b+=1){for(c=0;c<PS.Grid.x;c+=1){PS.XBTouch(c,b);}}}else{if(PS.CheckY(e,d)){for(c=0;c<PS.Grid.x;c+=1){PS.XBTouch(c,e);}}}}else{if(e===PS.ALL){if(!PS.CheckX(a,d)){return;}for(b=0;b<PS.Grid.y;b+=1){PS.XBTouch(a,b);}}else{if(PS.CheckX(a,d)&&PS.CheckY(e,d)){PS.XBTouch(a,e);}}}};PS.StatusText=function(d){var b,a,c;b="[PS.StatusText] ";a=typeof d;if(a!=="undefined"){if(a!=="string"){return PS.Oops(b+"Parameter is not a valid string");}c=document.getElementById(PS.STS_ID);if(c){if(PS.StatusUp){c.style.color=PS.Grid.bgColor;PS.StatusUpPhase=0;PS.StatusUpDelay=PS.STS_REG;PS.StatusDownPhase=100;}else{if(PS.StatusDown){c.style.color=PS.StatusHue;PS.StatusDelay=PS.StatusDelayRate;PS.StatusDownPhase=0;PS.StatusDownDelay=PS.STS_REG;}}c.value=d;}PS.Status=d;}return PS.Status;};PS.StatusColor=function(i,f,k){var j,a,c,d,l,h;j="[PS.StatusColor] ";if((i===undefined)||(i===PS.CURRENT)){return PS.StatusHue;}if(i===PS.DEFAULT){i=PS.D_ST_RGB;c=PS.D_ST_R;d=PS.D_ST_G;l=PS.D_ST_B;}else{a=PS.ColorParams(j,i,f,k);if(!a){return PS.ERROR;}c=a.r;d=a.g;l=a.b;}PS.StatusRed=c;PS.StatusGreen=d;PS.StatusBlue=l;PS.StatusHue="rgb("+c+","+d+","+l+")";PS.StatusUpPhase=100;PS.StatusDownPhase=100;h=document.getElementById(PS.STS_ID);if(h){h.style.color=PS.StatusHue;}return PS.StatusHue;};PS.CalcStep=function(a){var b;b=a/60;b*=PS.STS_FPS;b=100/b;return b;};PS.StatusFadeUp=function(b){var a,c;a="[PS.StatusFadeUp ]";if((b!==undefined)&&(b!==PS.CURRENT)){if(b===PS.DEFAULT){PS.StatusUp=true;PS.StatusUpRate=PS.D_STS_UP;PS.StatusUpStep=PS.CalcStep(PS.D_STS_UP);}else{if(typeof b!=="number"){return PS.Oops(a+"rate paramater not a number");}b=Math.floor(b);if(b<=0){PS.StatusUp=false;PS.StatusUpRate=0;PS.StatusUpPhase=100;c=document.getElementById(PS.STS_ID);if(c){c.style.color=PS.StatusHue;}}else{PS.StatusUp=true;PS.StatusUpRate=b;PS.StatusUpStep=PS.CalcStep(b);}}}return PS.StatusUpRate;};PS.StatusFadeDown=function(c,a){var b,d;b="[PS.StatusFadeDown ]";if((c!==undefined)&&(c!==PS.CURRENT)){if(c===PS.DEFAULT){PS.StatusDown=false;PS.StatusDownRate=PS.D_STS_DOWN;}else{if(typeof c!=="number"){return PS.Oops(b+"rate parameter not a number");}c=Math.floor(c);if(c<=0){PS.StatusDown=false;PS.StatusDownRate=0;PS.StatusDownPhase=100;d=document.getElementById(PS.STS_ID);if(d){d.style.color=PS.StatusHue;}}else{PS.StatusDown=true;PS.StatusDownRate=c;PS.StatusDownStep=PS.CalcStep(c);}if((a!==undefined)&&(a!==PS.CURRENT)){if(a===PS.DEFAULT){PS.StatusDelayRate=PS.D_STS_DELAY;}else{if(typeof a!=="number"){return PS.Oops(b+"delay parameter not a number");}a=Math.floor(a);if(a<=0){PS.StatusDelayRate=0;}else{PS.StatusDelayRate=a;}}}}}return{rate:PS.StatusDownRate,delay:PS.StatusDelayRate};};PS.StatusFade=function(a){var b,c;b="[PS.StatusFade] ";if((a!==undefined)&&(a!==PS.CURRENT)){if(a||(a===PS.DEFAULT)){a=true;PS.StatusUpRate=PS.D_STS_UP;PS.StatusUpPhase=100;}else{a=false;PS.StatusUpRate=0;PS.StatusUpPhase=100;c=document.getElementById(PS.STS_ID);if(c){c.style.color=PS.StatusHue;}}PS.StatusUp=a;}PS.StatusDown=false;PS.StatusDownRate=0;PS.StatusDownPhase=100;return PS.StatusUp;};PS.DebugOpen=function(){var b,a;if(!PS.DebugWindow){b=document.getElementById(PS.DBG_ID);b.style.display="inline";a=document.getElementById(PS.MON_ID);if(a){a.value="";}PS.DebugWindow=true;}};PS.DebugClose=function(){var a;if(PS.DebugWindow){a=document.getElementById(PS.DBG_ID);a.style.display="none";PS.DebugWindow=false;}};PS.Debug=function(b){var a;if((typeof b!=="string")||(b.length<1)){return;}PS.DebugOpen();a=document.getElementById(PS.MON_ID);if(a){a.value+=b;a.scrollTop=a.scrollHeight;}};PS.DebugClear=function(){var a;if(PS.DebugWindow){a=document.getElementById(PS.MON_ID);if(a){a.value="";}}};PS.Oops=function(b){var a;if((typeof b!=="string")||(b.length<1)){b="???";}a=document.getElementById(PS.FTR_ID);if(a){a.innerHTML=b;}PS.Debug("ERROR: "+b+"\n");PS.AudioPlay("fx_uhoh",PS.DEFAULT,null,PS.DEFAULT,undefined);return PS.ERROR;};PS.Clock=function(b){var a;a="[PS.Clock] ";if(b!==undefined){if(typeof b!=="number"){return PS.Oops(a+"ticks parameter not a number");}b=Math.floor(b);if(b<1){PS.UserClock=0;}else{if(typeof PS.Tick!=="function"){return PS.Oops(a+"PS.Tick function undefined");}}PS.UserDelay=0;PS.UserClock=b;}return PS.UserClock;};PS.Timer=function(){window.setTimeout(function(){window.requestAnimationFrame(PS.Timer);PS.XTimer();},PS.D_FPS);};PS.XTimer=function(){var l,h,f,c,p,k,a,j,o,n,q;PS.FlashDelay-=1;if(PS.FlashDelay<1){PS.FlashDelay=PS.FL_INTERVAL;l=PS.Grid.flashList.length;h=0;while(h<l){f=PS.Grid.flashList[h];c=PS.Grid.beads[f];p=c.flashPhase+PS.FL_STEP;if(p>=100){c.colorNow=c.color;c.flashPhase=0;PS.Grid.flashList.splice(h,1);l-=1;}else{c.flashPhase=p;a=PS.Dissolve(c.flashRed,c.alphaRed,p);j=PS.Dissolve(c.flashGreen,c.alphaGreen,p);o=PS.Dissolve(c.flashBlue,c.alphaBlue,p);c.colorNow="rgb("+a+","+j+","+o+")";h+=1;}PS.Bead(c);}}if(PS.FooterDelay>0){PS.FooterDelay-=1;if(!PS.FooterDelay){n=document.getElementById(PS.FTR_ID);if(n){n.innerHTML="";}}}if(PS.StatusUp&&(PS.StatusUpPhase<100)){if(PS.StatusUpDelay>0){PS.StatusUpDelay-=1;}else{PS.StatusUpDelay=PS.STS_REG;p=PS.StatusUpPhase+PS.StatusUpStep;if(p>=100){p=100;k=PS.StatusHue;if(PS.StatusDown){PS.StatusDelay=PS.StatusDelayRate;PS.StatusDownPhase=0;PS.StatusDownDelay=PS.STS_REG;}}else{a=PS.Dissolve(PS.Grid.bgRed,PS.StatusRed,p);j=PS.Dissolve(PS.Grid.bgGreen,PS.StatusGreen,p);o=PS.Dissolve(PS.Grid.bgBlue,PS.StatusBlue,p);k="rgb("+a+","+j+","+o+")";}PS.StatusUpPhase=p;n=document.getElementById(PS.STS_ID);if(n){n.style.color=k;}}}if(PS.StatusDown&&(PS.StatusDownPhase<100)){if(PS.StatusDelay>0){PS.StatusDelay-=1;}else{if(PS.StatusDownDelay>0){PS.StatusDownDelay-=1;}else{PS.StatusDownDelay=PS.STS_REG;p=PS.StatusDownPhase+PS.StatusDownStep;if(p>=100){p=100;k=PS.Grid.bgColor;}else{a=PS.Dissolve(PS.StatusRed,PS.Grid.bgRed,p);j=PS.Dissolve(PS.StatusGreen,PS.Grid.bgGreen,p);o=PS.Dissolve(PS.StatusBlue,PS.Grid.bgBlue,p);k="rgb("+a+","+j+","+o+")";}PS.StatusDownPhase=p;n=document.getElementById(PS.STS_ID);if(n){n.style.color=k;}if(p>=100){PS.StatusText("");}}}}l=PS.Holding.length;if(l>0){if(PS.KeyDelay>0){PS.KeyDelay-=1;}else{PS.KeyDelay=PS.KEY_RATE;h=0;while(h<l){q=PS.Holding[h];try{PS.KeyDown(q,PS.HoldShift,PS.HoldCtrl);}catch(d){PS.Oops("Key down repeat failed ["+d.message+"]");}h+=1;}}}if(PS.UserClock>0){PS.UserDelay+=1;if(PS.UserDelay>=PS.UserClock){PS.UserDelay=0;if(PS.Tick){try{PS.Tick();}catch(m){PS.UserClock=0;PS.Oops("PS.Tick() failed ["+m.message+"]");}}}}};PS.FlashStart=function(c,f){var e,b,d,a;e=c+(f*PS.Grid.x);b=PS.Grid.beads[e];b.flashPhase=0;b.colorNow=b.flashColor;PS.Bead(b);a=PS.Grid.flashList.length;for(d=0;d<a;d+=1){if(PS.Grid.flashList[d]===e){return;}}PS.Grid.flashList.push(e);};PS.MouseXY=function(a){var b,h,g,f,d,j,c,e;if(PS.Grid){b=document.getElementById(PS.CVS_ID);if(a.x&&a.y){h=a.x;g=a.y;}else{h=a.clientX;g=a.clientY;}h+=(document.body.scrollLeft+document.documentElement.scrollLeft-b.offsetLeft);g+=(document.body.scrollTop+document.documentElement.scrollTop-b.offsetTop);if((h>=PS.Grid.left)&&(h<PS.Grid.right)&&(g>=PS.Grid.top)&&(g<PS.Grid.bottom)){f=PS.Grid.beads;e=0;for(j=0;j<PS.Grid.y;j+=1){d=f[e];if((g>=d.top)&&(g<d.bottom)){for(c=0;c<PS.Grid.x;c+=1){d=f[e];if((h>=d.left)&&(h<d.right)){PS.MouseX=c;PS.MouseY=j;return;}e+=1;}}else{e+=PS.Grid.x;}}}}PS.MouseX=-1;PS.MouseY=-1;};PS.MouseDown=function(d){var a;PS.MouseXY(d);if(PS.MouseX>=0){a=PS.Grid.beads[PS.MouseX+(PS.MouseY*PS.Grid.x)];if(a.audio){PS.AudioPlay(a.audio,a.volume,null,PS.CURRENT,undefined);}if(typeof a.exec==="function"){try{a.exec(PS.MouseX,PS.MouseY,a.data);}catch(c){PS.Oops("Bead "+PS.MouseX+", "+PS.MouseY+" function failed ["+c.message+"]");}}if(PS.Click){try{PS.Click(PS.MouseX,PS.MouseY,a.data);}catch(b){PS.Oops("PS.Click() failed ["+b.message+"]");}}}};PS.MouseUp=function(c){var a;if(PS.Grid&&PS.Release){PS.MouseXY(c);if(PS.MouseX>=0){a=PS.Grid.beads[PS.MouseX+(PS.MouseY*PS.Grid.x)];try{PS.Release(PS.MouseX,PS.MouseY,a.data);}catch(b){PS.Oops("PS.Release() failed ["+b.message+"]");}}}};PS.MouseMove=function(f){var b,e;PS.OverCanvas=true;PS.MouseXY(f);if(PS.MouseX>=0){b=PS.Grid.beads[PS.MouseX+(PS.MouseY*PS.Grid.x)];if((PS.MouseX!==PS.LastX)||(PS.MouseY!==PS.LastY)){if(PS.Leave){if(PS.LastX>=0){e=PS.Grid.beads[PS.LastX+(PS.LastY*PS.Grid.x)];try{PS.Leave(PS.LastX,PS.LastY,e.data);}catch(d){PS.Oops("PS.Leave() failed ["+d.message+"]");}}}if(PS.Enter){try{PS.Enter(PS.MouseX,PS.MouseY,b.data);}catch(c){PS.Oops("PS.Enter() failed ["+c.message+"]");}}PS.LastX=PS.MouseX;PS.LastY=PS.MouseY;}}else{if(PS.LastX>=0){if(PS.Leave){e=PS.Grid.beads[PS.LastX+(PS.LastY*PS.Grid.x)];try{PS.Leave(PS.LastX,PS.LastY,e.data);}catch(a){PS.Oops("PS.Leave() failed ["+a.message+"]");}}PS.LastX=-1;PS.LastY=-1;}}};PS.MouseOut=function(c){var b;PS.OverCanvas=false;PS.MouseBead=-1;if(PS.Grid&&PS.Leave){if(PS.LastBead>=0){b=PS.Grid.beads[PS.LastBead];try{PS.Leave(b.x,b.y,b.data);}catch(a){PS.Oops("PS.Leave() failed ["+a.message+"]");}}}PS.LastBead=-1;};PS.LegalKey=function(a){if((a===91)||(a===93)){return false;}if((a>=32)||(a===27)||(a===9)){return true;}return false;};PS.KeyFilter=function(b,a){if((b>=65)&&(b<=90)){if(a){b+=32;}return b;}switch(b){case 33:b=PS.KEY_PAGE_UP;break;case 34:b=PS.KEY_PAGE_DOWN;break;case 35:b=PS.KEY_END;break;case 36:b=PS.KEY_HOME;break;case 37:b=PS.ARROW_LEFT;break;case 38:b=PS.ARROW_UP;break;case 39:b=PS.ARROW_RIGHT;break;case 40:b=PS.ARROW_DOWN;break;case 45:b=PS.KEY_INSERT;break;case 46:b=PS.KEY_DELETE;break;case 188:b=44;break;case 190:b=46;break;case 191:b=47;break;case 192:b=96;break;case 222:b=39;break;case 219:b=91;break;case 221:b=93;break;case 220:b=92;break;default:break;}if(a){switch(b){case 96:b=126;break;case 49:b=33;break;case 50:b=64;break;case 51:b=35;break;case 52:b=36;break;case 53:b=37;break;case 54:b=94;break;case 55:b=38;break;case 56:b=42;break;case 57:b=40;break;case 48:b=41;break;case 45:b=95;break;case 61:b=43;break;case 91:b=123;break;case 93:b=125;break;case 92:b=124;break;case 59:b=58;break;case 39:b=34;break;case 44:b=60;break;case 46:b=62;break;case 47:b=63;break;default:break;}}return b;};PS.SysKeyDown=function(c){var a;if(PS.DebugFocus){c.returnValue=true;return true;}if(PS.KeyDown){c.returnValue=false;if(!c.which){a=c.keyCode;}else{a=c.which;}if(PS.LegalKey(a)){PS.HoldShift=c.shiftKey;PS.HoldCtrl=c.ctrlKey;if(!PS.Pressed[a]){a=PS.KeyFilter(a,c.shiftKey);PS.Pressed[a]=1;if(PS.Holding.length<1){PS.KeyDelay=PS.KEY_RATE*5;}if(PS.Holding.indexOf(a)<0){PS.Holding.push(a);}try{PS.KeyDown(a,c.shiftKey,c.ctrlKey);}catch(b){PS.Oops("PS.KeyDown() failed ["+b.message+"]");}}}}return false;};PS.SysKeyUp=function(d){var b,a;if(PS.KeyUp){d.returnValue=false;if(d.which===null){b=d.keyCode;}else{b=d.which;}if(PS.LegalKey(b)){b=PS.KeyFilter(b,d.shiftKey);PS.Pressed[b]=0;a=PS.Holding.indexOf(b);if(a>=0){PS.Holding.splice(a,1);}if(PS.Holding.length<1){PS.KeyDelay=0;PS.HoldShift=0;PS.HoldCtrl=0;}try{PS.KeyUp(b,d.shiftKey,d.ctrlKey);}catch(c){PS.Oops("PS.KeyUp() failed ["+c.message+"]");}}}return false;};PS.SysWheel=function(b){var c;if(!PS.OverCanvas){b.returnValue=true;return true;}if(PS.Wheel){c=0;if(!b){b=window.event;}if(b.wheelDelta){c=b.wheelDelta/120;if(window.opera){c=-c;}}else{if(b.detail){c=-(b.detail/3);}}if(b.preventDefault){b.preventDefault();}if(c>=PS.FORWARD){c=PS.FORWARD;}else{c=PS.BACKWARD;}try{PS.Wheel(c);}catch(a){PS.Oops("PS.Wheel() failed ["+a.message+"]");}}b.returnValue=false;};PS.DefaultEvent=function(a){a.returnValue=true;};PS.Random=function(b){var a;a="[PS.Random] ";if(typeof b!=="number"){return PS.Oops(a+"Parameter is not a number");}b=Math.floor(b);if(b<2){return 1;}b=Math.random()*b;b=Math.floor(b)+1;return b;};PS.PianoFiles=["a0","bb0","b0","c1","db1","d1","eb1","e1","f1","gb1","g1","ab1","a1","bb1","b1","c2","db2","d2","eb2","e2","f2","gb2","g2","ab2","a2","bb2","b2","c3","db3","d3","eb3","e3","f3","gb3","g3","ab3","a3","bb3","b3","c4","db4","d4","eb4","e4","f4","gb4","g4","ab4","a4","bb4","b4","c5","db5","d5","eb5","e5","f5","gb5","g5","ab5","a5","bb5","b5","c6","db6","d6","eb6","e6","f6","gb6","g6","ab6","a6","bb6","b6","c7","db7","d7","eb7","e7","f7","gb7","g7","ab7","a7","bb7","b7","c8"];PS.Piano=function(d,a){var b,c;b="[PS.Piano] ";if(typeof d!=="number"){return PS.Oops(b+"Parameter is not a number");}d=Math.floor(d);if(d<1){d=1;}else{if(d>88){d=88;}}c="piano_"+PS.PianoFiles[d-1];if(a){c="l_"+c;}return c;};PS.HchordFiles=["a2","bb2","b2","c3","db3","d3","eb3","e3","f3","gb3","g3","ab3","a3","bb3","b3","c4","db4","d4","eb4","e4","f4","gb4","g4","ab4","a4","bb4","b4","c5","db5","d5","eb5","e5","f5","gb5","g5","ab5","a5","bb5","b5","c6","db6","d6","eb6","e6","f6","gb6","g6","ab6","a6","bb6","b6","c7","db7","d7","eb7","e7","f7"];PS.Harpsichord=function(d,a){var b,c;b="[PS.Harpsichord] ";if(typeof d!=="number"){return PS.Oops(b+"Parameter is not a number");}d=Math.floor(d);if(d<1){d=1;}else{if(d>57){d=57;}}c="hchord_"+PS.HchordFiles[d-1];if(a){c="l_"+c;}return c;};PS.XyloFiles=["a4","bb4","b4","c5","db5","d5","eb5","e5","f5","gb5","g5","ab5","a5","bb5","b5","c6","db6","d6","eb6","e6","f6","gb6","g6","ab6","a6","bb6","b6","c7","db7","d7","eb7","e7","f7","gb7","g7","ab7","a7","bb7","b7"];PS.Xylophone=function(c){var a,b;a="[PS.Xylophone] ";if(typeof c!=="number"){return PS.Oops(a+"Parameter is not a number");}c=Math.floor(c);if(c<1){c=1;}else{if(c>39){c=39;}}b="xylo_"+PS.XyloFiles[c-1];return b;};PS.ImageError=function(a){PS.Debug("[PS.ImageLoad] Error loading "+this.src);};PS.DoImageLoad=function(){var a,g,f,e,b,j,c,h;a=this.getAttribute("data-id");g=PS.LoaderList.length;f=0;while(f<g){e=PS.LoaderList[f];if(e.id===a){b=e.func;j=e.format;c=e.file;PS.LoaderList.splice(f,1);break;}f+=1;}h=PS.ImageData(this,j);if(h!==PS.ERROR){try{h.id=a;h.file=c;b(h);}catch(d){PS.Oops("[PS.ImageLoad] Load function failed");}}};PS.ImageLoad=function(b,e,f){var c,a,g;c="[PS.ImageLoad] ";if((typeof b!=="string")||(b.length<1)){return PS.Oops(c+"Invalid file parameter");}if(typeof e!=="function"){return PS.Oops(c+"Invalid function parameter");}if((f===PS.DEFAULT)||(f===undefined)){f=3;}else{if(typeof f!=="number"){return PS.Oops(c+"format parameter not a number");}if((f!==1)&&(f!==3)&&(f!==4)){return PS.Oops(c+"format is not 1, 3 or 4");}}g="img"+PS.LoaderCnt;PS.LoaderCnt+=1;PS.LoaderList.push({file:b,id:g,func:e,format:f});try{a=new Image();a.setAttribute("data-id",g);a.onload=PS.DoImageLoad;a.onerror=PS.ImageError;a.src=b;}catch(d){return PS.Oops(c+"Load failed: "+b+" ["+d.message+"]");}return g;};PS.ImageData=function(A,q){var e,k,t,n,l,x,d,s,f,p,o,z,m,u,y;e="[PS.ImageMap] ";k=A.width;if((typeof k!=="number")||(k<0)){return PS.Oops(e+"Image .width invalid");}k=Math.floor(k);t=A.height;if((typeof t!=="number")||(t<0)){return PS.Oops(e+"Image .height invalid");}t=Math.floor(t);try{PS.ImageCanvas.width=k;PS.ImageCanvas.height=t;n=PS.ImageCanvas.getContext("2d");n.drawImage(A,0,0);}catch(c){return PS.Oops(e+"Data extraction failed @ 1 ["+c.message+"]");}try{l=n.getImageData(0,0,k,t);}catch(v){return PS.Oops(e+"Data extraction failed @ 2 ["+v.message+"]");}x={width:l.width,height:l.height};d=l.data;s=d.length;f=[];p=0;if(q===3){f.length=(s/4)*3;o=0;while(p<s){f[o]=d[p];p+=1;o+=1;f[o]=d[p];p+=1;o+=1;f[o]=d[p];p+=2;o+=1;}x.pixelSize=3;}else{if(q===4){f.length=s;while(p<s){f[p]=d[p];p+=1;f[p]=d[p];p+=1;f[p]=d[p];p+=1;z=d[p];f[p]=Math.floor(z/2.55);p+=1;}x.pixelSize=4;}else{f.length=s/4;o=0;while(p<s){m=d[p];p+=1;u=d[p];p+=1;y=d[p];p+=2;f[o]=(m*PS.RSHIFT)+(u*PS.GSHIFT)+y;o+=1;}x.pixelSize=1;}}x.data=f;return x;};PS.ImageBlit=function(q,R,s,m,o,c,d){var D,F,l,J,T,M,V,C,E,u,Y,f,e,B,z,G,H,N,U,W,X,n,v,Q,S,P,O,K,k,I,j,L,p,A;D="[PS.ImageBlit] ";F=PS.Grid.x;l=PS.Grid.y;if(typeof q!=="object"){return PS.Oops(D+"Invalid imgdata parameter");}J=q.width;if(typeof J!=="number"){return PS.Oops(D+"imgdata.width not a number");}J=Math.floor(J);if(J<1){return PS.Oops(D+"imgdata.width < 1");}T=q.height;if(typeof T!=="number"){return PS.Oops(D+"imgdata.height not a number");}T=Math.floor(T);if(T<1){return PS.Oops(D+"imgdata.height < 1");}X=PS.D_ALPHA;C=q.pixelSize;if(typeof C!=="number"){return PS.Oops(D+"imgdata.pixelSize not a number");}C=Math.floor(C);if((C!==1)&&(C!==3)&&(C!==4)){return PS.Oops(D+"imgdata.pixelSize is not 1, 3 or 4");}M=J*T*C;V=q.data;if(V.length!==M){return PS.Oops(D+"imgdata.data length invalid ["+q.data.length+"]");}if((R===undefined)||(R===PS.DEFAULT)){R=0;}else{if(typeof R!=="number"){return PS.Oops(D+"xpos parameter not a number");}R=Math.floor(R);if((R>=F)||((R+J)<0)){return true;}}if((s===undefined)||(s===PS.DEFAULT)){s=0;}else{if(typeof s!=="number"){return PS.Oops(D+"ypos parameter not a number");}s=Math.floor(s);if((s>=l)||((s+T)<0)){return true;}}if(m===undefined){o=0;m=0;c=J;d=T;}else{if(typeof m!=="number"){return PS.Oops(D+"left parameter not a number");}m=Math.floor(m);if((m<0)||(m>=J)){return PS.Oops(D+"left parameter outside of image");}if(typeof o!=="number"){return PS.Oops(D+"top parameter not a number");}o=Math.floor(o);if((o<0)||(o>=T)){return PS.Oops(D+"top parameter outside of image");}if(typeof c!=="number"){return PS.Oops(D+"width parameter not a number");}c=Math.floor(c);if(c<1){return true;}if((m+c)>J){return PS.Oops(D+"left + width exceeds image width");}if(typeof d!=="number"){return PS.Oops(D+"height parameter not a number");}d=Math.floor(d);if(d<1){return true;}if((o+d)>T){return PS.Oops(D+"top + height exceeds image height");}}p=F-R;if(c>p){c=p;}A=l-s;if(d>A){d=A;}E=(J*C);z=PS.Grid.beadSize;p=z*c;A=z*d;PS.BlitCanvas.width=p;PS.BlitCanvas.height=A;B=PS.BlitContext;B.font=PS.Grid.glyphSize;B.textAlign="center";B.textBaseline="middle";u=(o*E)+(m*C);e=s;for(G=0;G<d;G+=1){Y=u;f=R;for(H=0;H<c;H+=1){if(C===1){n=V[Y];N=n/PS.RSHIFT;N=Math.floor(N);v=N*PS.RSHIFT;U=(n-v)/PS.GSHIFT;U=Math.floor(U);Q=U*PS.GSHIFT;W=n-v-Q;}else{N=V[Y];U=V[Y+1];W=V[Y+2];if(C===4){X=V[Y+3];}}if(X>0){S=f+(e*F);P=PS.Grid.beads[S];P.empty=false;if(X<PS.D_ALPHA){P.alphaRed=PS.Dissolve(P.red,N,X);P.alphaGreen=PS.Dissolve(P.green,U,X);P.alphaBlue=PS.Dissolve(P.blue,W,X);P.color="rgb("+P.alphaRed+","+P.alphaGreen+","+P.alphaBlue+")";N=P.alphaRed;U=P.alphaGreen;W=P.alphaBlue;}else{P.alphaRed=N;P.alphaGreen=U;P.alphaBlue=W;P.color="rgb("+N+","+U+","+W+")";}P.red=N;P.green=U;P.blue=W;O=z;K=H*z;I=G*z;if(P.visible){P.flashPhase=100;P.colorNow=P.color;k=K;j=I;L=P.borderWidth;if(L>0){B.fillStyle=P.borderColor;B.fillRect(K,I,O,O);K+=L;I+=L;O-=(L+L);}B.fillStyle=P.colorNow;B.fillRect(K,I,O,O);if(P.glyph>0){B.fillStyle=P.glyphColor;B.fillText(P.glyphStr,k+PS.Grid.glyphX,j+PS.Grid.glyphY);}}else{B.fillStyle=PS.Grid.bgColor;B.fillRect(K,I,O,O);}}f+=1;Y+=C;}e+=1;u+=E;}PS.Grid.context.drawImage(PS.BlitCanvas,z*R,z*s);return true;};PS.AudioError=function(a){var d,b;d=a.target.error.code;switch(d){case 1:b="Playback aborted";break;case 2:b="Network failure";break;case 3:b="Source decode failed";break;case 4:b="Invalid source file";break;default:b="Unknown";break;}return PS.Oops("HTML5 audio error "+d+" ("+b+")");};PS.AudioLoaded=function(c){var a,b;a=this.getAttribute("data-channel");b=PS.AudioChannels[a];b.status=PS.CH_READY;if(b.playNow){b.playNow=false;PS.PlayHTML5Audio(a,undefined,undefined,undefined);}};PS.AudioEnding=function(e){var a,d,c;a=this.getAttribute("data-channel");d=PS.AudioChannels[a];d.status=PS.CH_READY;c=d.exec;if(c&&(typeof c==="function")){try{d.exec=null;c(d.data);}catch(b){PS.Oops("Audio function error ["+b.message+"]");}}};PS.AudioInit=function(){var c,b,a;c="[PS.AudioInit] ";if(!document.createElement("audio").canPlayType){PS.Oops(c+"HTML5 audio not supported");return false;}PS.AudioContext=null;PS.AudioCurrentPath=PS.D_AUDIO_PATH;if(!PS.AudioContext){PS.ChannelsUsed=0;PS.AudioChannels.length=PS.AUDIO_MAX_CH;for(b=0;b<PS.AUDIO_MAX_CH;b+=1){a=document.createElement("audio");if(!a){return PS.Oops(c+"Audio element init failed");}a.setAttribute("data-channel",b);document.body.appendChild(a);PS.AudioChannels[b]={id:"",audio:a,volume:PS.D_VOL,playNow:false,exec:null,num:b+1,data:b+1,status:PS.CH_EMPTY};}}return true;};PS.AudioPath=function(b){var a;a="[PS.AudioPath] ";if((b===undefined)||(b===PS.CURRENT)){b=PS.AudioCurrentPath;}else{if(b===PS.DEFAULT){b=PS.D_AUDIO_PATH;}else{if(typeof b!=="string"){return PS.Oops(a+"parameter not a valid string");}}}PS.AudioCurrentPath=b;return b;};PS.AudioLoad=function(e,d){var b,c,a;b="[PS.AudioLoad] ";if((typeof e!=="string")||(e.length<1)){return PS.Oops(b+"ID parameter not a valid string");}if((d===undefined)||(d===PS.CURRENT)){d=PS.AudioCurrentPath;}else{if(d===PS.DEFAULT){d=PS.D_AUDIO_PATH;}else{if(typeof d!=="string"){return PS.Oops(b+"Path parameter not a valid string");}}}if(!PS.AudioContext){c=d+e+".wav";a=PS.LoadHTML5Audio(c,undefined,undefined,undefined,undefined);if(a===PS.ERROR){return a;}return true;}};PS.AudioPlay=function(a,e,b,j,c){var g,d,f,h;g="[PS.AudioPlay] ";if((e===undefined)||(e===PS.DEFAULT)){e=PS.D_VOL;}else{if(typeof e!=="number"){return PS.Oops(g+"Volume parameter not a number");}if(e<0){e=0;}else{if(e>PS.MAX_VOL){e=PS.MAX_VOL;}}}if(!b||(b===PS.DEFAULT)){b=null;}else{if(typeof b!=="function"){return PS.Oops(g+"Func parameter not a valid function");}}if((j===undefined)||(j===PS.CURRENT)){j=PS.AudioCurrentPath;}else{if(j===PS.DEFAULT){j=PS.D_AUDIO_PATH;}else{if(typeof j!=="string"){return PS.Oops(g+"Path parameter not a valid string");}}}if(!PS.AudioContext){h=j+a+".wav";for(d=0;d<PS.ChannelsUsed;d+=1){f=PS.AudioChannels[d];if((f.id===h)&&(f.status===PS.CH_READY)){return PS.PlayHTML5Audio(d,e,b,c);}}d=PS.LoadHTML5Audio(h,e,b,c,true);if(d===PS.ERROR){return d;}return d+1;}};PS.AudioStop=function(d){var a,b;a="[PS.AudioStop] ";if(typeof d!=="number"){return PS.Oops(a+"Parameter is not a number");}d=Math.floor(d);if(!PS.AudioContext){if((d<1)||(d>PS.AUDIO_MAX_CH)){return PS.Oops(a+"Invalid channel id");}b=PS.AudioChannels[d-1];b.audio.pause();b.audio.currentTime=0;b.status=PS.CH_READY;return d;}};PS.AudioPause=function(e){var a,d,b;a="[PS.AudioPause] ";if(typeof e!=="number"){return PS.Oops(a+"Parameter is not a number");}e=Math.floor(e);if(!PS.AudioContext){if((e<1)||(e>PS.AUDIO_MAX_CH)){return PS.Oops(a+"Invalid channel id ["+e+"]");}d=PS.AudioChannels[e-1];b=d.audio;if(b.paused){PS.PlayHTML5Audio(e-1,undefined,undefined,undefined);}else{d.status=PS.CH_PAUSED;b.pause();}return e;}};PS.LoadChannel=function(c,g,f,e,h,b){var d,a;d=PS.AudioChannels[c];d.id=g;if(f!==undefined){d.volume=f;}else{d.volume=PS.D_VOL;}if(e){d.exec=e;}else{d.exec=null;}if(h!==undefined){d.data=h;}else{d.data=d.num;}if(b){d.playNow=true;}else{d.playNow=false;}a=d.audio;a.addEventListener("error",PS.AudioError,false);a.addEventListener("canplaythrough",PS.AudioLoaded,false);a.addEventListener("ended",PS.AudioEnding,false);a.preload="auto";a.volume=d.volume;a.setAttribute("src",g);d.status=PS.CH_LOADING;};PS.LoadHTML5Audio=function(g,f,e,h,a){var c,d,b;c="[PS.LoadHTML5Audio] ";for(b=0;b<PS.ChannelsUsed;b+=1){d=PS.AudioChannels[b];if((d.id===g)&&(d.status===PS.CH_READY)){d.audio.currentTime=0;if(f!==undefined){d.volume=f;}else{d.volume=PS.D_VOL;}d.audio.volume=d.volume;if(e){d.exec=e;}else{d.exec=null;}if(h!==undefined){d.data=h;}else{d.data=d.num;}if(a){PS.PlayHTML5Audio(b,undefined,undefined,undefined);}return b;}}for(b=0;b<PS.AUDIO_MAX_CH;b+=1){d=PS.AudioChannels[b];if(d.status===PS.CH_EMPTY){PS.ChannelsUsed=b+1;PS.LoadChannel(b,g,f,e,h,a);return b;}}for(b=0;b<PS.ChannelsUsed;b+=1){d=PS.AudioChannels[b];if(d.status===PS.CH_READY){PS.LoadChannel(b,g,f,e,h,a);return b;}}return PS.ERROR;};PS.PlayHTML5Audio=function(a,d,c,e){var b;b=PS.AudioChannels[a];if(d===undefined){d=b.volume;}else{b.volume=d;}b.audio.volume=d;if(c){b.exec=c;}else{b.exec=null;}if(e!==undefined){b.data=e;}else{b.data=b.num;}b.status=PS.CH_PLAYING;b.audio.play();return a+1;};PS.Sys=function(){var j,a,f,k,b,h,c,g;j="[PS.Sys] ";a=j+"Invalid element";window.onblur=function(m){var e,l;e=PS.Pressed.length;for(l=0;l<e;l+=1){PS.Pressed[l]=0;}};f=document.createElement("div");if(!f){window.alert(a);return;}f.id=PS.MAIN_ID;document.body.appendChild(f);b=document.createElement("div");if(!b){window.alert(a);return;}b.id=PS.DBG_ID;document.body.appendChild(b);h=document.createElement("input");if(!h){window.alert(a);return;}h.id=PS.STS_ID;h.type="text";h.readonly="readonly";h.value="";f.appendChild(h);PS.StatusUp=true;PS.StatusUpRate=PS.D_STS_UP;PS.StatusUpStep=PS.CalcStep(PS.D_STS_UP);PS.Pressed.length=256;for(g=0;g<256;g+=1){PS.Pressed[g]=0;}PS.Holding.length=0;h=document.createElement("canvas");if(!h){window.alert(j+"HTML5 canvas not supported.");return;}h.id=PS.CVS_ID;h.width=PS.CVS_W;h.height=PS.CVS_W;h.addEventListener("mousedown",PS.MouseDown,false);h.addEventListener("mouseup",PS.MouseUp,false);h.addEventListener("mouseout",PS.MouseOut,false);h.addEventListener("mousemove",PS.MouseMove,false);f.appendChild(h);k=document.createElement("p");if(!h){window.alert(a);return;}k.id=PS.FTR_ID;k.innerHTML="Loading Perlenspiel";f.appendChild(k);c=document.createElement("textarea");if(!c){window.alert(a);return;}c.id=PS.MON_ID;c.cols=57;c.rows=8;c.wrap="soft";c.readonly="readonly";c.onfocus=function(){PS.DebugFocus=true;};c.onblur=function(){PS.DebugFocus=false;};b.appendChild(c);if(!PS.AudioInit()){return;}PS.AudioLoad("fx_uhoh",PS.DEFAULT);if(typeof PS.Init!=="function"){PS.Init=null;PS.Oops(j+"WARNING: PS.Init function undefined");}if(typeof PS.Click!=="function"){PS.Click=null;PS.Oops(j+"WARNING: PS.Click function undefined");}if(typeof PS.Release!=="function"){PS.Release=null;PS.Oops(j+"WARNING: PS.Release function undefined");}if(typeof PS.Enter!=="function"){PS.Enter=null;PS.Oops(j+"WARNING: PS.Enter function undefined");}if(typeof PS.Leave!=="function"){PS.Leave=null;PS.Oops(j+"WARNING: PS.Leave function undefined");}if(typeof PS.KeyDown!=="function"){PS.KeyDown=null;PS.Oops(j+"WARNING: PS.KeyDown function undefined");}if(typeof PS.KeyUp!=="function"){PS.KeyUp=null;PS.Oops(j+"WARNING: PS.KeyUp function undefined");}if(typeof PS.Wheel!=="function"){PS.Wheel=null;PS.Oops(j+"WARNING: PS.Wheel function undefined");}document.onkeydown=PS.SysKeyDown;document.onkeyup=PS.SysKeyUp;if(window.addEventListener){window.addEventListener("DOMMouseScroll",PS.SysWheel,false);window.addEventListener("mousewheel",PS.SysWheel,false);}else{window.onmousewheel=PS.SysWheel;document.onmousewheel=PS.SysWheel;}PS.ImageCanvas=document.createElement("canvas");PS.BlitCanvas=document.createElement("canvas");PS.BlitCanvas.width=PS.CVS_W;PS.BlitCanvas.height=PS.CVS_W;PS.BlitContext=PS.BlitCanvas.getContext("2d");PS.BlitContext.textAlign="center";PS.BlitContext.textBaseline="middle";k.innerHTML="";PS.Timer();if(PS.Init){try{PS.Init();}catch(d){PS.Oops("PS.Init() failed ["+d.message+"]");}}else{PS.GridSize(PS.D_G_W,PS.D_G_H);}};\r