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

Are Image[] and Image[]= undocumented? #285

Open
ccoupe opened this issue Oct 25, 2016 · 5 comments
Open

Are Image[] and Image[]= undocumented? #285

ccoupe opened this issue Oct 25, 2016 · 5 comments

Comments

@ccoupe
Copy link

ccoupe commented Oct 25, 2016

They are image methods and the C functions are called by other functions in ruby.c at the C level but I can't find a Shoes/Ruby level use or description. I'm inclined to delete the Ruby.c method defs.

@passenger94
Copy link
Contributor

passenger94 commented Oct 25, 2016

Are you talking about those ? https://github.com/Shoes3/shoes3/blob/master/shoes/ruby.c#L4766
getter and setter for a pixel in image (in Shoes, an_image[x,y]).
In theory could be used if you want to tweak images at the pixel level in Shoes/Ruby, might work for creating your own image effect like blur etc ... but would be slow, harmless, i'd say !
One can grab a part of an image and do stuff on/with it, lots of possibilities ...
I remember vaguely someone blogging about it, might be the Creator himself :-)

@IanTrudel
Copy link
Collaborator

@passenger94 could also be useful as when someone wants their own colorpicker on an image or something.

@passenger94
Copy link
Contributor

Indeed ! Let's leave the door open ...

@IanTrudel
Copy link
Collaborator

We need some kind of demo for the manual. I made a small colour picker for your entertainment but it seems a bug has been uncovered. The colour picked is not relative, i.e. if you hover over "Color picked" you will actually get the colour of the top of the image, as if it was positioned on top.

Please, also take note that img[left, top] and img.image[left, top] give the same results. They are synonymous.

image

Shoes.app do
    flow do
        @r = rect 0, 0, self.width - 1, 25
        @p = para
    end

    img = image "#{DIR}/static/shoes-manual-apps.png"
    motion do |left, top|
        color = img.image[left, top]
        info [left, top, color, img[left, top]]
        @r.fill = color
        @p.text = strong("Color picked: #{color}\n")
    end
end

@IanTrudel
Copy link
Collaborator

IanTrudel commented Nov 10, 2016

Interesting development on Image[]=. The code below uses direct access and can handle the 24 frames per second. However, if you use @img.image[x, y], it will freeze or only works at low animate FPS such as 5 or so.

image

Shoes.app(:width => 200, :height => 200) do
    s = stack do
        @img = image "#{DIR}/static/shoes-icon-red.png"
    end

    w, h = [@img.full_width, @img.full_height]

    table = []
    (0..w).each do |x|
        (0..h).each do |y|
            unless @img[x, y].nil?
                r, g, b, a = [:red, :green, :blue, :alpha].collect { |n| @img[x, y].send(n) }
                table << [x, y] if (r > 20 and 2 >= g and 2 >= b) # catch any red looking colors
            end
        end
    end

    animate(24) do |frame|
        color = rgb(rand(0..255), rand(0..255), rand(0..255), rand(0..255))
        table.each do |n|
            @img[*n] = color
        end
        s.refresh_slot
    end
end

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

3 participants