How to use escapePath method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

mandelbrotexplorer.js

Source:mandelbrotexplorer.js Github

copy

Full Screen

1/** escapingZ to get the eye 1000cloud res  16iterations filter iteratios > 122currentZ = mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex]);3previousZ = mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex-1]);4useZ = currentZ - previousZ;5useZ;6*/7/** valley of the elephants turnd inside out....8currentZ = mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex]);9previousZ = mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex-1]);10useZ = currentZ - previousZ;11useX = escapePath[pathIndex-1][0] + ((escapePath[pathIndex][0]/currentZ) * currentZ);12useY = escapePath[pathIndex-1][1] + ((escapePath[pathIndex][1]/currentZ) * currentZ);13escapePath[pathIndex][0] = useX;14escapePath[pathIndex][1] = useY;15useZ;16useZ = abs(z(n)) - abs(z(n-1);17useX = z(n-1)[x] + ((z(n)[x]/abs(z(n))) * abs(z(n)));18useY = z(n-1)[y] + ((z(n)[y]/abs(z(n))) * abs(z(n)));19z(n)[0] = useX;20z(n)[1] = useY;21useZ;22*/23/** stuffed in the corner24currentZ = mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex]);25previousZ = mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex-1]);26useX = escapePath[pathIndex][0] + (escapePath[pathIndex][0] * (escapePath[pathIndex][0]/Math.sqrt(currentZ)));27useY = escapePath[pathIndex][1] + (escapePath[pathIndex][1] * (escapePath[pathIndex][1]/Math.sqrt(currentZ)));28useZ = mandelbrotExplorer.getAbsoluteValueOfComplexNumber([useX, useY]) - previousZ;29escapePath[pathIndex][0] = useX;30escapePath[pathIndex][1] = useY;31useZ;32*/33/*34// this is a neat flower.....35newX = pathIndex > 0 ? newX - escapePath[0][0] : 0;36newY = pathIndex > 0 ? newY - escapePath[0][1] : 0;37*/38/*39I need to add a way of mapping the particles displayed in the current scene 40back to their initial x,y.41*/42/*43Preturbation: somehting where each iteration is slowed by the previous iteratyions in the same frame44*/45var STR_PAD_LEFT = 1;46var STR_PAD_RIGHT = 2;47var STR_PAD_BOTH = 3;48var paletteColors = {49	"lightyellow1":			{"R": 255, "G": 255, "B": 204, "A": 255},50 	"lightyellow2":			{"R": 255, "G": 255, "B": 153, "A": 255},51 	"lightyellow3":			{"R": 255, "G": 255, "B": 102, "A": 255},52 	"lightyellow4":			{"R": 255, "G": 255, "B": 51, "A": 255},53 	"yellow":				{"R": 255, "G": 255, "B": 0, "A": 255},54 	"darkyellow1":			{"R": 204, "G": 204, "B": 0, "A": 255},55 	"darkyellow2":			{"R": 153, "G": 153, "B": 0, "A": 255},56 	"darkyellow3":			{"R": 102, "G": 102, "B": 0, "A": 255},57 	"darkyellow4":			{"R": 51, "G": 51, "B": 0, "A": 255},58 	"lawngreen":			{"R": 124, "G": 252, "B": 0, "A": 255},59 	"chartreuse":			{"R": 127, "G": 255, "B": 0, "A": 255},60 	"limegreen":			{"R": 50, "G": 205, "B": 50, "A": 255},61 	"lime":					{"R": 0, "G": 255, "B": 0, "A": 255},62 	"forestgreen":			{"R": 34, "G": 139, "B": 34, "A": 255},63 	"green": 				{"R": 0, "G": 128, "B": 0, "A": 255},64 	"darkgreen":			{"R": 0, "G": 100, "B": 0, "A": 255},65 	"springgreen": 			{"R": 0, "G": 255, "B": 127, "A": 255},66 	"greenyellow": 			{"R": 173, "G": 255, "B": 47, "A": 255},67 	"yellowgreen": 			{"R": 154, "G": 205, "B": 50, "A": 255},68 	"mediumspringgreen":	{"R": 0, "G": 250, "B": 154, "A": 255},69 	"lightgreen":			{"R": 144, "G": 238, "B": 144, "A": 255},70 	"palegreen":			{"R": 152, "G": 251, "B": 152, "A": 255},71 	"darkseagreen":			{"R": 143, "G": 188, "B": 143, "A": 255},72 	"mediumseagreen":		{"R": 60, "G": 179, "B": 113, "A": 255},73 	"lightseagreen":		{"R": 32, "G": 178, "B": 170, "A": 255},74 	"seagreen":				{"R": 46, "G": 139, "B": 87, "A": 255},75 	"olive":				{"R": 128, "G": 128, "B": 0, "A": 255},76 	"darkolivegreen":		{"R": 85, "G": 107, "B": 47, "A": 255},77 	"olivedrab":			{"R": 107, "G": 142, "B": 35, "A": 255},78 	"aliceblue":			{"R": 240, "G": 248, "B": 255, "A": 255},79 	"lavender":				{"R": 230, "G": 230, "B": 250, "A": 255},80 	"powderblue":			{"R": 176, "G": 224, "B": 230, "A": 255},81 	"lightblue":			{"R": 173, "G": 216, "B": 230, "A": 255},82 	"lightskyblue":			{"R": 135, "G": 206, "B": 250, "A": 255},83 	"skyblue":				{"R": 135, "G": 206, "B": 235, "A": 255},84 	"deepskyblue":			{"R": 0, "G": 191, "B": 255, "A": 255},85 	"lightsteelblue":		{"R": 176, "G": 196, "B": 222, "A": 255},86 	"dodgerblue":			{"R": 30, "G": 144, "B": 255, "A": 255},87 	"cornflowerblue":		{"R": 100, "G": 149, "B": 237, "A": 255},88 	"steelblue":			{"R": 70, "G": 130, "B": 180, "A": 255},89 	"cadetblue":			{"R": 95, "G": 158, "B": 160, "A": 255},90 	"mediumslateblue":		{"R": 123, "G": 104, "B": 238, "A": 255},91 	"slateblue":			{"R": 106, "G": 90, "B": 205, "A": 255},92 	"darkslateblue":		{"R": 72, "G": 61, "B": 139, "A": 255},93 	"royalblue":			{"R": 65, "G": 105, "B": 225, "A": 255},94 	"blue":					{"R": 0, "G": 0, "B": 255, "A": 255},95 	"mediumblue":			{"R": 0, "G": 0, "B": 205, "A": 255},96 	"darkblue":				{"R": 0, "G": 0, "B": 139, "A": 255},97 	"navy":					{"R": 0, "G": 0, "B": 128, "A": 255},98 	"midnightblue":			{"R": 25, "G": 25, "B": 112, "A": 255},99 	"blueviolet":			{"R": 138, "G": 43, "B": 226, "A": 255},100 	"indigo":				{"R": 75, "G": 0, "B": 130, "A": 255},101 	"lightsalmon":			{"R": 255, "G": 160, "B": 122, "A": 255},102 	"salmon":				{"R": 250, "G": 128, "B": 114, "A": 255},103 	"darksalmon":			{"R": 233, "G": 150, "B": 122, "A": 255},104 	"lightcoral":			{"R": 240, "G": 128, "B": 128, "A": 255},105 	"indianred":			{"R": 205, "G": 92, "B": 92, "A": 255},106 	"crimson":				{"R": 220, "G": 20, "B": 60, "A": 255},107 	"firebrick":			{"R": 178, "G": 34, "B": 34, "A": 255},108 	"red":					{"R": 255, "G": 0, "B": 0, "A": 255},109 	"darkred":				{"R": 139, "G": 0, "B": 0, "A": 255},110 	"maroon":				{"R": 128, "G": 0, "B": 0, "A": 255},111 	"tomato":				{"R": 255, "G": 99, "B": 71, "A": 255},112 	"orangered":			{"R": 255, "G": 69, "B": 0, "A": 255},113 	"palevioletred":		{"R": 219, "G": 112, "B": 147, "A": 255},114};115var palettes = {116	"palette1": [117		{"B": 15, "R": 10, "G":  5, "A":255},118		{"R": 15, "G": 10, "B":  5, "A":255},119		{"G": 15, "B": 10, "R":  5, "A":255},120		{"B": 30, "R": 20, "G": 10, "A":255},121		{"R": 30, "G": 20, "B": 10, "A":255},122		{"G": 30, "B": 20, "R": 10, "A":255},123		{"B": 45, "R": 30, "G": 15, "A":255},124		{"R": 45, "G": 30, "B": 15, "A":255},125		{"G": 45, "B": 30, "R": 15, "A":255},126		{"B": 60, "R": 40, "G": 20, "A":255},127		{"R": 60, "G": 40, "B": 20, "A":255},128		{"G": 60, "B": 40, "R": 20, "A":255},129		{"B": 75, "R": 50, "G": 25, "A":255},130		{"R": 75, "G": 50, "B": 25, "A":255},131		{"G": 75, "B": 50, "R": 25, "A":255},132		{"B": 90, "R": 60, "G": 30, "A":255},133		{"R": 90, "G": 60, "B": 30, "A":255},134		{"G": 90, "B": 60, "R": 30, "A":255},135		{"B":105, "R": 70, "G": 35, "A":255},136		{"R":105, "G": 70, "B": 35, "A":255},137		{"G":105, "B": 70, "R": 35, "A":255},138		{"B":120, "R": 80, "G": 40, "A":255},139		{"R":120, "G": 80, "B": 40, "A":255},140		{"G":120, "B": 80, "R": 40, "A":255},141		{"B":135, "R": 90, "G": 45, "A":255},142		{"R":135, "G": 90, "B": 45, "A":255},143		{"G":135, "B": 90, "R": 45, "A":255},144		{"B":150, "R":100, "G": 50, "A":255},145		{"R":150, "G":100, "B": 50, "A":255},146		{"G":150, "B":100, "R": 50, "A":255},147		{"B":165, "R":110, "G": 55, "A":255},148		{"R":165, "G":110, "B": 55, "A":255},149		{"G":165, "B":110, "R": 55, "A":255},150		{"B":170, "R":120, "G": 60, "A":255},151		{"R":170, "G":120, "B": 60, "A":255},152		{"G":170, "B":120, "R": 60, "A":255},153		{"B":185, "R":130, "G": 65, "A":255},154		{"R":185, "G":130, "B": 65, "A":255},155		{"G":185, "B":130, "R": 65, "A":255},156		{"B":200, "R":140, "G": 70, "A":255},157		{"R":200, "G":140, "B": 70, "A":255},158		{"G":200, "B":140, "R": 70, "A":255},159		{"B":215, "R":150, "G": 75, "A":255},160		{"R":215, "G":150, "B": 75, "A":255},161		{"G":215, "B":150, "R": 75, "A":255},162		{"B":230, "R":160, "G": 80, "A":255},163		{"R":230, "G":160, "B": 80, "A":255},164		{"G":230, "B":160, "R": 80, "A":255},165		{"B":245, "R":170, "G": 85, "A":255},166		{"R":245, "G":170, "B": 85, "A":255},167		{"G":245, "B":170, "R": 85, "A":255}168	],169	"palette2": [170		{"R":  30, "G":  25, "B":  20, "A":255},171		{"R":  60, "G":  50, "B":  40, "A":255},172		{"R":  90, "G":  75, "B":  60, "A":255},173		{"R": 120, "G": 100, "B":  80, "A":255},174		{"R": 150, "G": 125, "B": 100, "A":255},175		{"R": 180, "G": 150, "B": 120, "A":255},176		{"R": 210, "G": 175, "B": 140, "A":255},177		{"R": 240, "G": 200, "B": 160, "A":255},178		{"R":  15, "G": 225, "B": 180, "A":255},179		180		{"R":  45, "G": 250, "B": 200, "A":255},181		{"R":  75, "G":  20, "B": 220, "A":255},182		{"R": 105, "G":  45, "B": 240, "A":255},183		{"R": 135, "G":  60, "B":   5, "A":255},184		{"R": 165, "G":  85, "B":  25, "A":255},185		{"R": 195, "G": 110, "B":  45, "A":255},186		{"R": 225, "G": 135, "B":  65, "A":255},187		{"R": 255, "G": 160, "B":  85, "A":255},188		{"R":  30, "G": 185, "B": 105, "A":255},189		190		{"R":  60, "G": 210, "B": 125, "A":255},191		{"R":  90, "G": 235, "B": 145, "A":255},192		{"R": 120, "G":   5, "B": 165, "A":255},193		{"R": 150, "G":  30, "B": 185, "A":255},194		{"R": 180, "G":  55, "B": 205, "A":255},195		{"R": 210, "G":  80, "B": 225, "A":255},196		{"R": 240, "G": 105, "B": 245, "A":255},197		{"R":  15, "G": 130, "B":  10, "A":255},198		{"R":  45, "G": 155, "B":  30, "A":255}199		200	],201	"palette3": [202		{"R":  30, "G":  0, "B":  0, "A":255},203		{"R":  45, "G":  0, "B":  0, "A":255},204		{"R":  60, "G":  0, "B":  0, "A":255},205		{"R":  75, "G":  0, "B":  0, "A":255},206		{"R":  90, "G":  0, "B":  0, "A":255},207		{"R": 105, "G":  0, "B":  0, "A":255},208		{"R": 120, "G":  0, "B":  0, "A":255},209		{"R": 135, "G":  0, "B":  0, "A":255},210		{"R": 150, "G":  0, "B":  0, "A":255},211		{"R": 165, "G":  0, "B":  0, "A":255},212		{"R": 180, "G":  0, "B":  0, "A":255},213		{"R": 195, "G":  0, "B":  0, "A":255},214		{"R": 210, "G":  0, "B":  0, "A":255},215		{"R": 225, "G":  0, "B":  0, "A":255},216		{"R": 240, "G":  0, "B":  0, "A":255},217		{"R": 255, "G":  0, "B":  0, "A":255}218	],219	"palette4": [220		{"R":  30, "G":128, "B":  0, "A":255},221		{"R": 255, "G":255, "B":  0, "A":255},222		{"R":  45, "G":120, "B":  0, "A":255},223		{"R": 240, "G":240, "B":  0, "A":255},224		{"R":  60, "G":112, "B":  0, "A":255},225		{"R": 225, "G":225, "B":  0, "A":255},226		{"R":  75, "G":105, "B":  0, "A":255},227		{"R": 210, "G":210, "B":  0, "A":255},228		{"R":  90, "G": 97, "B":  0, "A":255},229		{"R": 195, "G":195, "B":  0, "A":255},230		{"R": 105, "G": 48, "B":  0, "A":255},231		{"R": 180, "G":180, "B":  0, "A":255},232		{"R": 120, "G": 24, "B":  0, "A":255},233		{"R": 165, "G":165, "B":  0, "A":255},234		{"R": 135, "G": 12, "B":  0, "A":255},235		{"R": 150, "G":150, "B":  0, "A":255},236		{"R": 150, "G":  6, "B":  0, "A":255},237		{"R": 135, "G":135, "B":  0, "A":255},238		{"R": 165, "G":  3, "B":  0, "A":255},239		{"R": 120, "G":120, "B":  0, "A":255},240		{"R": 180, "G":  2, "B":  0, "A":255},241		{"R": 105, "G":105, "B":  0, "A":255},242		{"R": 195, "G":  1, "B":  0, "A":255},243		{"R":  90, "G": 90, "B":  0, "A":255},244		{"R": 210, "G":  0, "B":  0, "A":255},245		{"R":  75, "G": 75, "B":  0, "A":255},246		{"R": 225, "G":  0, "B":  0, "A":255},247		{"R":  60, "G": 60, "B":  0, "A":255},248		{"R": 240, "G":  0, "B":  0, "A":255},249		{"R":  45, "G": 45, "B":  0, "A":255},250		{"R": 255, "G":  0, "B":  0, "A":255},251		{"R":   0, "G":  0, "B":128, "A":255}252	],253	"palette5": [254		{"R":  30, "G":  0, "B":  0, "A":255},255		{"R":  45, "G": 15, "B": 15, "A":255},256		{"R":  60, "G":  0, "B":  0, "A":255},257		{"R":  75, "G": 30, "B": 30, "A":255},258		{"R":  90, "G":  0, "B":  0, "A":255},259		{"R": 105, "G": 45, "B": 45, "A":255},260		{"R": 120, "G":  0, "B":  0, "A":255},261		{"R": 135, "G": 60, "B": 60, "A":255},262		{"R": 150, "G":  0, "B":  0, "A":255},263		{"R": 165, "G": 75, "B": 75, "A":255},264		{"R": 180, "G":  0, "B":  0, "A":255},265		{"R": 195, "G": 90, "B": 90, "A":255},266		{"R": 210, "G":  0, "B":  0, "A":255},267		{"R": 225, "G":105, "B":105, "A":255},268		{"R": 240, "G":  0, "B":  0, "A":255},269		{"R": 255, "G":120, "B":120, "A":255}270	],271	"Ginger": [272		{"R": 247, "G":255, "B":0, "A":255},273		{"R": 0, "G":255, "B":0, "A":255},274		{"R": 0, "G":0, "B":255, "A":255},275		{"R": 255, "G":0, "B":0, "A":255},276	],277	"palette6": [278		{"R": 0, "G":0, "B":0, "A":255},279		{"G": 0, "B":0, "R":205, "A":255},280		{"B": 0, "G":0, "R":210, "A":255},281		{"R": 0, "G":0, "B":215, "A":255},282		{"R": 0, "B":0, "G":220, "A":255},283		{"B": 0, "R":0, "G":10, "A":255},284		{"R": 0, "B":0, "G":15, "A":255},285		{"G": 0, "B":0, "R":20, "A":255},286		{"R": 0, "B":0, "G":145, "A":255},287		{"G": 0, "R":0, "B":150, "A":255},288		{"R": 0, "B":0, "G":155, "A":255},289		{"R": 0, "B":0, "G":160, "A":255},290		{"G": 0, "R":0, "B":165, "A":255},291		{"G": 0, "B":0, "R":170, "A":255},292		{"R": 0, "B":0, "G":175, "A":255},293		{"B": 0, "R":0, "G":25, "A":255},294		{"R": 0, "G":0, "B":30, "A":255},295		{"R": 0, "B":0, "G":35, "A":255},296		{"G": 0, "B":0, "R":40, "A":255},297		{"B": 0, "G":0, "R":55, "A":255},298		{"R": 0, "B":0, "G":50, "A":255},299		{"G": 0, "B":0, "R":55, "A":255},300		{"B": 0, "G":0, "R":60, "A":255},301		{"G": 0, "R":0, "B":65, "A":255},302		{"R": 0, "B":0, "G":70, "A":255},303		{"B": 0, "R":0, "G":75, "A":255},304		{"G": 0, "B":0, "R":5, "A":255},305		{"B": 0, "R":0, "G":250, "A":255},306		{"G": 0, "R":0, "B":255, "A":255},307		{"B": 0, "R":0, "G":130, "A":255},308		{"R": 0, "G":0, "B":135, "A":255},309		{"G": 0, "B":0, "R":140, "A":255},310		{"B": 0, "G":0, "R":90, "A":255},311		{"R": 0, "G":0, "B":95, "A":255},312		{"B": 0, "R":0, "G":100, "A":255},313		{"G": 0, "R":0, "B":105, "A":255},314		{"B": 0, "G":0, "R":110, "A":255},315		{"G": 0, "R":0, "B":115, "A":255},316		{"B": 0, "R":0, "G":120, "A":255},317		{"B": 0, "G":0, "R":125, "A":255},318		{"R": 0, "B":0, "G":200, "A":255},319		{"G": 0, "B":0, "R":80, "A":255},320		{"R": 0, "G":0, "B":85, "A":255},321		{"G": 0, "R":0, "B":240, "A":255},322		{"R": 0, "G":0, "B":245, "A":255},323		{"B": 0, "G":0, "R":225, "A":255},324		{"B": 0, "G":0, "R":230, "A":255},325		{"R": 0, "B":0, "G":235, "A":255},326		{"G": 0, "R":0, "B":180, "A":255},327		{"B": 0, "G":0, "R":185, "A":255},328		{"G": 0, "B":0, "R":190, "A":255},329		{"G": 0, "R":0, "B":195, "A":255},330		331		332	],333	"namedColorsish": [334		paletteColors.lightyellow1,335		paletteColors.lightyellow2,336		paletteColors.lightyellow3,337		paletteColors.lightyellow4,338		paletteColors.yellow,339		paletteColors.darkyellow1,340		paletteColors.darkyellow2,341		paletteColors.darkyellow3,342		paletteColors.darkyellow4,343		paletteColors.lawngreen,344		paletteColors.chartreuse,345		paletteColors.limegreen,346		paletteColors.lime,347		paletteColors.forestgreen,348		paletteColors.green,349		paletteColors.darkgreen,350		paletteColors.springgreen,351		paletteColors.greenyellow,352		paletteColors.yellowgreen,353		paletteColors.mediumspringgreen,354		paletteColors.lightgreen,355		paletteColors.palegreen,356		paletteColors.darkseagreen,357		paletteColors.mediumseagreen,358		paletteColors.lightseagreen,359		paletteColors.seagreen,360		paletteColors.olive,361		paletteColors.darkolivegreen,362		paletteColors.olivedrab,363		paletteColors.aliceblue,364		paletteColors.lavender,365		paletteColors.powderblue,366		paletteColors.lightblue,367		paletteColors.lightskyblue,368		paletteColors.skyblue,369		paletteColors.deepskyblue,370		paletteColors.lightsteelblue,371		paletteColors.dodgerblue,372		paletteColors.cornflowerblue,373		paletteColors.steelblue,374		paletteColors.cadetblue,375		paletteColors.mediumslateblue,376		paletteColors.slateblue,377		paletteColors.darkslateblue,378		paletteColors.royalblue,379		paletteColors.blue,380		paletteColors.mediumblue,381		paletteColors.darkblue,382		paletteColors.navy,383		paletteColors.midnightblue,384		paletteColors.blueviolet,385		paletteColors.indigo,386		paletteColors.lightsalmon,387		paletteColors.salmon,388		paletteColors.darksalmon,389		paletteColors.lightcoral,390		paletteColors.indianred,391		paletteColors.crimson,392		paletteColors.firebrick,393		paletteColors.red,394		paletteColors.darkred,395		paletteColors.maroon,396		paletteColors.tomato,397		paletteColors.orangered,398		paletteColors.palevioletred,399	],400	"rainbow": [{"R":128,"G":243,"B":32,"A":255},{"R":166,"G":223,"B":12,"A":255},{"R":200,"G":193,"B":2,"A":255},{"R":227,"G":158,"B":3,"A":255},{"R":246,"G":121,"B":16,"A":255},{"R":255,"G":83,"B":38,"A":255},{"R":252,"G":50,"B":69,"A":255},{"R":238,"G":24,"B":105,"A":255},{"R":214,"G":7,"B":143,"A":255},{"R":182,"G":1,"B":179,"A":255},{"R":146,"G":6,"B":211,"A":255},{"R":108,"G":22,"B":236,"A":255},{"R":72,"G":48,"B":251,"A":255},{"R":41,"G":81,"B":255,"A":255},{"R":17,"G":117,"B":247,"A":255},{"R":4,"G":155,"B":229,"A":255},{"R":1,"G":191,"B":202,"A":255},{"R":10,"G":221,"B":169,"A":255},{"R":30,"G":242,"B":131,"A":255},{"R":58,"G":253,"B":93,"A":255},{"R":93,"G":254,"B":59,"A":255},{"R":130,"G":243,"B":31,"A":255},{"R":168,"G":221,"B":11,"A":255},{"R":201,"G":192,"B":2,"A":255},{"R":229,"G":156,"B":4,"A":255},{"R":247,"G":118,"B":17,"A":255},{"R":255,"G":81,"B":40,"A":255},{"R":251,"G":49,"B":71,"A":255},{"R":237,"G":23,"B":107,"A":255},{"R":212,"G":7,"B":145,"A":255},{"R":180,"G":1,"B":181,"A":255},{"R":144,"G":7,"B":213,"A":255}],401	"variable_rainbow": [],402	get buildRainbow(){403		if(this.variable_rainbow.length == 0){404			var result = [];405			var frequency = .3;406			for (var i = 0; i < 32; ++i){407			   red   = Math.round( (Math.sin(frequency*i + 0) * 127 + 128) % 255, 0);408			   green = Math.round( (Math.sin(frequency*i + 2) * 127 + 128) % 255, 0);409			   blue  = Math.round( (Math.sin(frequency*i + 4) * 127 + 128) % 255, 0);410			   result.push({"R": red, "G": green, "B": blue, "A": 255});411			}412			413			this.variable_rainbow = result;414		}415		return this.variable_rainbow;416	},417	"getColorIndex": function(colorPalette, color){418		for( var index = 0; index < colorPalette.length; index++ ){419			if(    colorPalette[index].R == color.R 420				&& colorPalette[index].G == color.G 421				&& colorPalette[index].B == color.B 422				&& colorPalette[index].A == color.A )423			{424				return index;425			}426		}427		428		return -1;429	}430};431var mandelbrotExplorer = {432	"useRenderer": THREE.WebGLRenderer,433	"rendererOptions": {434		alpha: true, 435		precision: "mediump", 436		antialias: false,437		preserveDrawingBuffer: true 438	},439	"onlyShortened": true,440	"onlyFull": false,441	"startX": 				-2,442	"endX": 				2,443	"startY": 				2,444	"endY": 				-2,445	"maxIterations_2d": 	32,446	"maxIterations_3d": 	512,447	"zoomFactor": 			0.15,448	"xOffset": 				null,449	"yOffset": 				null,450	"canvas_2d": 			null,451	"xScale_2d": 			null,452	"yScale_2d": 			null,453	"canvas_3d": 			null,454	"xScale_3d": 			null,455	"yScale_3d": 			null,456	"scales_3d":			[],457	"randomizeCloudStepping": false,458	"cloudResolution":		"43,101",//774,459	"dualZ": true,460	"dualZMultiplier":      "newX = escapePath[pathIndex][0];\nnewY = escapePath[pathIndex][1];\nnewZ = z * -1;",461    "dualZMultiplierExamples": [462        "newX += escapePath[pathIndex-1][0];\nnewY += escapePath[pathIndex-1][1];\nnewZ = z * -1;",463		"newX += escapePath[pathIndex > 1 ? pathIndex - 1 : 0][0] * -1;\nnewY += escapePath[pathIndex > 1 ? pathIndex - 1 : 0][1] * -1;\nnewZ = z * -1;",464    ],465	"particleSize":         "mandelbrotExplorer.xScale_3d/mandelbrotExplorer.maxIterations_3d",466    "particleSizeExamples": [467        "0",468        "index/mandelbrotExplorer.iterationParticles.length"469    ],470	"cloudLengthFilter":	"escapePath.length > 8",//"escapePath.length == mandelbrotExplorer.maxIterations_3d - 1",//"escapePath.length > 8",471	//"cloudLengthFilterPresets": {472	"presets": {473		"cloudLengthFilter": {474			"iteration8": 			"escapePath.length == 8",475			"iterationDecimation":	"escapePath.length % 10 == 0",476			"maxIterations":		"escapePath.length == mandelbrotExplorer.maxIterations_3d || escapePath.shortened",477			"theMeat":				"escapePath.length > parseInt( mandelbrotExplorer.maxIterations_3d * .1 )"478							   + "&& escapePath.length < parseInt( mandelbrotExplorer.maxIterations_3d * .9 )"479							   + "&& escapePath.length  > 5"480		},481		"juliaC": {482			"mandelbrot":	"[0,0]",483			"strange1":		"[(c[0]*-1)+c[1],0]",484			"strange2":		"[(c[0]*-1)-c[1],(c[1]*-1)-c[0]]",485			"julia01":		"[-1.037,0.17]",486			"julia02":		"[-0.52,0.57]",487			"julia03":		"[0.295,0.55]",488			"julia04":		"[-0.624,0.435]",489			"julia05":		"[.285,0]",490			"julia06":		"[.285,0.01]",491			"julia07":		"[0.45,0.1428]",492			"julia08":		"[-0.70176,-0.3842]",493			"julia09":		"[-0.835,-0.2321]",494			"julia10":		"[-0.8,0.156]",495			"julia11":		"[-.62772,.42193]",496			"julia12":		"[-.74434,-.10772]",497			"julia13":		"[.233,.53780]",498			"julia14":		"[.03515,-.07467]",499			"julia15":		"[-.67319,.34442]",500			"julia16":		"[-.74543,.11301]",501			502			"julia17":		"[0.37,0.16]",503			"julia18":		"[−0.50,−0.56]",504			"julia19":		"[−0.25,0]",505			"julia20":		"[0,1]",506			"julia21":		"[−1.5,0]",507			"julia22":		"[−0.75,0.25]",508			"julia23":		"[−0.8,0.15]",509			"julia24":		"[−1,0]",510			"julia25":		"[-0.79,0.14]",511			"julia26":		"[0.35,0.11]",512			"julia27":		"[-0.25,0.64]",513			"julia28":		"[0,-0.66]",514			"julia29":		"[-0.039,0.695]",515			"julia30":		"[-0.1,0.651]",516			"julia31":		"[-0.74543,0.11301]"517		},518		"mandelbrot": {519			"escapingZ": {520				"currentZLessPreviousZ_percentOfMax3D": "((pathIndex + 1)/mandelbrotExplorer.maxIterations_3d)*(mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex]) - mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex-1]));",521				"currentZLessPreviousZ": 			"mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex]) - mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex-1]);",522				"alternatingPathOrigin": 			"zDirection * mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[0]);",523				pathOriginAndSkewedByPrevious: function(escapePath, pathIndex){524					this.toString = function(escapePath, pathIndex){525						return "mandelbrotExplorer.getAbsoluteValueOfComplexNumber((escapePath.length == 1 ? escapePath[0] : [escapePath[pathIndex][0] + escapePath[pathIndex-1][0],escapePath[pathIndex][1] + escapePath[pathIndex-1][1]]));";526					}527					528					return mandelbrotExplorer.getAbsoluteValueOfComplexNumber((escapePath.length == 1 ? escapePath[0] : [escapePath[pathIndex][0] + escapePath[pathIndex-1][0],escapePath[pathIndex][1] + escapePath[pathIndex-1][1]]));529				},530				previousPathZ: function(escapePath, pathIndex){531					this.toString = function(escapePath, pathIndex){532						return "mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex - 1]);";533					}534					535					return mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex - 1]);536				},537				pathEnd: function(){538					this.toString = function(escapePath, pathIndex){539						return "mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[escapePath.length - 1]);";540					}541					return mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[escapePath.length - 1]);542				},543				pathOrigin: function(escapePath, pathIndex){544					this.toString = function(escapePath, pathIndex){545						return "mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[0]);";546					}547					return mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[0]);548				},549				currentPathZ: function(escapePath, pathIndex){550					this.toString = function(){551						return "mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex]);";552					}553					554					return mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex]);555				}556			},557		}558	},559	"cloudIterationFilter":	"iteration > 8",//"iteration > 8",//"iteration == mandelbrotExplorer.maxIterations_3d",//"iteration < 9",560	"particleSystems": 		[],//[iterationIndex][THREE.ParticleSystem]561	"lines": 		[],//[iterationIndex][THREE.]562	"iterationParticles": [],//[iterationIndex]{particles: THREE.Geometry}      563/*564	this.iterationParticles[iterationIndex] = {"particles": new THREE.Geometry()};565					}566					var newX = escapePath[pathIndex][0];567					var newY = escapePath[pathIndex][1];568					var particleVector = new THREE.Vector3(newX, newY, z);569					this.iterationParticles[iterationIndex].particles.vertices.push(particleVector);570*/571	"particleCoords":	[],//[iterationIndex][X1,Y1,Z1,X2,Y2,Y3,...]572	"particleLimit": 		100000000,573	"cycleTime": 			10,574	"continueColorCycle": 	false,575	"continueIterationCycle": false,576	"iterationCycleFrame":  10,577	"renderer": 			null,578	"scene": 				null,579	"camera": 				null,580	"controls": 			null,581	"palette":				palettes.palette2,582	"particleFilter":		null,583    "particleFilterExamples": [584        "(newX > 0.24 && newX < 0.26) || (newY > 0.24 && newY < 0.26)",585        "(newX > 0.24 && newX < 0.26)",586        "(mandelbrotExplorer.getAbsoluteValueOfComplexNumber([newX, newY]) > 0.24 && mandelbrotExplorer.getAbsoluteValueOfComplexNumber([newX, newY]) < 0.26)"587    ],588	"initialZ":				"return [0,0];", 589    "initialZExamples": [590        "return this.getAbsoluteValueOfComplexNumber(escapePath[0]);",591        "return this.getAbsoluteValueOfComplexNumber(escapePath[escapePath.length - 1]);",592    ],593	"escapingZ":			"return (\n"594							+ "mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex]) - mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex-1])"595                            + "\n);",596    "escapingZExamples": [597        "return mandelbrotExplorer.presets.mandelbrot.escapingZ.previousPathZ(escapePath, pathIndex);",598        "((pathIndex + 1)/this.maxIterations_3d)*(this.getAbsoluteValueOfComplexNumber(escapePath[pathIndex]) - this.getAbsoluteValueOfComplexNumber(escapePath[pathIndex-1]));",599        "this.getAbsoluteValueOfComplexNumber(escapePath[pathIndex]) - this.getAbsoluteValueOfComplexNumber(escapePath[pathIndex-1]);",600        "this.getAbsoluteValueOfComplexNumber((escapePath.length == 1 ? escapePath[0] : [escapePath[pathIndex][0] + escapePath[pathIndex-1][0],escapePath[pathIndex][1] + escapePath[pathIndex-1][1]]));",601        "this.getAbsoluteValueOfComplexNumber(escapePath[0]);",602        "this.getAbsoluteValueOfComplexNumber(escapePath[pathIndex - 1])"603    ],604	"nextCycleIteration":	1,605	"iterationCycleTime":	parseInt(1000/30),606	"juliaC":				  "[0,0]",607    "juliaCExamples": [608        "[c[1],c[0]]",609        "[(c[0]*-1)+c[1],0]",610        "[(c[0]*-1)-c[1],(c[1]*-1)-c[0]]",611        "[-1.037,0.17]",612        "[-0.52,0.57]",613        "[0.295,0.55]",614        "[-0.624,0.435]",615        "[.285,0]",616        "[.285,0.01]",617        "[0.45,0.1428]",618        "[-0.70176,-0.3842]",619        "[-0.835,-0.2321]",620        "[-0.8,0.156]",621        "[-.62772,.42193]",622        "[-.74434,-.10772]",623        "[.233,.53780]",624        "[.03515,-.07467]",625        "[-.67319,.34442]",626        "[-.74543,.11301]"627    ],628	"_cloudIterationCyclerId": null,629	"drawMandelbrot": function(params) {630		this.assignParams( params );631		var canvasContext = this.canvas_2d.getContext("2d");632		var canvasImageData = canvasContext.getImageData(0, 0, this.canvas_2d.width, this.canvas_2d.height);633		this.xScale_2d = Math.abs( this.startX - this.endX ) / this.canvas_2d.width;634		this.yScale_2d = Math.abs( this.startY - this.endY ) / this.canvas_2d.height;635		this.xOffset = 0 - ( this.startX / this.xScale_2d );636		this.yOffset = this.startY / this.yScale_2d;637		// FIX THIS638var repeatCheck = function(zValues, z, lastZ){639	var test = zValues.filter(function(testZ){640		return z[0] != testZ[0] && z[1] != testZ[1];641	});642	return zValues.length != test.length;643};644		//var juliaC = eval(this.juliaC);645		for( var xValue = this.startX, imageX = 0; imageX < this.canvas_2d.width; xValue += this.xScale_2d, imageX++ ){646			for( var yValue = this.startY, imageY = 0; imageY < this.canvas_2d.height; yValue -= this.yScale_2d, imageY++ ){647				var c = [xValue, yValue];648				var juliaC = eval(this.juliaC);649				var color;650				if( this.getAbsoluteValueOfComplexNumber( juliaC ) != 0 ){651					color = this.getJuliaEscapePathLengthColor( juliaC, c, this.maxIterations_2d, null, true, repeatCheck );				652				}653				else{654					color = this.getJuliaEscapePathLengthColor( c, juliaC, this.maxIterations_2d, null, true, repeatCheck );				655				}656				this.setPixel( canvasImageData, imageX, imageY, color );657			}658		}659		canvasContext.putImageData(canvasImageData,0,0);660	},661	"clearMandelbrotCloud": function(){662		for( var index = this.particleSystems.length - 1; index >= 0; index-- ){663			if(!this.particleSystems[index]){continue;}664			this.scene.remove(this.particleSystems[index]);665			this.particleSystems[index] = null;666			delete this.particleSystems[index];667		}668		669		this.particleSystems = [];670	},671    "cloudMethods_CLEANUP": {672        "functionsFromEval": {},673        "evalInitialZ": function(escapePath) {674            if( typeof mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.initialZ === 'undefined' ) {675                if (mandelbrotExplorer.initialZ) {676                    eval("mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.initialZ = function (){\n " + mandelbrotExplorer.initialZ + "\n}");677                } else {678                    mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.initialZ = function(){679                        return 0;680                    };681                }682            }683            684            return mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.initialZ();685        },686        "processCloudLengthFilter": function(pathIndex, iteration, escapePath){687            if( typeof mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.cloudLengthFilter === 'undefined' ) {688                if (mandelbrotExplorer.cloudLengthFilter) {689                    let functionDefinition = "function (pathIndex, iteration, escapePath){\nreturn " + mandelbrotExplorer.cloudLengthFilter + ";\n}";690                    eval('mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.cloudLengthFilter = ' + functionDefinition + ';');691                } else {692                    mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.cloudLengthFilter = function(){693                        return true;694                    };695                }696            }697            698            return mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.cloudLengthFilter(pathIndex, iteration, escapePath);699        },700        "processCloudIterationFilter": function(pathIndex, iteration, escapePath) {701            if( typeof mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.cloudIterationFilter === 'undefined' ) {702                if (mandelbrotExplorer.cloudIterationFilter) {703                    let functionDefinition = "function (pathIndex, iteration, escapePath){\nreturn " + mandelbrotExplorer.cloudIterationFilter + ";\n}";704                    eval('mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.cloudIterationFilter = ' + functionDefinition + ';');705                } else {706                    mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.cloudIterationFilter = function(){707                        return true;708                    };709                }710            }711            712            return mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.cloudIterationFilter(pathIndex, iteration, escapePath);713        },714        "evalEscapingZ": function (pathIndex, iteration, escapePath) {715            if( typeof mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.escapingZ === 'undefined' ) {716                if (mandelbrotExplorer.escapingZ) {717                    let functionDefinition = "function (pathIndex, iteration, escapePath){\n" 718                            + mandelbrotExplorer.escapingZ 719                        + ";\n}";720                    eval('mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.escapingZ = ' + functionDefinition + ';');721                } else {722                    mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.escapingZ = function(){723                        return 0;724                    };725                }726            }727            728            return mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.escapingZ(pathIndex, iteration, escapePath);729        },730        "processParticleFilter": function (newX, newY, particleVector) {731            if( typeof mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.particleFilter === 'undefined' ) {732                if (mandelbrotExplorer.particleFilter) {733                    let functionDefinition = "function (newX, newY, particleVector){\n" 734                            + "var allowed = " + mandelbrotExplorer.particleFilter + ";\n"735                            + "return {newX: newX, newY: newY, particleVector: particleVector, allowed: allowed};\n"736                        + "}";737                    eval('mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.particleFilter = ' + functionDefinition + ';');738                } else {739                    let functionDefinition = "function (newX, newY, particleVector){\n" 740                            + "var allowed = true;\n"741                            + "return {newX: newX, newY: newY, particleVector: particleVector, allowed: allowed};\n"742                        + "}";743                    eval('mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.particleFilter = ' + functionDefinition + ';');744                }745            }746            747            return mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval.particleFilter(newX, newY, particleVector);748            749            750/*751            var allowed = true752            753            if (mandelbrotExplorer.particleFilter) {754                allowed = eval( mandelbrotExplorer.particleFilter );755            }756            757            758            return {759                newX: newX,760                newY: newY,761                particleVector: particleVector,762                allowed: allowed763            };764*/765        },766        "processDualZMultiplier": function(pathIndex, iteration, escapePath, newX, newY, z) {767            // TODO: Save this and do something about it....768            //1;z=pathIndex == 0 ? z :  mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex-1]) - mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex]);769            //1;z=pathIndex == 0 ? z :  mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex]) - mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex-1]);770			771			var newZ = z;772            var dualZMultiplier = eval(mandelbrotExplorer.dualZMultiplier);773            774            return [newX, newY, newZ];775        },776        "evalJuliaC": function(c) {777            return eval(mandelbrotExplorer.juliaC);778        },779        "handleCloudSteppingAdjustments": function(c){780            if(mandelbrotExplorer.randomizeCloudStepping){781                var getRandomArbitrary = function(min, max) {782                  return Math.random() * (max - min) + min;783                }784                785                c[0] = getRandomArbitrary(c[0] - mandelbrotExplorer.xScale_3d, c[0] + mandelbrotExplorer.xScale_3d);786                c[1] = getRandomArbitrary(c[1] - mandelbrotExplorer.yScale_3d, c[1] + mandelbrotExplorer.yScale_3d);787            }788            789            return c;790        },791        "getEscapePath": function(c) {792            var juliaC = mandelbrotExplorer.cloudMethods_CLEANUP.evalJuliaC(c);793            var repeatCheck = function(zValues, z, lastZ){794                var test = zValues.filter(function(testZ){795                    return z[0] != testZ[0] && z[1] != testZ[1];796                });797                return zValues.length != test.length;798            };799            var escapePath;800            if( mandelbrotExplorer.getAbsoluteValueOfComplexNumber( juliaC ) != 0 ){801                escapePath = mandelbrotExplorer.getJuliaEscapePath( juliaC, c, mandelbrotExplorer.maxIterations_3d, true, repeatCheck );				802            }803            else{804                escapePath = mandelbrotExplorer.getJuliaEscapePath( c, juliaC, mandelbrotExplorer.maxIterations_3d, true, repeatCheck );				805            }806            807            return escapePath;808        },809        "discontinueIterationCycle": function() {810            var result = mandelbrotExplorer.continueIterationCycle;811            mandelbrotExplorer.continueIterationCycle = false;812            return result;813        },814        "startRenderer": function() {815            if( mandelbrotExplorer.renderer == null )	{816                mandelbrotExplorer.renderer = new mandelbrotExplorer.useRenderer(817					{818						canvas: mandelbrotExplorer.canvas_3d,  819						alpha: mandelbrotExplorer.rendererOptions.alpha, 820						precision: mandelbrotExplorer.rendererOptions.precision, 821						antialias: mandelbrotExplorer.rendererOptions.antialias,822						preserveDrawingBuffer: mandelbrotExplorer.rendererOptions.preserveDrawingBuffer823					}824				);825//               mandelbrotExplorer.renderer.xr.enabled  = true;826 827                mandelbrotExplorer.renderer.setClearColor( 0x000001, 0 );	828            }829            830            mandelbrotExplorer.cloudMethods_CLEANUP.startScene();831            mandelbrotExplorer.cloudMethods_CLEANUP.startCamera();832            mandelbrotExplorer.cloudMethods_CLEANUP.startTrackballControls();833        },834        "startScene": function(){835            if( mandelbrotExplorer.scene == null ) {836                mandelbrotExplorer.scene = new THREE.Scene();837            }838            else {839                mandelbrotExplorer.clearMandelbrotCloud();840				mandelbrotExplorer.clearMandelbrotsHair();841            }842        },843        "startCamera": function() {844            if(mandelbrotExplorer.camera == null){845                mandelbrotExplorer.camera = new THREE.PerspectiveCamera( 846                    45, 847                    Math.abs(mandelbrotExplorer.startX - mandelbrotExplorer.endX) / Math.abs(mandelbrotExplorer.startY - mandelbrotExplorer.endY),848                    .1,849                    1000850                );851                mandelbrotExplorer.camera.position.z = 5;852            }853        },854        "startTrackballControls": function() {855            if(mandelbrotExplorer.controls == null){856                mandelbrotExplorer.controls = new THREE.TrackballControls( mandelbrotExplorer.camera, mandelbrotExplorer.renderer.domElement );857            }858        },859        "initialize3DScaling": function() {860			var cloudResolutions = [];861			if(mandelbrotExplorer.cloudResolution.toString().indexOf(",") !== -1){862				cloudResolutions = mandelbrotExplorer.cloudResolution.split(",");863			}864			else{865				cloudResolutions.push(mandelbrotExplorer.cloudResolution);866			}867			var minRes = Math.min.apply(null, cloudResolutions);868			var maxRes = Math.max.apply(null, cloudResolutions);869			870			mandelbrotExplorer.scales_3d = [];871			872			var sosRes = 0;873			cloudResolutions.forEach(874				function(useResolution) {875					sosRes += (useResolution * useResolution);876					mandelbrotExplorer.scales_3d.push({877						x: Math.abs( mandelbrotExplorer.startX - mandelbrotExplorer.endX ) / useResolution, 878						y: Math.abs( mandelbrotExplorer.startY - mandelbrotExplorer.endY ) / useResolution879					});880				}881			)882			883			if(sosRes == 0) {884				sosRes = 43;885			}886			// TODO: I want to allow for multiple scales in the same render...887            mandelbrotExplorer.xScale_3d = Math.abs( mandelbrotExplorer.startX - mandelbrotExplorer.endX ) / Math.sqrt(sosRes);888            mandelbrotExplorer.yScale_3d = Math.abs( mandelbrotExplorer.startY - mandelbrotExplorer.endY ) / Math.sqrt(sosRes);889			890        },891        "initializeMandelbrotCloud": function(){892            mandelbrotExplorer.cloudMethods_CLEANUP.startRenderer();893            mandelbrotExplorer.cloudMethods_CLEANUP.initialize3DScaling();894            895            896            mandelbrotExplorer.iterationParticles = [];897            mandelbrotExplorer.particleSystems = [];898            mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval = {};899        },900		"initializeMandelbrotHair": function(){901			mandelbrotExplorer.cloudMethods_CLEANUP.startRenderer();902            mandelbrotExplorer.cloudMethods_CLEANUP.initialize3DScaling();903            904            905			mandelbrotExplorer.iterationParticles = [];906			mandelbrotExplorer.lines = [];907			mandelbrotExplorer.lineVectors = [];908			909            mandelbrotExplorer.cloudMethods_CLEANUP.functionsFromEval = {};910		},911        "generateMandelbrotCloudParticles": function() {912            console.time("drawMandelbrotCloud: Generating particles");913			914			mandelbrotExplorer.scales_3d.forEach(function(useScales){915			916				for( var x = mandelbrotExplorer.startX; x < mandelbrotExplorer.endX; x += (useScales.x) ) {917					for( var y = mandelbrotExplorer.startY; y > mandelbrotExplorer.endY; y -= (useScales.y) ) {918						var c = mandelbrotExplorer.cloudMethods_CLEANUP.handleCloudSteppingAdjustments([x,y]);919						920						var escapePath = mandelbrotExplorer.cloudMethods_CLEANUP.getEscapePath(c);921						if(922							(mandelbrotExplorer.onlyShortened && !escapePath.shortened) ||923							(mandelbrotExplorer.onlyFull && escapePath.shortened)924						){925							continue;926						}927						var z = mandelbrotExplorer.cloudMethods_CLEANUP.evalInitialZ(escapePath);928						var accumulatedZ = 0;929						var averageOfAccumulatedZ = 0;930						escapePath.forEach(function(pathValue, pathIndex, source){931							accumulatedZ += mandelbrotExplorer.getAbsoluteValueOfComplexNumber(escapePath[pathIndex]);932							averageOfAccumulatedZ = accumulatedZ / (pathIndex + 1)933							var iteration = pathIndex + 1;934							if (935								!mandelbrotExplorer.cloudMethods_CLEANUP.processCloudLengthFilter(pathIndex, iteration, escapePath) ||936								!mandelbrotExplorer.cloudMethods_CLEANUP.processCloudIterationFilter(pathIndex, iteration, escapePath)937							){938								return true;939							}940							if( pathIndex != 0 ) {941								// FIX THE FUCK OUT OF THIS!942								z = mandelbrotExplorer.cloudMethods_CLEANUP.evalEscapingZ(pathIndex, iteration, escapePath);// eval( mandelbrotExplorer.escapingZ );943							}944							945							var iterationIndex = parseInt(pathIndex);946							947							if( typeof mandelbrotExplorer.iterationParticles[iterationIndex] === "undefined" ) {948								mandelbrotExplorer.iterationParticles[iterationIndex] = {"particles": new THREE.Geometry()};949							}950							var newX = escapePath[pathIndex][0];951							var newY = escapePath[pathIndex][1];952							var particleVector = new THREE.Vector3(newX, newY, z);953							var particleFilterResult = mandelbrotExplorer.cloudMethods_CLEANUP.processParticleFilter(newX, newY, particleVector);954							if (!particleFilterResult['allowed']) {955								return true;956							}957							958							mandelbrotExplorer.iterationParticles[iterationIndex].particles.vertices.push(particleFilterResult.particleVector);959							960							// Why was I trying to catch the floating point error?961							if(typeof mandelbrotExplorer.iterationParticles[iterationIndex].fpe === "undefined"){962								mandelbrotExplorer.iterationParticles[iterationIndex].fpe = 0;963							}964							mandelbrotExplorer.iterationParticles[iterationIndex].fpe += pathValue.fpe;965							966							967							if(mandelbrotExplorer.dualZ){968								var newX = particleFilterResult.newX;969								var newY = particleFilterResult.newY;970								var coords = mandelbrotExplorer.cloudMethods_CLEANUP.processDualZMultiplier(pathIndex, iteration, escapePath, newX, newY, z);971								var particleVector = new THREE.Vector3(coords[0], coords[1], coords[2]);972								973								mandelbrotExplorer.iterationParticles[iterationIndex].particles.vertices.push(particleVector);974							}975						});976					}977				}978			});979            console.timeEnd("drawMandelbrotCloud: Generating particles");980            981            mandelbrotExplorer.cloudMethods_CLEANUP.applyMandelbrotCloudPalette();982            983            mandelbrotExplorer.iterationParticles = null;984        },985        "applyMandelbrotCloudPalette": function() {986            console.time("drawMandelbrotCloud: Applying palette");987            for( var index in mandelbrotExplorer.iterationParticles ) {988                var color = mandelbrotExplorer.palette[ mandelbrotExplorer.getColorIndex(index) ];989                990                var size = mandelbrotExplorer.particleSize ? eval(mandelbrotExplorer.particleSize): 0;//mandelbrotExplorer.xScale_3dmandelbrotExplorer.xScale_3d >= 0.1 ? 0 : mandelbrotExplorer.xScale_3d/2;//mandelbrotExplorer.iterationParticles[index].fpe / mandelbrotExplorer.xScale_3d;991                //var pMaterial = new THREE.ParticleBasicMaterial({992                var pMaterial = new THREE.PointsMaterial({993                    color: new THREE.Color( color.R / 255, color.G / 255, color.B / 255 ),994                    size: size,//0,995                    transparent: false,996                    opacity: color.A/255997                });998                999                //mandelbrotExplorer.particleSystems[index] = new THREE.ParticleSystem(1000                mandelbrotExplorer.particleSystems[index] = new THREE.Points(1001                    mandelbrotExplorer.iterationParticles[parseInt(index)].particles,1002                    pMaterial);1003                1004                mandelbrotExplorer.iterationParticles[parseInt(index)] = null;1005            }1006            console.timeEnd("drawMandelbrotCloud: Applying palette");1007        },1008		"generateMandelbrotHair": function () {1009			1010			1011			// FUCKING FIX THIS1012			//var juliaC = mandelbrotExplorer.cloudMethods_CLEANUP.evalJuliaC();1013			console.time("drawMandelbrotsHair: Generating line vectors");1014			mandelbrotExplorer.scales_3d.forEach(function(useScales){1015				for( var x = mandelbrotExplorer.startX; x < mandelbrotExplorer.endX; x += useScales.x ) {1016					for( var y = mandelbrotExplorer.startY; y > mandelbrotExplorer.endY; y -= useScales.y ) {1017						var c = [x,y];1018						var juliaC = mandelbrotExplorer.cloudMethods_CLEANUP.evalJuliaC();1019						if(mandelbrotExplorer.randomizeCloudStepping){1020							var getRandomArbitrary = function(min, max) {1021							  return Math.random() * (max - min) + min;1022							}1023							1024							c[0] = getRandomArbitrary(x - mandelbrotExplorer.xScale_3d, x + mandelbrotExplorer.xScale_3d);1025							c[1] = getRandomArbitrary(y - mandelbrotExplorer.xScale_3d, y + mandelbrotExplorer.xScale_3d);1026						}1027						var repeatCheck = function(zValues, z, lastZ){1028							var test = zValues.filter(function(testZ){1029								return z[0] != testZ[0] && z[1] != testZ[1];1030							});1031							return zValues.length != test.length;1032						};1033						//var escapePath = mandelbrotExplorer.getMandelbrotEscapePath( c, mandelbrotExplorer.maxIterations_3d );1034						var escapePath;1035						if( mandelbrotExplorer.getAbsoluteValueOfComplexNumber( juliaC ) != 0 ){1036							escapePath = mandelbrotExplorer.getJuliaEscapePath( juliaC, c, mandelbrotExplorer.maxIterations_3d, true, repeatCheck );				1037						}1038						else{1039							escapePath = mandelbrotExplorer.getJuliaEscapePath( c, juliaC, mandelbrotExplorer.maxIterations_3d, true, repeatCheck );				1040						}1041						if((mandelbrotExplorer.onlyShortened && !escapePath.shortened) ||1042						   (mandelbrotExplorer.onlyFull && escapePath.shortened)){continue;}1043						// FIX THIS STUPID SHIT1044						var z = mandelbrotExplorer.cloudMethods_CLEANUP.evalInitialZ(escapePath);1045						var accumulatedZ = 0;1046						var averageOfAccumulatedZ = 0;1047						1048						var lineVectors = [];1049						escapePath.forEach(function(pathValue, pathIndex, source){1050							var iteration = pathIndex + 1;1051							1052							// COME THE FUCK ON, FIX THIS SHIT!1053							if( mandelbrotExplorer.cloudLengthFilter.length > 0 && eval( mandelbrotExplorer.cloudLengthFilter ) == false ) return true;1054							if( mandelbrotExplorer.cloudIterationFilter.length > 0 && eval( mandelbrotExplorer.cloudIterationFilter ) == false ) return true;1055							var direction = [1,1];1056							if(pathIndex > 0){1057								direction[0] = escapePath[pathIndex][0] > escapePath[pathIndex-1][0] ? -1 : 1;1058								direction[1] = escapePath[pathIndex][1] > escapePath[pathIndex-1][1] ? -1 : 1;1059							}1060							// this isn't right.... zDirection...1061							var zDirection = direction[0] * direction[1];1062							1063							if( pathIndex != 0 ) {1064								// FIX THE FUCK OUT OF THIS!1065								//z = eval( mandelbrotExplorer.escapingZ );1066								z = mandelbrotExplorer.cloudMethods_CLEANUP.evalEscapingZ(pathIndex, iteration, escapePath);// eval( mandelbrotExplorer.escapingZ );1067							}1068							1069							var iterationIndex = parseInt(pathIndex);1070							1071							if( typeof mandelbrotExplorer.iterationParticles[iterationIndex] === "undefined" ) {1072								mandelbrotExplorer.iterationParticles[iterationIndex] = {"particles": new THREE.Geometry()};1073							}1074							var newX = escapePath[pathIndex][0];1075							var newY = escapePath[pathIndex][1];1076							var particleVector = new THREE.Vector3(newX, newY, z);1077							if(mandelbrotExplorer.particleFilter){1078								// FIX THE FUCK OUT OF THIS!1079								var allowed = eval( mandelbrotExplorer.particleFilter );1080								if( !allowed ){1081									return true;1082								}1083							}1084							lineVectors.push(particleVector);1085						});1086						if(lineVectors.length > 1){1087							mandelbrotExplorer.lineVectors.push(lineVectors);1088						}1089					}1090				}1091			});1092			console.timeEnd("drawMandelbrotsHair: Generating line vectors");1093			for(var lineIndex in mandelbrotExplorer.lineVectors){1094				var currentLine = mandelbrotExplorer.lineVectors[lineIndex];1095				1096				var color = mandelbrotExplorer.palette[ mandelbrotExplorer.getColorIndex(lineIndex) ];1097				var geometry = new THREE.Geometry();1098				var curve = new THREE.CatmullRomCurve3(currentLine, false, 'chordal' );1099				geometry.vertices = curve.getPoints(50);1100				1101				//gradientline.js1102				var steps = 0.2;1103				var phase = 1.5;1104				//Create the final object to add to the scene1105				var coloredLine = getColoredBufferLine_2( steps, phase, geometry, color );1106				var coloredLine = getColoredBufferLine_3(geometry, mandelbrotExplorer.palette );1107				1108				mandelbrotExplorer.scene.add(coloredLine);1109				mandelbrotExplorer.lines.push(coloredLine);1110			}1111			//console.timeEnd("drawMandelbrotsHair");1112		}1113    },1114	"drawMandelbrotCloud": function( params ) {1115		console.time("drawMandelbrotCloud");1116		mandelbrotExplorer.assignParams( params );1117        1118        mandelbrotExplorer.cloudMethods_CLEANUP.initializeMandelbrotCloud();1119        1120		var resumeIterationCycle = mandelbrotExplorer.cloudMethods_CLEANUP.discontinueIterationCycle();1121        1122        mandelbrotExplorer.cloudMethods_CLEANUP.generateMandelbrotCloudParticles();1123		1124		mandelbrotExplorer.displayCloudParticles();1125		mandelbrotExplorer.continueIterationCycle = resumeIterationCycle;1126		console.timeEnd("drawMandelbrotCloud");1127	},1128	"clearMandelbrotsHair": function(){1129		for( var index = this.lines.length - 1; index >= 0; index-- ){1130			if(!this.lines[index]){continue;}1131			this.scene.remove(this.lines[index]);1132			this.lines[index] = null;1133			delete this.lines[index];1134		}1135		1136		this.lines = [];1137	},1138	"drawMandelbrotsHair": function( params ) {1139		console.time("drawMandelbrotsHair");1140		mandelbrotExplorer.assignParams( params );1141        1142        mandelbrotExplorer.cloudMethods_CLEANUP.initializeMandelbrotHair();1143        1144		var resumeIterationCycle = mandelbrotExplorer.cloudMethods_CLEANUP.discontinueIterationCycle();1145		1146		if( mandelbrotExplorer.renderer == null )	{1147			mandelbrotExplorer.renderer = new mandelbrotExplorer.useRenderer(1148				{1149					canvas: mandelbrotExplorer.canvas_3d,  1150					alpha: mandelbrotExplorer.rendererOptions.alpha, 1151					precision: mandelbrotExplorer.rendererOptions.precision, 1152					antialias: mandelbrotExplorer.rendererOptions.antialias,1153					preserveDrawingBuffer: mandelbrotExplorer.rendererOptions.preserveDrawingBuffer1154				}1155			);1156			mandelbrotExplorer.renderer.setClearColor( 0x000001, 0 );	1157		}1158		1159		if( mandelbrotExplorer.scene == null ) {1160			mandelbrotExplorer.scene = new THREE.Scene();1161		}1162		else {1163			mandelbrotExplorer.clearMandelbrotsHair();1164		}1165		1166		if(mandelbrotExplorer.camera == null){1167			mandelbrotExplorer.camera = new THREE.PerspectiveCamera( 45, Math.abs(mandelbrotExplorer.startX - mandelbrotExplorer.endX) / Math.abs(mandelbrotExplorer.startY - mandelbrotExplorer.endY), .1, 1000 );1168			mandelbrotExplorer.camera.position.z = 5;1169		}1170		1171		if(mandelbrotExplorer.controls == null){1172			mandelbrotExplorer.controls = new THREE.TrackballControls( mandelbrotExplorer.camera, mandelbrotExplorer.renderer.domElement );1173		}1174		1175		1176		mandelbrotExplorer.xScale_3d = Math.abs( mandelbrotExplorer.startX - mandelbrotExplorer.endX ) / mandelbrotExplorer.cloudResolution;1177		mandelbrotExplorer.yScale_3d = Math.abs( mandelbrotExplorer.startY - mandelbrotExplorer.endY ) / mandelbrotExplorer.cloudResolution;1178		1179		mandelbrotExplorer.iterationParticles = [];1180		//mandelbrotExplorer.particleSystems = [];1181		mandelbrotExplorer.lines = [];1182		mandelbrotExplorer.lineVectors = [];1183		1184		mandelbrotExplorer.cloudMethods_CLEANUP.generateMandelbrotHair();1185		console.timeEnd("drawMandelbrotsHair");1186	},1187	"displayCloudParticles": function() {1188		mandelbrotExplorer.particleCount = 0;1189		//var vertexCounts = [];1190		1191		for( var index = this.particleSystems.length - 1; index >= 0; index-- ){1192			if(!this.particleSystems[index]){continue;}1193			var iteration = index + 1;1194			this.scene.remove(this.particleSystems[index]);1195			if( mandelbrotExplorer.particleCount + this.particleSystems[index].geometry.vertices.length <= this.particleLimit ){1196				mandelbrotExplorer.particleCount += this.particleSystems[index].geometry.vertices.length;1197				this.scene.add(this.particleSystems[index]);1198			}1199		}1200	},1201	"getMandelbrotEscapePathLengthColor": function(c, maxIterations, palette){1202		if( typeof( palette ) == "undefined" || !palette ){1203			palette = this.palette;1204		}1205		var escapePath = this.getMandelbrotEscapePath(c, maxIterations);1206		var index = escapePath.length % palette.length;1207		1208		return palette[ index ];1209	},1210	"getJuliaEscapePathLengthColor": function(c, z, maxIterations, palette, bailOnRepeat, repeatCheck){1211		if( typeof( palette ) == "undefined" || !palette ){1212			palette = this.palette;1213		}1214		var escapePath = this.getJuliaEscapePath(c, z, maxIterations, bailOnRepeat, repeatCheck);1215		var index = escapePath.length % palette.length;1216//		if(escapePath.shortened == 0){1217//			return {"B": 255, "R": 255, "G":  255, "A":0}1218//		}1219//		else{1220			return palette[ index ];1221//		}1222		1223	},1224	"assignParams": function(params) {1225		for( var property in params ){1226			this[ property ] = params[ property ];1227		}1228	},1229	"setPixel": function( imageData, x, y, c ){1230		var i = ((y * imageData.width) + x) * 4;1231		if( i + 3 < (imageData.width * imageData.height * 4) ){1232			imageData.data[i]=c.R;1233			imageData.data[i+1]=c.G;1234			imageData.data[i+2]=c.B;1235			imageData.data[i+3]=c.A;1236		}1237	},1238	"cycle2dColors": function(){1239		var startTime = new Date();1240		1241		var canvasContext = this.canvas_2d.getContext("2d");1242		var canvasImageData = canvasContext.getImageData(0, 0, this.canvas_2d.width, this.canvas_2d.height);1243		var index, currentColor, currentColorIndex, nextColorIndex, nextColor1244		for( var pixel = 0; pixel < ( canvasImageData.height * canvasImageData.width ); pixel++ ){1245			index = pixel * 4;1246			currentColor = {1247				"R": canvasImageData.data[ index ],1248				"G": canvasImageData.data[ index + 1 ],1249				"B": canvasImageData.data[ index + 2 ],1250				"A": canvasImageData.data[ index + 3 ]1251			};1252			1253			currentColorIndex =  palettes.getColorIndex(this.palette, currentColor);// this.palette.indexOf( currentColor );1254			nextColorIndex = currentColorIndex + 1;1255			while( nextColorIndex >= this.palette.length ){1256				nextColorIndex -= this.palette.length;1257			}1258			nextColor = this.palette[nextColorIndex];1259			1260			canvasImageData.data[ index ] = nextColor.R;1261			canvasImageData.data[ index + 1 ] = nextColor.G;1262			canvasImageData.data[ index + 2 ] = nextColor.B;1263			canvasImageData.data[ index + 3 ] = nextColor.A;1264		}1265		canvasContext.putImageData(canvasImageData,0,0);1266		1267		this.cycleTime = (new Date()) - startTime;1268		if( this.continueColorCycle ){1269			setTimeout( function(){mandelbrotExplorer.cycle2dColors();}, this.iterationCycleTime )1270		}1271	},1272	"cycleCloudColors": function(){1273		var startTime = new Date();1274		var index, currentColor, currentColorIndex, nextColorIndex, nextColor1275				1276		for( var index = 0; index < this.particleSystems.length; index++ )1277		{1278			if(!this.particleSystems[index] || !this.particleSystems[index].material){ continue; };1279			var materialColor = this.particleSystems[index].material.color;1280			1281			currentColor = {1282				"R": materialColor.r * 255,1283				"G": materialColor.g * 255,1284				"B": materialColor.b * 255,1285				"A": 2551286			};1287			1288			currentColorIndex =  palettes.getColorIndex(this.palette, currentColor);// this.palette.indexOf( currentColor );1289			nextColorIndex = currentColorIndex + 1;1290			while( nextColorIndex >= this.palette.length )1291			{1292				nextColorIndex -= this.palette.length;1293			}1294			nextColor = this.palette[nextColorIndex];1295			1296			this.particleSystems[index].material.color.setHex(parseInt( "0x" + this.padString( nextColor.R.toString(16), 2, "0", STR_PAD_LEFT )1297									  + this.padString( nextColor.G.toString(16), 2, "0", STR_PAD_LEFT )1298									  + this.padString( nextColor.B.toString(16), 2, "0", STR_PAD_LEFT )1299								, 16));1300		}1301		1302		this.cycleTime = (new Date()) - startTime;1303		if( this.continueColorCycle )1304		{1305			setTimeout( function(){mandelbrotExplorer.cycleCloudColors();}, this.iterationCycleTime )1306		}1307	},1308	"cycleCloudIterations": function() {1309		var particleCount = 0;1310		var foundNext = false;1311		var particleSystemsLength = this.particleSystems.length;1312		var cycleDirection = 1;1313		while( particleSystemsLength > 0 && foundNext == false ){1314			for( var index = 0; index < particleSystemsLength; index++ ){1315				this.scene.remove( this.particleSystems[index] );1316				var iteration = index + 1;1317				// FUCKING FIX IT1318				if( this.cloudIterationFilter.length > 0 && eval( this.cloudIterationFilter ) == false ) continue;1319				1320				if( this.particleSystems[index] && 1321					iteration >= this.nextCycleIteration - (this.iterationCycleFrame/2) && 1322					iteration <= this.nextCycleIteration + (this.iterationCycleFrame/2) 1323				  ){1324					foundNext = true;1325					particleCount += this.particleSystems[index].geometry.vertices.length;1326					this.scene.add( this.particleSystems[index] );1327				}1328			}1329			this.nextCycleIteration += cycleDirection;1330			1331			if(this.nextCycleIteration > this.particleSystems.length || this.nextCycleIteration < 0){1332				cycleDirection *= -1;1333			}1334			1335			while( this.nextCycleIteration > this.particleSystems.length )1336			{1337				this.nextCycleIteration -= this.particleSystems.length;1338			}1339		}1340		1341		if( this.continueIterationCycle ){1342			this._cloudIterationCyclerId = setTimeout( function(){mandelbrotExplorer.cycleCloudIterations();}, this.iterationCycleTime )1343		}1344		1345	},1346	"setPalette": function( newPalette ) {1347		var canvasContext = this.canvas_2d.getContext("2d");1348		var canvasImageData = canvasContext.getImageData(0, 0, this.canvas_2d.width, this.canvas_2d.height);1349		var index, currentColor, currentColorIndex, nextColorIndex, nextColor1350		for( var pixel = 0; pixel < ( canvasImageData.height * canvasImageData.width ); pixel++ )1351		{1352			index = pixel * 4;1353			currentColor = {1354				"R": canvasImageData.data[ index ],1355				"G": canvasImageData.data[ index + 1 ],1356				"B": canvasImageData.data[ index + 2 ],1357				"A": canvasImageData.data[ index + 3 ]1358			};1359			1360			currentColorIndex =  palettes.getColorIndex(this.palette, currentColor);// this.palette.indexOf( currentColor );1361			nextColorIndex = currentColorIndex + 1;1362			while( nextColorIndex >= newPalette.length )1363			{1364				nextColorIndex -= newPalette.length;1365			}1366			nextColor = newPalette[nextColorIndex];1367			1368			canvasImageData.data[ index ] = nextColor.R;1369			canvasImageData.data[ index + 1 ] = nextColor.G;1370			canvasImageData.data[ index + 2 ] = nextColor.B;1371			canvasImageData.data[ index + 3 ] = nextColor.A;1372		}1373		canvasContext.putImageData(canvasImageData,0,0);1374		1375		for( var index = 0; index < this.particleSystems.length; index++ ){1376			if(!this.particleSystems[index]){continue;}1377			var materialColor = this.particleSystems[index].material.color;1378			1379			currentColor = {1380				"R": materialColor.r * 255,1381				"G": materialColor.g * 255,1382				"B": materialColor.b * 255,1383				"A": this.particleSystems[index].material.opacity * 2551384			};1385			1386			currentColorIndex =  palettes.getColorIndex(this.palette, currentColor);1387			nextColorIndex = currentColorIndex + 1;1388			while( nextColorIndex >= newPalette.length ){1389				nextColorIndex -= newPalette.length;1390			}1391			nextColor = newPalette[nextColorIndex];1392			1393			this.particleSystems[index].material.color.setHex(parseInt( "0x" + this.padString( nextColor.R.toString(16), 2, "0", STR_PAD_LEFT )1394									  + this.padString( nextColor.G.toString(16), 2, "0", STR_PAD_LEFT )1395									  + this.padString( nextColor.B.toString(16), 2, "0", STR_PAD_LEFT )1396								, 16));1397		}1398		1399		this.palette = newPalette;1400	},1401	"getPixel": function(imageData,x,y){1402		var i = ((y * imageData.width) + x) * 4;1403		if( i + 3 < imageData.width * imageData.height ){1404			return {R:imageData.data[i],1405				  G:imageData.data[i+1],1406				  B:imageData.data[i+2],1407				  A:imageData.data[i+3]}1408		}1409		return false;1410	},1411	"getMandelbrotEscapePath": function( c, maxIterations, bailOnRepeat ){1412		if(typeof(bailOnRepeat) == "undefined"){1413			bailOnRepeat = true;1414		}1415		1416		return this.getJuliaEscapePath( c, [0,0], maxIterations, bailOnRepeat );1417	},1418	"getJuliaEscapePath": function( c, z, maxIterations, bailOnRepeat, repeatCheck ){1419		if(typeof(bailOnRepeat) === "undefined"){1420			bailOnRepeat = true;1421		}1422		1423		if(typeof(repeatCheck) === "undefined"){1424			repeatCheck = function(zValues, z, lastZ){1425				return z[0] == lastZ[0] && z[1] == lastZ[1];1426			};1427		}1428		1429		var iterations = 0;1430		var zValues = Array();1431		if( this.getAbsoluteValueOfComplexNumber(z) != 0 ){1432			zValues.push(z);1433		}1434		1435		var lastZ = [null, null];1436		var limit = 2;1437		while( this.getAbsoluteValueOfComplexNumber(z) < limit && iterations < maxIterations ){1438			iterations++;1439			var zX = Math.pow(z[0], 2) - Math.pow(z[1], 2) + c[0];1440			var zY = (2*z[0]*z[1]) + c[1];1441			z = [zX, zY];1442			1443			z.fpe = Math.abs((z[0] - Math.sqrt(Math.pow(z[0], 2))) + (z[1] - Math.sqrt(Math.pow(z[1], 2))));1444			1445			zValues.push(z);1446			1447			lastZ = z;1448		}1449		var fullLength = zValues.length;1450		zValues = zValues.filter(function(teztZ, testZIndex, testZValues){1451			for ( var zi = 0; zi < testZIndex; zi++ ){1452				if(teztZ[0] == testZValues[zi][0] && teztZ[1] == testZValues[zi][1]){1453					return false;1454				}1455			}1456			return true;1457		})1458		zValues.shortened = fullLength - zValues.length;1459		return zValues;1460	},1461    "getColorIndex": function(index) {1462        var colorIndex = index;1463        while( colorIndex >= mandelbrotExplorer.palette.length  ) {1464            colorIndex -= mandelbrotExplorer.palette.length;1465        }1466        return colorIndex;1467    },1468	"getJuliaEscapePath_orig": function( c, z, maxIterations, bailOnRepeat, repeatCheck ){1469		if(typeof(bailOnRepeat) === "undefined"){1470			bailOnRepeat = true;1471		}1472		1473		if(typeof(repeatCheck) === "undefined"){1474			repeatCheck = function(zValues, z, lastZ){1475				return z[0] == lastZ[0] && z[1] == lastZ[1];1476			};1477		}1478		1479		var iterations = 0;1480		var zValues = Array();1481		if( this.getAbsoluteValueOfComplexNumber(z) != 0 ){1482			zValues.push(z);1483		}1484		1485		var lastZ = [null, null];1486		var limit = 2;1487		while( this.getAbsoluteValueOfComplexNumber(z) < limit && iterations < maxIterations ){1488			iterations++;1489			var zX = Math.pow(z[0], 2) - Math.pow(z[1], 2) + c[0];1490			var zY = (2*z[0]*z[1]) + c[1];1491			z = [zX, zY];1492			/* This isn't right, but it is fun, do something about finding repeating patterns */1493			if(bailOnRepeat && repeatCheck(zValues, z, lastZ)){1494				iterations = maxIterations;1495			}1496			else{1497				zValues.push(z);1498			}1499			1500			lastZ = z;1501		}1502		1503		return zValues;1504	},1505	"runJuliaCalc": function( c, z, maxIterations, verbose ){1506		if(verbose){console.time("runJuliaCalc");}1507		var iterations = 0;1508		while( this.getAbsoluteValueOfComplexNumber(z) < 2 && iterations < maxIterations ){1509			iterations++;1510			var zX = Math.pow(z[0], 2) - Math.pow(z[1], 2) + c[0];1511			var zY = (2*z[0]*z[1]) + c[1];1512			z = [zX, zY];1513		}1514		1515		if(verbose){console.timeEnd("runJuliaCalc");}1516	},1517	"getAbsoluteValueOfComplexNumber": function( c ){1518		return Math.sqrt( Math.abs( Math.pow(c[0], 2) + Math.pow(c[1],2) ) );1519	},1520	"padString": function (str, len, pad, dir) {1521		if (typeof(len) == "undefined") { var len = 0; }1522		if (typeof(pad) == "undefined") { var pad = ' '; }1523		if (typeof(dir) == "undefined") { var dir = STR_PAD_RIGHT; }1524		if (len + 1 >= str.length) {1525			switch (dir){1526				case STR_PAD_LEFT:1527					str = Array(len + 1 - str.length).join(pad) + str;1528					break;1529				case STR_PAD_BOTH:1530					var right = Math.ceil((padlen = len - str.length) / 2);1531					var left = padlen - right;1532					str = Array(left+1).join(pad) + str + Array(right+1).join(pad);1533					break;1534				default:1535					str = str + Array(len + 1 - str.length).join(pad);1536					break;1537			}1538		}1539		1540		return str;1541	}...

Full Screen

Full Screen

FileUtil.js

Source:FileUtil.js Github

copy

Full Screen

...73function save(path, data) {74    if (exists(path)) {75        remove(path);76    }77    path = escapePath(path);78    textTemp[path] = data;79    createDirectory(Path.dirname(path));80    FS.writeFileSync(path, data, { encoding: charset });81}82exports.save = save;83function writeFileAsync(path, content, charset) {84    return new Promise(function (resolve, reject) {85        FS.writeFile(path, content, { encoding: charset }, function (err) {86            if (err) {87                reject(err);88            }89            else {90                resolve(true);91            }92        });93    });94}95exports.writeFileAsync = writeFileAsync;96/**97 * 创建文件夹98 */99function createDirectory(path, mode) {100    path = escapePath(path);101    if (mode === undefined) {102        mode = 511 & (~process.umask());103    }104    if (typeof mode === 'string')105        mode = parseInt(mode, 8);106    path = Path.resolve(path);107    try {108        FS.mkdirSync(path, mode);109    }110    catch (err0) {111        switch (err0.code) {112            case 'ENOENT':113                createDirectory(Path.dirname(path), mode);114                createDirectory(path, mode);115                break;116            default:117                var stat;118                try {119                    stat = FS.statSync(path);120                }121                catch (err1) {122                    throw err0;123                }124                if (!stat.isDirectory())125                    throw err0;126                break;127        }128    }129}130exports.createDirectory = createDirectory;131var textTemp = {};132/**133 * 读取文本文件,返回打开文本的字符串内容,若失败,返回"".134 * @param path 要打开的文件路径135 */136function read(path, ignoreCache) {137    if (ignoreCache === void 0) { ignoreCache = false; }138    path = escapePath(path);139    var text = textTemp[path];140    if (text && !ignoreCache) {141        return text;142    }143    try {144        text = FS.readFileSync(path, charset);145        text = text.replace(/^\uFEFF/, '');146    }147    catch (err0) {148        return "";149    }150    if (text) {151        var ext = getExtension(path).toLowerCase();152        if (ext == "ts" || ext == "exml") {153            textTemp[path] = text;154        }155    }156    return text;157}158exports.read = read;159function readFileAsync(path, charset) {160    return new Promise(function (resolve, reject) {161        FS.readFile(path, charset, function (err, data) {162            if (err) {163                reject(err);164            }165            else {166                resolve(data);167            }168        });169    });170}171exports.readFileAsync = readFileAsync;172/**173 * 读取字节流文件,返回字节流,若失败,返回null.174 * @param path 要打开的文件路径175 */176function readBinary(path) {177    path = escapePath(path);178    try {179        var binary = FS.readFileSync(path);180    }181    catch (e) {182        return null;183    }184    return binary;185}186exports.readBinary = readBinary;187/**188 * 复制文件或目录189 * @param source 文件源路径190 * @param dest 文件要复制到的目标路径191 */192function copy(source, dest) {193    source = escapePath(source);194    dest = escapePath(dest);195    var stat = FS.lstatSync(source);196    if (stat.isDirectory()) {197        _copy_dir(source, dest);198    }199    else {200        _copy_file(source, dest);201    }202}203exports.copy = copy;204function isDirectory(path) {205    path = escapePath(path);206    try {207        var stat = FS.statSync(path);208    }209    catch (e) {210        return false;211    }212    return stat.isDirectory();213}214exports.isDirectory = isDirectory;215function isSymbolicLink(path) {216    path = escapePath(path);217    try {218        var stat = FS.statSync(path);219    }220    catch (e) {221        return false;222    }223    return stat.isSymbolicLink();224}225exports.isSymbolicLink = isSymbolicLink;226function isFile(path) {227    path = escapePath(path);228    try {229        var stat = FS.statSync(path);230    }231    catch (e) {232        return false;233    }234    return stat.isFile();235}236exports.isFile = isFile;237function _copy_file(source_file, output_file) {238    createDirectory(Path.dirname(output_file));239    var byteArray = FS.readFileSync(source_file);240    FS.writeFileSync(output_file, byteArray);241}242function _copy_dir(sourceDir, outputDir) {243    createDirectory(outputDir);244    var list = readdirSync(sourceDir);245    list.forEach(function (fileName) {246        copy(Path.join(sourceDir, fileName), Path.join(outputDir, fileName));247    });248}249/**250 * 删除文件或目录251 * @param path 要删除的文件源路径252 */253function remove(path) {254    path = escapePath(path);255    try {256        FS.lstatSync(path).isDirectory()257            ? rmdir(path)258            : FS.unlinkSync(path);259        getDirectoryListing(path);260    }261    catch (e) {262    }263}264exports.remove = remove;265function rmdir(path) {266    var files = [];267    if (FS.existsSync(path)) {268        files = readdirSync(path);269        files.forEach(function (file) {270            var curPath = path + "/" + file;271            if (FS.statSync(curPath).isDirectory()) {272                rmdir(curPath);273            }274            else {275                FS.unlinkSync(curPath);276            }277        });278        FS.rmdirSync(path);279    }280}281function rename(oldPath, newPath) {282    if (isDirectory(oldPath)) {283        FS.renameSync(oldPath, newPath);284    }285}286exports.rename = rename;287/**288 * 返回指定文件的父级文件夹路径,返回字符串的结尾已包含分隔符。289 */290function getDirectory(path) {291    path = escapePath(path);292    return Path.dirname(path) + "/";293}294exports.getDirectory = getDirectory;295/**296 * 获得路径的扩展名,不包含点字符。297 */298function getExtension(path) {299    path = escapePath(path);300    var index = path.lastIndexOf(".");301    if (index == -1)302        return "";303    var i = path.lastIndexOf("/");304    if (i > index)305        return "";306    return path.substring(index + 1);307}308exports.getExtension = getExtension;309/**310 * 获取路径的文件名(不含扩展名)或文件夹名311 */312function getFileName(path) {313    if (!path)314        return "";315    path = escapePath(path);316    var startIndex = path.lastIndexOf("/");317    var endIndex;318    if (startIndex > 0 && startIndex == path.length - 1) {319        path = path.substring(0, path.length - 1);320        startIndex = path.lastIndexOf("/");321        endIndex = path.length;322        return path.substring(startIndex + 1, endIndex);323    }324    endIndex = path.lastIndexOf(".");325    if (endIndex == -1 || isDirectory(path))326        endIndex = path.length;327    return path.substring(startIndex + 1, endIndex);328}329exports.getFileName = getFileName;330/**331 * 获取指定文件夹下的文件或文件夹列表,不包含子文件夹内的文件。332 * @param path 要搜索的文件夹333 * @param relative 是否返回相对路径,若不传入或传入false,都返回绝对路径。334 */335function getDirectoryListing(path, relative) {336    if (relative === void 0) { relative = false; }337    path = escapePath(path);338    try {339        var list = readdirSync(path);340    }341    catch (e) {342        return [];343    }344    var length = list.length;345    if (!relative) {346        for (var i = length - 1; i >= 0; i--) {347            if (list[i].charAt(0) == ".") {348                list.splice(i, 1);349            }350            else {351                list[i] = joinPath(path, list[i]);352            }353        }354    }355    else {356        for (i = length - 1; i >= 0; i--) {357            if (list[i].charAt(0) == ".") {358                list.splice(i, 1);359            }360        }361    }362    return list;363}364exports.getDirectoryListing = getDirectoryListing;365/**366 * 获取指定文件夹下全部的文件列表,包括子文件夹367 * @param path368 * @returns {any}369 */370function getDirectoryAllListing(path) {371    var list = [];372    if (isDirectory(path)) {373        var fileList = getDirectoryListing(path);374        for (var key in fileList) {375            list = list.concat(getDirectoryAllListing(fileList[key]));376        }377        return list;378    }379    return [path];380}381exports.getDirectoryAllListing = getDirectoryAllListing;382/**383 * 使用指定扩展名搜索文件夹及其子文件夹下所有的文件384 * @param dir 要搜索的文件夹385 * @param extension 要搜索的文件扩展名,不包含点字符,例如:"png"。不设置表示获取所有类型文件。386 */387function search(dir, extension) {388    var list = [];389    try {390        var stat = FS.statSync(dir);391    }392    catch (e) {393        return list;394    }395    if (stat.isDirectory()) {396        findFiles(dir, list, extension, null);397    }398    return list;399}400exports.search = search;401/**402 * 使用过滤函数搜索文件夹及其子文件夹下所有的文件403 * @param dir 要搜索的文件夹404 * @param filterFunc 过滤函数:filterFunc(file:File):Boolean,参数为遍历过程中的每一个文件,返回true则加入结果列表405 */406function searchByFunction(dir, filterFunc, checkDir) {407    var list = [];408    try {409        var stat = FS.statSync(dir);410    }411    catch (e) {412        return list;413    }414    if (stat.isDirectory()) {415        findFiles(dir, list, "", filterFunc, checkDir);416    }417    return list;418}419exports.searchByFunction = searchByFunction;420function readdirSync(filePath) {421    var files = FS.readdirSync(filePath);422    files.sort();423    return files;424}425function findFiles(filePath, list, extension, filterFunc, checkDir) {426    var files = readdirSync(filePath);427    var length = files.length;428    for (var i = 0; i < length; i++) {429        if (files[i].charAt(0) == ".") {430            continue;431        }432        var path = joinPath(filePath, files[i]);433        var exists_1 = FS.existsSync(path);434        if (!exists_1) {435            continue;436        }437        var stat = FS.statSync(path);438        if (stat.isDirectory()) {439            if (checkDir) {440                if (!filterFunc(path)) {441                    continue;442                }443            }444            findFiles(path, list, extension, filterFunc);445        }446        else if (filterFunc != null) {447            if (filterFunc(path)) {448                list.push(path);449            }450        }451        else if (extension) {452            var len = extension.length;453            if (path.charAt(path.length - len - 1) == "." &&454                path.substr(path.length - len, len).toLowerCase() == extension) {455                list.push(path);456            }457        }458        else {459            list.push(path);460        }461    }462}463/**464 * 指定路径的文件或文件夹是否存在465 */466function exists(path) {467    path = escapePath(path);468    return FS.existsSync(path);469}470exports.exists = exists;471/**472 * 转换本机路径为Unix风格路径。473 */474function escapePath(path) {475    if (!path)476        return "";477    return path.split("\\").join("/");478}479exports.escapePath = escapePath;480/**481 * 连接路径,支持传入多于两个的参数。也支持"../"相对路径解析。返回的分隔符为Unix风格。482 */483function joinPath(dir) {484    var filename = [];485    for (var _i = 1; _i < arguments.length; _i++) {486        filename[_i - 1] = arguments[_i];487    }488    var path = Path.join.apply(null, arguments);489    path = escapePath(path);490    return path;491}492exports.joinPath = joinPath;493function getRelativePath(dir, filename) {494    var relative = Path.relative(dir, filename);495    return escapePath(relative);496    ;497}498exports.getRelativePath = getRelativePath;499function basename(p, ext) {500    var path = Path.basename.apply(null, arguments);501    path = escapePath(path);502    return path;503}504exports.basename = basename;505//获取相对路径 to相对于from的路径506function relative(from, to) {507    var path = Path.relative.apply(null, arguments);508    path = escapePath(path);509    return path;510}511exports.relative = relative;512function getAbsolutePath(path) {513    if (Path.isAbsolute(path)) {514        return escapePath(path);515    }516    return joinPath(egret.args.projectDir, path);517}518exports.getAbsolutePath = getAbsolutePath;519function searchPath(searchPaths) {520    for (var _i = 0, searchPaths_1 = searchPaths; _i < searchPaths_1.length; _i++) {521        var searchPath_1 = searchPaths_1[_i];522        if (exists(searchPath_1)) {523            return searchPath_1;524        }525    }526    return null;527}528exports.searchPath = searchPath;...

Full Screen

Full Screen

file.js

Source:file.js Github

copy

Full Screen

...11function save(path,data){12    if(exists(path)) {13        remove(path);14    }15    path = escapePath(path);16    createDirectory(path_lib.dirname(path));17    fs.writeFileSync(path,data,charset);18}19/**20 * 创建文件夹21 */22function createDirectory(path, mode, made) {23    path = escapePath(path);24    if (mode === undefined) {25        mode = 0777 & (~process.umask());26    }27    if (!made) made = null;28    if (typeof mode === 'string')29        mode = parseInt(mode, 8);30    path = path_lib.resolve(path);31    try {32        fs.mkdirSync(path, mode);33        made = made || path;34    }35    catch (err0) {36        switch (err0.code) {37            case 'ENOENT' :38                made = createDirectory(path_lib.dirname(path), mode, made);39                createDirectory(path, mode, made);40                break;41            default:42                var stat;43                try {44                    stat = fs.statSync(path);45                }46                catch (err1) {47                    throw err0;48                }49                if (!stat.isDirectory()) throw err0;50                break;51        }52    }53    return made;54}55var textTemp = {};56/**57 * 读取文本文件,返回打开文本的字符串内容,若失败,返回"".58 * @param path 要打开的文件路径59 */60function read(path) {61    path = escapePath(path);62    var text = textTemp[path];63    if(text){64        return text;65    }66    try{67        text = fs.readFileSync(path,charset);68    }69    catch (err0) {70        return "";71    }72    if(text){73        var ext = getExtension(path).toLowerCase();74        if(ext=="ts"||ext=="exml"){75            textTemp[path] = text;76        }77    }78    return text;79}80/**81 * 读取字节流文件,返回字节流,若失败,返回null.82 * @param path 要打开的文件路径83 */84function readBinary(path) {85    path = escapePath(path);86    try{87        var binary = fs.readFileSync(path);88    }89    catch (e) {90        return null;91    }92    return binary;93}94/**95 * 复制文件或目录96 * @param source 文件源路径97 * @param dest 文件要复制到的目标路径98 */99function copy(source, dest) {100    source = escapePath(source);101    dest = escapePath(dest);102    var stat = fs.lstatSync(source);103    if (stat.isDirectory()) {104        _copy_dir(source, dest);105    }106    else {107        _copy_file(source, dest);108    }109}110function isDirectory(path){111    path = escapePath(path);112    try{113        var stat = fs.statSync(path);114    }115    catch(e){116        return false;117    }118    return stat.isDirectory();119}120function isSymbolicLink(path){121    path = escapePath(path);122    try{123        var stat = fs.statSync(path);124    }125    catch(e){126        return false;127    }128    return stat.isSymbolicLink();129}130function isFile(path){131    path = escapePath(path);132    try{133        var stat = fs.statSync(path);134    }135    catch(e){136        return false;137    }138    return stat.isFile();139}140function _copy_file(source_file, output_file) {141    createDirectory(path_lib.dirname(output_file))142    var byteArray = fs.readFileSync(source_file);143    fs.writeFileSync(output_file, byteArray);144}145function _copy_dir(sourceDir, outputDir) {146    createDirectory(outputDir);147    var list = fs.readdirSync(sourceDir);148    list.forEach(function (fileName) {149        copy(path_lib.join(sourceDir, fileName), path_lib.join(outputDir, fileName));150    });151}152/**153 * 删除文件或目录154 * @param path 要删除的文件源路径155 */156function remove(path) {157    path = escapePath(path);158    try{159        fs.lstatSync(path).isDirectory()160            ? rmdir(path)161            : fs.unlinkSync(path)162    }163    catch (e){164    }165}166function rmdir(path) {167    var files = [];168    if( fs.existsSync(path) ) {169        files = fs.readdirSync(path);170        files.forEach(function(file){171            var curPath = path + "/" + file;172            if(fs.statSync(curPath).isDirectory()) {173                rmdir(curPath);174            }175            else {176                fs.unlinkSync(curPath);177            }178        });179        fs.rmdirSync(path);180    }181}182/**183 * 返回指定文件的父级文件夹路径,返回字符串的结尾已包含分隔符。184 */185function getDirectory(path) {186    path = escapePath(path);187    return path_lib.dirname(path)+"/";188}189/**190 * 获得路径的扩展名,不包含点字符。191 */192function getExtension(path) {193    path = escapePath(path);194    var index = path.lastIndexOf(".");195    if(index==-1)196        return "";197    var i = path.lastIndexOf("/");198    if(i>index)199        return "";200    return path.substring(index+1);201}202/**203 * 获取路径的文件名(不含扩展名)或文件夹名204 */205function getFileName(path) {206    if (!path)207        return "";208    path = escapePath(path);209    var startIndex = path.lastIndexOf("/");210    var endIndex;211    if (startIndex > 0 && startIndex == path.length - 1) {212        path = path.substring(0, path.length - 1);213        startIndex = path.lastIndexOf("/");214        endIndex = path.length;215        return path.substring(startIndex + 1, endIndex);216    }217    endIndex = path.lastIndexOf(".");218    if (endIndex == -1)219        endIndex = path.length;220    return path.substring(startIndex + 1, endIndex);221}222/**223 * 获取指定文件夹下的文件或文件夹列表,不包含子文件夹内的文件。224 * @param path 要搜索的文件夹225 * @param relative 是否返回相对路径,若不传入或传入false,都返回绝对路径。226 */227function getDirectoryListing(path){228    var relative = arguments[1];229    path = escapePath(path);230    try{231        var list = fs.readdirSync(path);232    }233    catch (e){234        return [];235    }236    if(!relative){237        var length = list.length;238        for(var i = 0;i<length;i++){239            list[i] = joinPath(path,list[i]);240        }241    }242    return list;243}244/**245 * 使用指定扩展名搜索文件夹及其子文件夹下所有的文件246 * @param dir 要搜索的文件夹247 * @param extension 要搜索的文件扩展名,不包含点字符,例如:"png"。不设置表示获取所有类型文件。248 */249function search(dir, extension) {250    var list = [];251    try{252        var stat = fs.statSync(dir);253    }254    catch(e){255        return list;256    }257    if (stat.isDirectory()) {258        findFiles(dir,list,extension,null);259    }260    return list;261}262/**263 * 使用过滤函数搜索文件夹及其子文件夹下所有的文件264 * @param dir 要搜索的文件夹265 * @param filterFunc 过滤函数:filterFunc(file:File):Boolean,参数为遍历过程中的每一个文件,返回true则加入结果列表266 */267function searchByFunction(dir, filterFunc) {268    var list = [];269    try{270        var stat = fs.statSync(dir);271    }272    catch(e){273        return list;274    }275    if (stat.isDirectory()) {276        findFiles(dir,list,"",filterFunc);277    }278    return list;279}280function findFiles(filePath,list,extension,filterFunc) {281    var files = fs.readdirSync(filePath);282    var length = files.length;283    for (var i = 0; i < length; i++) {284        var path = joinPath(filePath ,files[i]);285        var stat = fs.statSync(path);286        if (path.charAt(0) == ".") {287            continue;288        }289        if (stat.isDirectory()) {290            findFiles(path, list,extension,filterFunc);291        }292        else if (filterFunc != null) {293            if (filterFunc(path)) {294                list.push(path);295            }296        }297        else if(extension){298            var len = extension.length;299            if(path.charAt(path.length-len-1)=="."&&300                path.substr(path.length-len,len).toLowerCase()==extension){301                list.push(path);302            }303        }304        else{305            list.push(path);306        }307    }308}309/**310 * 指定路径的文件或文件夹是否存在311 */312function exists(path) {313    path = escapePath(path);314    return fs.existsSync(path);315}316/**317 * 转换本机路径为Unix风格路径。318 */319function escapePath(path) {320    if (!path)321        return "";322    return path.split("\\").join("/");323}324/**325 * 连接路径,支持传入多于两个的参数。也支持"../"相对路径解析。返回的分隔符为Unix风格。326 */327function joinPath(dir,filename){328    var path = path_lib.join.apply(null,arguments);329    path = escapePath(path);330    return path;331}332/**333 * 检查文件是否为UTF8格式334 */335function isUTF8(text) {336    var i = 0;337    while(i < text.length){338        if(     (// ASCII339                    text[i] == 0x09 ||340                    text[i] == 0x0A ||341                    text[i] == 0x0D ||342                    (0x20 <= text[i] && text[i] <= 0x7E)343                )...

Full Screen

Full Screen

gatsby-node.js

Source:gatsby-node.js Github

copy

Full Screen

...85    .replace(/[^a-zA-Z0-9-\/_]/g, '');86const isSearchMatch = (a, b) => a.length > 0 && a.filter((x, i) => ~b.indexOf(x)).length;87const createCritterPage = (createPage, groups) => critter => {88  return createPage({89    path: escapePath(`/critter/${critter.type}/${critter.name}`),90    component: path.resolve('./src/templates/CritterPage.jsx'),91    context: {92      critter,93      similar: groups[getCritterLocation(critter.loc)],94    },95  });96};97const createDiyPage = (createPage, recipes) => diy => {98  let matches = recipes99    .filter(r => r !== diy && isSearchMatch(diy.search, r.search))100    .map(match => ({101      ...match,102      accuracy: isSearchMatch(match.search, diy.search),103    }));104  matches.sort((a, b) => b.accuracy - a.accuracy);105  diy.materialsNeeded = diy.materialsNeeded.map(material => {106    let recipe = recipes.find(107      r => r.name.toLowerCase() === (material.ingredient || '').toLowerCase()108    );109    let link;110    if (recipe) {111      link = escapePath(`/${recipe.section}/${recipe.name}`);112    } else {113      link = escapePath(`/material/${material.ingredient}`);114    }115    return {116      ...recipe,117      ...material,118      link,119      type: recipe ? 'diy' : 'material',120    };121  });122  return createPage({123    path: escapePath(`/${diy.section}/${diy.name}`),124    component: path.resolve('./src/templates/DiyPage.jsx'),125    context: { diy, similar: matches },126  });127};128const createMaterialPage = (createPage, allRecipes) => material => {129  let name = material.name.toLowerCase();130  let recipes = allRecipes.filter(recipe =>131    recipe.materialsNeeded.find(m => ~(m.ingredient || '').toLowerCase().indexOf(name))132  );133  return createPage({134    path: escapePath(`/material/${material.name}`),135    component: path.resolve('./src/templates/MaterialPage.jsx'),136    context: { material, recipes },137  });138};139const createFlowerPage = ({ createPage, createRedirect }, allRecipes) => (flower, _, flowers) => {140  let name = flower.name.toLowerCase();141  let recipes = allRecipes.filter(recipe =>142    recipe.materialsNeeded.find(m => ~(m.ingredient || '').toLowerCase().indexOf(name))143  );144  let similar = flowers.filter(f => f.genus === flower.genus);145  createRedirect({146    fromPath: escapePath(`/material/${flower.name}`),147    isPermanent: true,148    redirectInBrowser: true,149    toPath: escapePath(`/flower/${flower.name}`),150  });151  return createPage({152    path: escapePath(`/flower/${flower.name}`),153    component: path.resolve('./src/templates/FlowerPage.jsx'),154    context: { flower, recipes, similar },155  });156};157exports.createPages = async ({ graphql, ...gatsby }) => {158  const { createPage, createRedirect } = gatsby.actions;159  let results = await graphql(critterPageQuery);160  const { allCrittersJson, allDiyJson, allMaterialsJson, allFlowersJson } = results.data;161  if (results.errors) throw new Error(results.errors);162  // const critters = allCrittersJson.edges.map(edge => edge.node).filter(Boolean);163  const diys = allDiyJson.edges.map(edge => edge.node).filter(Boolean);164  const materials = allMaterialsJson.edges.map(edge => edge.node).filter(Boolean);165  const flowers = allFlowersJson.edges.map(edge => edge.node).filter(Boolean);166  // const critterGroups = groupBy(critters, critter => getCritterLocation(critter.loc));...

Full Screen

Full Screen

endpoint.test.js

Source:endpoint.test.js Github

copy

Full Screen

...3test("Test endpoint basic", t => {4  var endpoint = new Endpoint("/users/${id}/devices/${device_name}", {id: 10, device_name: "mine"})5  t.is(endpoint.path, "/users/${id}/devices/${device_name}")6  t.deepEqual(endpoint.pathArgs, {id: 10, device_name: "mine"})7  t.is(endpoint.escapePath(), "/users/10/devices/mine")8})9test("Test endpoint escape url", t => {10  var endpoint = new Endpoint("/articles/${id}/${title}", {id: 2734, title: "Carmilla movie released! & watch it NOW!!!"})11  t.is(endpoint.escapePath(), "/articles/2734/Carmilla%20movie%20released!%20%26%20watch%20it%20NOW!!!")12})13test("Test with invalid placeholders", t => {14  var endpoint = new Endpoint("/devices/{$id}/sensors/${sensor_id}/measures/$datetime/${filter/${s}", {id: 10, datetime: 5467651, filter: "my", s: "temp"})15  t.is(endpoint.escapePath(), "/devices/{$id}/sensors/${sensor_id}/measures/$datetime/${filter/temp")16})17test.skip("Test datetime place to escaped path", t => {18  var date = new Date("2017-12-05 18:00")19  var endpoint = new Endpoint("/time/${time}", {time: date})20  t.is(endpoint.escapePath(), "/time/" + date)21})22test("Extend endpoint", t => {23  var endpoint = new Endpoint("/devices/${device}/sensors", {device: "245a2c0df5bb0cd11d"})24  var extended = endpoint.ext("/${uid}", {uid: "abc0123def654a0"})25  t.is(extended.escapePath(), "/devices/245a2c0df5bb0cd11d/sensors/abc0123def654a0")26})27test("Join endpoints", t => {28  var endpoint = new Endpoint("/devices/${device}/sensors", {device: "245a2c0df5bb0cd11d"})29  var extended = endpoint.join(new Endpoint("/${uid}", {uid: "abc0123def654a0"}))30  t.is(extended.escapePath(), "/devices/245a2c0df5bb0cd11d/sensors/abc0123def654a0")31})32test("Merge endpoint", t => {33  var endpoint = new Endpoint("/foo/${foo}", {foo: "abc"})34  var endpoint2 = new Endpoint("/bar/${bar}/baz/${foo}", {bar: "xyz"})35  var merged = endpoint.merge(endpoint2)36  t.is(merged.escapePath(), "/foo/abc/bar/xyz/baz/abc")37})38test("Remove and escape unsafe chars", t => {39  var endpoint = new Endpoint("/foo/bar/../${foo}", {foo: "../admin"})40  t.is(endpoint.escapePath(), "/foo/bar%2Fadmin")41})42test("Convert endpoint to string", t => {43  var endpoint = new Endpoint("/foo/${foo}", {foo: "abc"})44  t.is(endpoint.toString(), "/foo/abc")...

Full Screen

Full Screen

PHashService.js

Source:PHashService.js Github

copy

Full Screen

1// @flow2import typeof { Logger } from "log4js";3import { promisify } from "util";4import { imageHash, hammingDistance } from "phash";5import JimpService from "./JimpService";6import FileSystemHelper from "../../../helpers/FileSystemHelper";7import type { Config } from "../../../types";8const imageHashAsync = promisify(imageHash);9export default class PHashService {10  log: Logger;11  config: Config;12  js: JimpService;13  constructor(config: Config) {14    this.log = config.getLogger(this);15    this.config = config;16    this.js = new JimpService(config);17  }18  /**19   * XXX: pHash library cannot process multibyte file path.20   */21  prepareEscapePath = async (targetPath: string): Promise<string> => {22    return FileSystemHelper.prepareEscapePath(targetPath);23  };24  clearEscapePath = (escapePath: string): Promise<void> =>25    FileSystemHelper.clearEscapePath(escapePath);26  calculate = async (targetPath: string): Promise<null | string> => {27    let escapePath = null;28    try {29      escapePath = await this.prepareEscapePath(targetPath);30      const targetPathFixed = await this.js.fixTargetPath(escapePath);31      const hash = await imageHashAsync(targetPathFixed);32      this.log.debug(`calculate pHash: path = ${targetPath} hash = ${hash}`);33      await this.clearEscapePath(escapePath);34      await this.js.clearFixedPath(targetPathFixed, targetPath);35      return hash;36    } catch (e) {37      this.log.warn(e, `path = ${targetPath}`);38      if (escapePath) {39        await this.clearEscapePath(escapePath);40      }41    }42    return null;43  };44  static compare = (a: ?string, b: ?string): number | false => {45    if (!a || !b) {46      return false;47    }48    return hammingDistance(a, b);49  };...

Full Screen

Full Screen

fileUtils.js

Source:fileUtils.js Github

copy

Full Screen

...34/**5 * 转换本机路径为Unix风格路径。6 */7function escapePath(path) {8    if (!path)9        return "";10    return path.split("\\").join("/");11}1213/**14 * 是否是文件夹15 * @param path16 * @returns {*}17 */18function isDirectory(path){19    path = escapePath(path);20    try{21        var stat = fs.statSync(path);22    }23    catch(e){24        return false;25    }26    return stat.isDirectory();27}2829/**30 * 保存数据到指定文件31 * @param path 文件完整路径名32 * @param data 要保存的数据33 */34function save(path, data){35    if(exists(path)) {36        remove(path);37    }38    path = escapePath(path);39    fs.writeFileSync(path, data, charset);40}41/**42 * 删除文件或目录43 * @param path 要删除的文件源路径44 */45function remove(path) {46    path = escapePath(path);47    try{48        fs.lstatSync(path).isDirectory()49            ? rmdir(path)50            : fs.unlinkSync(path)51    }52    catch (e){53    }54}555657/**58 * 指定路径的文件或文件夹是否存在59 */60function exists(path) {61    path = escapePath(path);62    return fs.existsSync(path);63}6465exports.save = save;66exports.isDirectory = isDirectory;
...

Full Screen

Full Screen

escape-path.util.js

Source:escape-path.util.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3exports.escapePath = void 0;4function escapePath(path) {5    return path.startsWith('.') && path[1] === '/'6        ? path.slice(2)7        : path.startsWith('/')8            ? path.slice(1)9            : path;10}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = wd.promiseChainRemote('localhost', 4723);2driver.init({3}).then(function () {4    return driver.escapePath("path/to/myFile.txt");5});6var driver = wd.promiseChainRemote('localhost', 4723);7driver.init({8}).then(function () {9    return driver.escapePath("path/to/myFile.txt");10});11var driver = wd.promiseChainRemote('localhost', 4723);12driver.init({13}).then(function () {14    return driver.escapePath("path/to/myFile.txt");15});16var driver = wd.promiseChainRemote('localhost', 4723);17driver.init({18}).then(function () {19    return driver.escapePath("path/to/myFile.txt");20});21var driver = wd.promiseChainRemote('localhost', 4723);22driver.init({23}).then(function () {24    return driver.escapePath("path/to/myFile.txt");25});26var driver = wd.promiseChainRemote('localhost', 4723);27driver.init({

Full Screen

Using AI Code Generation

copy

Full Screen

1var AndroidDriver = require('appium-android-driver').AndroidDriver;2var driver = new AndroidDriver();3var path = driver.escapePath('C:\\test\\test');4console.log(path);5var AndroidDriver = require('appium-android-driver').AndroidDriver;6var driver = new AndroidDriver();7var path = driver.escapePath('C:/test/test');8console.log(path);

Full Screen

Using AI Code Generation

copy

Full Screen

1var androidDriver = require('appium-android-driver');2var driver = new androidDriver.AndroidDriver();3var path = driver.escapePath("C:\test\path");4var androidDriver = require('appium-android-driver');5var driver = new androidDriver.AndroidDriver();6var path = driver.escapePath("C:\test\path");

Full Screen

Using AI Code Generation

copy

Full Screen

1const escapePath = require('appium-android-driver').escapePath;2const path = '/Users/user1/Downloads/MyFile.txt';3const escapedPath = escapePath(path);4console.log(escapedPath);5const escapePath = require('appium-android-driver').escapePath;6const path = 'C:\\Users\\user1\\Downloads\\MyFile.txt';7const escapedPath = escapePath(path);8console.log(escapedPath);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Android Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful