loadPixels and updatePixels and pixels.length for Array of pixels like assembler

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 :smile:
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

Thanks @Ignatz and @dave1707 yes it’s very slow but it s for me most simple than shader.
i thank new logical bit binary or hexadecimal command like bit.rol or bit.ror …
i don’t know if commands are supported by last version of codea
like bitwise operations

http://lua-users.org/wiki/BitwiseOperators
http://bitop.luajit.org

and

http://stackoverflow.com/questions/5977654/lua-bitwise-logical-operations

We used bitmap technics in hp48 asm with saturn 4khz processor and it was very very fast

https://books.google.fr/books?id=eMM4uusdj6cC&pg=PT816&lpg=PT816&dq=hp+48+bit+scroll&source=bl&ots=I9uGJgtFSu&sig=Il1twxbm7fOMjxpqr2hDhGL8cY8&hl=fr&sa=X&ved=0ahUKEwja3I_XpsfMAhVGVRoKHXo_DsUQ6AEIJjAA#v=onepage&q=hp%2048%20bit%20scroll&f=false

or here

http://members.ziggo.nl/kees.van.der.sanden/downloads/Saturn_tutorial.pdf

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.