Closed PolyPenguinDev closed 2 months ago
i'm making an extension to let you write shader code for this extension: https://github.com/TurboWarp/extensions/pull/1424 but my menu icons look like this: here is the code for it:
(function (Scratch) { 'use strict'; if (!Scratch.extensions.unsandboxed) { throw new Error('This example must run unsandboxed'); } const svgString = "data:image/svg+xml;charset=UTF-8,%3csvg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='57.33639' height='69.46717' viewBox='0,0,57.33639,69.46717'%3e%3cg transform='translate(-211.33181,-144.32361)'%3e%3cg data-paper-data='%7b"isPaintingLayer":true%7d' fill-rule='nonzero' stroke-linejoin='miter' stroke-miterlimit='10' stroke-dasharray='' stroke-dashoffset='0' style='mix-blend-mode: normal'%3e%3cpath d='M212.58182,156.32361c0,-2.20914 1.79086,-4 4,-4h5.57942c2,0 3,-1 4,-2l4,-4c1,-1 2,-2 4,-2h12c2,0 3,1 4,2l4,4c1,1 2,2 4,2h5.25697c2.20914,0 4,1.79086 4,4v41.55608c0,2.20914 -1.79086,4 -4,4h-46.83639c-2.20914,0 -4,-1.79086 -4,-4z' data-paper-data='%7b"index":null%7d' fill='none' stroke='none' stroke-width='0' stroke-linecap='butt'/%3e%3cpath d='M212.58181,158.98471c0,-2.20914 1.79086,-4 4,-4h46.83639c2.20914,0 4,1.79086 4,4v41.55608c0,2.20914 -1.79086,4 -4,4h-5.25697c-2,0 -3,1 -4,2l-4,4c-1,1 -2,2 -4,2h-12c-2,0 -3,-1 -4,-2l-4,-4c-1,-1 -2,-2 -4,-2h-5.57942c-2.20914,0 -4,-1.79086 -4,-4z' fill='%230b8e69' stroke='%230b8e69' stroke-width='2.5' stroke-linecap='butt'/%3e%3cpath d='M212.58181,155.22196c0,-2.20914 1.79086,-4 4,-4h46.83639c2.20914,0 4,1.79086 4,4v41.55608c0,2.20914 -1.79086,4 -4,4h-5.25697c-2,0 -3,1 -4,2l-4,4c-1,1 -2,2 -4,2h-12c-2,0 -3,-1 -4,-2l-4,-4c-1,-1 -2,-2 -4,-2h-5.57942c-2.20914,0 -4,-1.79086 -4,-4z' fill='%230fbd8c' stroke='%233cf1bd' stroke-width='2.5' stroke-linecap='butt'/%3e%3cpath d='M224.14195,165.37086c0,-1.37657 1.0079,-2.4925 2.25121,-2.4925h26.35967c1.24331,0 2.25122,1.11593 2.25122,2.4925v25.89464c0,1.37657 -1.0079,2.49249 -2.25122,2.49249h-26.35967c-1.24331,0 -2.25121,-1.11593 -2.25121,-2.49249z' fill='%23064835' stroke='%23064835' stroke-width='2.5' stroke-linecap='butt'/%3e%3cpath d='M231.5166,171.84528h-11.3167' fill='none' stroke='%23064835' stroke-width='5' stroke-linecap='round'/%3e%3cpath d='M231.5166,184.79108h-11.3167' fill='none' stroke='%23064835' stroke-width='5' stroke-linecap='round'/%3e%3cpath d='M259.11001,171.84528h-11.3167' fill='none' stroke='%23064835' stroke-width='5' stroke-linecap='round'/%3e%3cpath d='M247.79331,184.79108h11.3167' fill='none' stroke='%23064835' stroke-width='5' stroke-linecap='round'/%3e%3cpath d='M233.18206,186.45653v11.3167' fill='none' stroke='%23064835' stroke-width='5' stroke-linecap='round'/%3e%3cpath d='M246.12787,186.45653v11.3167' fill='none' stroke='%23064835' stroke-width='5' stroke-linecap='round'/%3e%3cpath d='M233.18206,170.17982v-11.3167' fill='none' stroke='%23064835' stroke-width='5' stroke-linecap='round'/%3e%3cpath d='M246.12787,170.17982v-11.3167' fill='none' stroke='%23064835' stroke-width='5' stroke-linecap='round'/%3e%3cpath d='M229.90065,184.85155c-1.21462,0 -2.2473,-0.26095 -3.09805,-0.78285c-0.84813,-0.52493 -1.4934,-1.25924 -1.93579,-2.20291c-0.44239,-0.94367 -0.66358,-2.04513 -0.66358,-3.30436c0,-0.98008 0.13219,-1.86307 0.39658,-2.64895c0.26701,-0.78588 0.65181,-1.46102 1.15441,-2.0254c0.5026,-0.56741 1.11776,-0.99829 1.84548,-1.29261c0.73034,-0.29736 1.55753,-0.44604 2.48158,-0.44604c0.5026,0 1.01567,0.05614 1.53921,0.1684c0.52354,0.10923 1.03661,0.31405 1.53921,0.61445c0.25915,0.13958 0.43585,0.33529 0.53009,0.58714c0.09686,0.25185 0.12827,0.51431 0.09424,0.7874c-0.03403,0.27309 -0.11911,0.52342 -0.25522,0.75099c-0.13612,0.22757 -0.32067,0.37929 -0.55364,0.45514c-0.23036,0.07586 -0.49082,0.03793 -0.78138,-0.11379c-0.30103,-0.16385 -0.62825,-0.28977 -0.98164,-0.37777c-0.35077,-0.088 -0.72249,-0.13199 -1.11514,-0.13199c-0.67275,0 -1.23293,0.14109 -1.68056,0.42328c-0.44763,0.27916 -0.78269,0.69334 -1.0052,1.24255c-0.21989,0.54617 -0.32983,1.21524 -0.32983,2.0072c0,1.18945 0.2513,2.08761 0.7539,2.69447c0.5026,0.60382 1.24603,0.90574 2.23028,0.90574c0.30365,0 0.63348,-0.03489 0.98949,-0.10468c0.35601,-0.06979 0.71463,-0.1684 1.07588,-0.29584l-0.51045,1.20614v-2.99031h-1.05624c-0.3403,0 -0.60469,-0.09861 -0.79316,-0.29584c-0.18586,-0.20026 -0.27878,-0.48094 -0.27878,-0.84202c0,-0.36108 0.09293,-0.6372 0.27878,-0.82836c0.18847,-0.19116 0.45286,-0.28674 0.79316,-0.28674h2.23028c0.35339,0 0.62301,0.10772 0.80887,0.32315c0.18586,0.21544 0.27878,0.52645 0.27878,0.93305v3.86419c0,0.34894 -0.06282,0.64631 -0.18847,0.89208c-0.12565,0.24274 -0.32459,0.41722 -0.59684,0.52342c-0.47118,0.18509 -0.98426,0.32922 -1.53921,0.43239c-0.55234,0.1062 -1.10467,0.1593 -1.657,0.1593zM236.51161,184.81969c-0.44239,0 -0.784,-0.14261 -1.02483,-0.42784c-0.24083,-0.28826 -0.36124,-0.68879 -0.36124,-1.20158v-9.22582c0,-0.52493 0.12303,-0.92698 0.3691,-1.20614c0.24606,-0.27916 0.59029,-0.41873 1.03268,-0.41873h3.71059c1.20414,0 2.13473,0.35805 2.79178,1.07414c0.65966,0.7161 0.98949,1.70376 0.98949,2.963c0,1.25924 -0.32983,2.24691 -0.98949,2.963c-0.65704,0.7161 -1.58763,1.07414 -2.79178,1.07414h-2.34022v2.77639c0,0.5128 -0.11518,0.91332 -0.34554,1.20158c-0.23036,0.28522 -0.5772,0.42784 -1.04053,0.42784zM237.89768,177.94698h1.85726c0.52092,0 0.92143,-0.13047 1.20152,-0.39142c0.28271,-0.26095 0.42407,-0.65389 0.42407,-1.17883c0,-0.53707 -0.14135,-0.93305 -0.42407,-1.18793c-0.28009,-0.25791 -0.6806,-0.38687 -1.20152,-0.38687h-1.85726zM249.41039,184.85155c-0.77484,0 -1.45937,-0.11379 -2.05359,-0.34136c-0.5916,-0.22757 -1.09158,-0.56741 -1.49994,-1.01953c-0.40575,-0.45514 -0.71201,-1.02256 -0.91881,-1.70225c-0.20418,-0.68272 -0.30627,-1.47316 -0.30627,-2.37131v-5.61196c0,-0.53404 0.12042,-0.9376 0.36124,-1.21069c0.24083,-0.27612 0.58244,-0.41418 1.02483,-0.41418c0.45286,0 0.79709,0.13806 1.03268,0.41418c0.23559,0.27309 0.35339,0.67665 0.35339,1.21069v5.64837c0,0.89512 0.17015,1.57025 0.51045,2.0254c0.34292,0.45514 0.84159,0.68272 1.49602,0.68272c0.64396,0 1.13608,-0.22757 1.47638,-0.68272c0.34292,-0.45514 0.51438,-1.13028 0.51438,-2.0254v-5.64837c0,-0.53404 0.11779,-0.9376 0.35339,-1.21069c0.23559,-0.27612 0.57459,-0.41418 1.01698,-0.41418c0.44239,0 0.77876,0.13806 1.00912,0.41418c0.23297,0.27309 0.34946,0.67665 0.34946,1.21069v5.61196c0,1.20158 -0.17931,2.20746 -0.53794,3.01762c-0.35601,0.80712 -0.88609,1.41247 -1.59025,1.81603c-0.70154,0.40053 -1.56538,0.60079 -2.59153,0.60079z' fill='%230fbd8c' stroke='none' stroke-width='1' stroke-linecap='square'/%3e%3c/g%3e%3c/g%3e%3c/svg%3e%3c!--rotationCenter:28.66819000000001:35.67638500000001--%3e"; class GPUoperators { getInfo() { return { id: 'gpuoperators', name: 'GPU Operators', blockIconURI: svgString, blocks: [ { blockType: Scratch.BlockType.REPORTER, opcode: 'sqrt', text: '[OF] of [CONTENT]', arguments: { OF: { type: Scratch.ArgumentType.STRING, menu: 'OF_MENU' }, CONTENT: { type: Scratch.ArgumentType.STRING, defaultValue: '' } }, extensions: ["colours_operators"], } ], menus: { OF_MENU: { acceptReporters: false, items: ['abs', 'floor', 'ceiling', 'sqrt', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'ln', 'log', 'e ^', '10 ^'] } } } } sqrt(args) { return JSON.stringify({ line: args.OF, input: JSON.parse(args.CONTENT) }) } } class GPUblocks { constructor() { this.script = [] this.sn = "" this.rn = "" } getInfo() { return { id: 'gpublocks', name: 'GPU Blocks', blockIconURI: svgString, blocks: [ { blockType: Scratch.BlockType.HAT, opcode: 'gpuScript', text: 'GPU script with name: [NAME]', arguments: { NAME: { type: Scratch.ArgumentType.STRING, defaultValue: 'script' } }, extensions: ["colours_pen"], }, { blockType: Scratch.BlockType.COMMAND, opcode: 'compileGpuScripts', text: 'compile GPU script with name: [NAME]', arguments: { NAME: { type: Scratch.ArgumentType.STRING, defaultValue: 'script' } }, extensions: ["colours_pen"], }, { blockType: Scratch.BlockType.COMMAND, opcode: 'return', text: 'return [CONTENT]', arguments: { CONTENT: { type: Scratch.ArgumentType.STRING, defaultValue: 'content' } }, extensions: ["colours_pen"], terminal: true, }, { blockType: Scratch.BlockType.COMMAND, opcode: 'ifthen', text: 'if[COND]then', arguments: { COND: { type: Scratch.ArgumentType.BOOLEAN, defaultValue: false }, }, branchCount: 1, extensions: ["colours_control"], }, ], }; } ifthen(args) { } gpuScript(args) { if (this.rn == args.NAME) { this.rn = "" return true } return false } return(args) { this.script.push({ line: "return", input: JSON.parse(args.CONTENT) }) let code = "" for (let i = 0; i < this.script.length; i++) { code += " " + this.evalLine(this.script[i]) + ";\n"; } let txt = "name: " + this.sn + "\n\n@group(0) @binding(0)\nvar<storage, read_write> strg: array<f32>;\n\n@compute @workgroup_size(256)\nfn main(\n @builtin(global_invocation_id)\n global_id: vec3u\n) {\n" + code + '}' console.log(txt) Scratch.vm.editingTarget.comments[this.sn] = { text: txt } console.log(Scratch.vm.editingTarget.comments) this.script = [] this.sn = "" } isNumeric(str) { for (let i = 0; i < str.length; i++) { if (isNaN(parseInt(str[i]))) { return false; } } return true; } evalLine(line) { let cmd = line["line"] if (cmd == 'sqrt') { return "sqrt(" + this.evalLine(line['input']) + ")" } else if (cmd == 'return') { return ("strg[global_id.x] = " + this.evalLine(line['input'])) } else if (cmd == 'abs') { return "abs(" + this.evalLine(line['input']) + ")" } else if (cmd == 'floor') { return "floor(" + this.evalLine(line['input']) + ")" } else if (cmd == 'ceil') { return "ceil(" + this.evalLine(line['input']) + ")" } else if (cmd == 'sin') { return "sin(" + this.evalLine(line['input']) + ")" } else if (cmd == 'cos') { return "cos(" + this.evalLine(line['input']) + ")" } else if (cmd == 'tan') { return "tan(" + this.evalLine(line['input']) + ")" } else if (cmd == 'asin') { return "asin(" + this.evalLine(line['input']) + ")" } else if (cmd == 'acos') { return "acos(" + this.evalLine(line['input']) + ")" } else if (cmd == 'atan') { return "atan(" + this.evalLine(line['input']) + ")" } else if (cmd == 'ln') { return "log(" + this.evalLine(line['input']) + ")" } else if (cmd == 'log') { return "log10(" + this.evalLine(line['input']) + ")" } else if (cmd == 'e ^') { return "pow(2.71828182846, " + this.evalLine(line['input']) + ")" } else if (cmd == '10 ^') { return "pow(10, " + this.evalLine(line['input']) + ")" } else if (isNaN(parseFloat(line['line']))) { return line } else { return { line: "\"" + line['line'] + "\"", input: line["input"] } } } compileGpuScripts(args) { const name = args.NAME this.rn = name this.sn = name return new Promise((resolve, reject) => { const intervalId = setInterval(() => { if (this.sn != name) { clearInterval(intervalId); resolve(); } }, 1); }); } // Notice: whenSpacePressed does not have a function defined! } Scratch.extensions.register(new GPUblocks()); Scratch.extensions.register(new GPUoperators()); })(Scratch);
Fixed by using a different uri generator
i'm making an extension to let you write shader code for this extension: https://github.com/TurboWarp/extensions/pull/1424 but my menu icons look like this:
here is the code for it: