Is It possible to create processing functions ?
https://processing.org/reference/loadPixels_.html
Image = loadImage("picture.jpg");
loadPixels()
for i = 0; pixels.length(Image) do
pixels[i] = color(random(255))
end
updatePixels()
it would be convenient for color or scrolling bit effects.
I have the same question for sound.
thanks
Sorry it’s possible with
r,g,b,a = myImage:get( )
I think those 3 internal functions would be faster and point function too
but with sound, for modifying micro input or sound import i don’t know
There is no LoadPixels function in Codea, but you can change pixel colours directly with Image:set(x,y,colour)
However, this is going to be very slow. It will be way faster to use a shader to change the image colours.
@hpsoft Here’s an example of how slow bit scrolling is using :get and :set.
displayMode(FULLSCREEN)
function setup()
img=readImage("Cargo Bot:Startup Screen")
xs=img.width
ys=img.height
ys2=ys/2+15
sz=32
tab={}
end
function draw()
background(0)
for y=1,sz do
tab[y]=vec4(img:get(1,ys2+y))
end
for x=2,xs do
for y=1,sz do
r,g,b,a=img:get(x,ys2+y)
img:set(x-1,ys2+y,r,g,b,a)
end
end
for y=1,sz do
tab[y]=vec4(img:set(xs,ys2+y,tab[y].x,tab[y].y,tab[y].z,tab[y].w))
end
sprite(img,WIDTH/2,HEIGHT/2)
end
The only way to get or set bitmap pixels is as we showed above
@hpsoft learn GLES shaders. They’re such a common standard that they’re incredibly well documented and there’s tonnes of examples online. Start with @Ignatz shaders ebook, and some shader playground sites. My favourite is http://shaderfrog.com . This one is good too: https://www.shadertoy.com
Thanks a lot @yojimbo2000 for this awesome website
https://www.shadertoy.com/view/XscXzn
In sounds tab i have exactly what i’m looking for but i think sounds doesn’t work.
@hpsoft Here’s an example similar to my code above that uses shaders for scrolling. You can adjust the speed parameter to see how fast it can go. You can change the upper limit of speed if you want it to go faster.
EDIT: Comment out this line to see the whole page scroll.
//if (vTexCoord.y>0.51 && vTexCoord.y<0.55)
supportedOrientations(LANDSCAPE_ANY)
function setup()
parameter.number("speed",0,.25,.005)
img=readImage("Cargo Bot:Startup Screen")
offset=0
m=mesh()
m:addRect(WIDTH/2,HEIGHT/2,WIDTH,HEIGHT)
m.texture=img
m.shader=shader(vShader,fShader)
end
function draw()
background(40, 40, 50)
offset=offset+speed
if offset>=1 then
offset=0
end
m.shader.offset=offset
m:draw()
end
vShader = [[
uniform mat4 modelViewProjection;
attribute vec4 position;
attribute vec4 color;
attribute vec2 texCoord;
varying lowp vec4 vColor;
varying highp vec2 vTexCoord;
uniform lowp float offset;
void main()
{ vColor=color;
vTexCoord = texCoord;
gl_Position = modelViewProjection * position;
} ]]
fShader = [[
uniform lowp sampler2D texture;
varying lowp vec4 vColor;
varying highp vec2 vTexCoord;
uniform lowp float offset;
lowp float xx;
void main()
{ xx=0.0;
if (vTexCoord.y>0.51 && vTexCoord.y<0.55)
{ xx=offset;
if (vTexCoord.x+xx>=1.0)
xx=offset-1.0;
}
gl_FragColor=texture2D( texture,vec2(vTexCoord.x+xx,vTexCoord.y))*vColor;
} ]]
@dave1707 thank you It’s very fast …
I study @yojimbo2000 awesome website particularly
https://www.shadertoy.com/view/XscXzn ( sounds tab )
But i believe i can unfortunately not create synthesizer like in this example.