Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sine Distortion Shader not working #370

Closed
realHaloboi3 opened this issue Apr 30, 2023 · 3 comments
Closed

Sine Distortion Shader not working #370

realHaloboi3 opened this issue Apr 30, 2023 · 3 comments

Comments

@realHaloboi3
Copy link

So I tried to code a shader for sine distortion, but it just isn't working. Any thoughts?

(function(ext) {

var distortion = 0;

ext._shutdown = function() {};

ext._getStatus = function() {
return {status: 2, msg: 'Ready'};
};

ext.setDistortion = function(value) {
distortion = value;
};

ext.getDistortion = function() {
return distortion;
};

ext.applySineDistortion = function() {
var data = stage.canvas.getContext('2d').getImageData(0, 0, 480, 360);
var pixels = data.data;
var length = pixels.length;
var width = data.width;

for (var i = 0; i < length; i += 4) {
  var x = (i / 4) % width;
  var y = Math.floor((i / 4) / width);

  var sinDistortion = Math.sin(x / 10) * distortion;
  var cosDistortion = Math.cos(y / 10) * distortion;
  var offset = Math.round((y + sinDistortion) * width + (x + cosDistortion)) * 4;

  if (offset >= 0 && offset < length) {
    pixels[i] = data.data[offset];
    pixels[i + 1] = data.data[offset + 1];
    pixels[i + 2] = data.data[offset + 2];
  }
}

stage.canvas.getContext('2d').putImageData(data, 0, 0);

};

var descriptor = {
blocks: [
[' ', 'set sine distortion to %n', 'setDistortion', 0],
['r', 'get sine distortion', 'getDistortion'],
[' ', 'apply sine distortion', 'applySineDistortion']
]
};

ScratchExtensions.register('Sine Distortion', descriptor, ext);

})({});

@David-Orangemoon
Copy link
Contributor

I don't think that is how extensions are formatted in Turbowarp also turbowarp uses WEBGL and not 2D context.

@CST1229
Copy link
Collaborator

CST1229 commented Apr 30, 2023

That extension registration format is for ScratchX extensions, not Scratch 3.0/TurboWarp. Please read the documentation.

Also, the stage canvas uses WebGL - 2D Canvas functions won't work.

@SharkPool-SP
Copy link
Collaborator

invalid as mentioned above

@SharkPool-SP SharkPool-SP closed this as not planned Won't fix, can't repro, duplicate, stale Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants