Replies: 5 comments 9 replies
-
https://ctrlr.org/forums/topic/looking-to-change-button-image-on-value-change/#post-120030 Hi there @bijlevel, I realised there's some redundancy in the code: frResource=resources:getResource("KurzScreen") frImage = Image() -- gets overwritten by next line anyway!! frImage = frResource:asImage() I have tested this using the attached panel which I created back in September (now modified): function graphicsLCD(mod, g) frImage = Image(resources:getResourceAsImage("KurzScreen")) if frImage ~= nil then g:setOpacity(1.0) -- 0.0 - 1.0 g:drawImageAt(frImage, 0, 0, false) -- x,y position in uiComponent console(Colour(frImage:getPixelAt(30, 30)):toString()) -- will return hex string end -- image found end |
Beta Was this translation helpful? Give feedback.
-
Hi @bijlevel I often refer to the JUCE documentation to help me and the source code for Ctrlr. When you find a method called .def(...) in Ctrlr source code it means a JUCE C++ function/method is bound to lua (i.e can be used in lua) - (using luabind). The next challenge is to find the correct syntax. That's when I use the Monkey Theorum! LoL When I found .def("getPixelAt", &Image::getPixelAt) I then looked up the Image Method for JUCE and saw that Colour | getPixelAt (int x, int y) const has a class type of Colour, so I then guessed to access getPixelAt() one needed to declare a Colour object and then I looked and saw a method toString - From what I understand, in lua you can call methods belonging to certain classes using : , (this has to do with a basic type of class structure using tables in lua where table values get passed to functions belonging to the table) To be honest I'm not always so lucky as I was with your question. It can be frustrating, but I prefer to see it as an interesting puzzle solving quest! But, to answer your question, the lua to JUCE syntax is still not clear to me. You can, however, learn a lot from Atom's panels in the DEMO folder of your installation of Ctrlr. There's a lot of information in there, that's for sure. He is obviously on a whole different level. lua syntax will resemble JUCE (C++) syntax, but it is never the same. With regard to lua, if you can learn how to use tables, your way of programming in lua will be much much easier. Regards. |
Beta Was this translation helpful? Give feedback.
-
what and how are really, really handy. Just remember to assign a variable and do the what and how on that. You can't do it on the "command" itself. I also search the old forum (or use google and search for "ctrlr something", for example ctrlr wait, to find how to insert a pause into a bulk sysex request loop. I find these resources pop up a lot (in addition to ctrlr.org forums): https://www.lua.org/manual/5.1/manual.html (ctrlr uses 5.1. Some of the bitwise functions are done differently. 5.2 uses >> for example, 5.1 uses a library), http://lua-users.org/wiki/LuaTypeChecking lots of really useful examples there. Oh and previous panels. I'm going to start puting code snippets up here as well, such as the class definitions that I'm using for the Jupiter 8 Librarian, and other problems that I've solved. |
Beta Was this translation helpful? Give feedback.
-
Yep, it takes time to go deeper into Ctrlr with more complex things and indeed you listed the 3 sources of info:
|
Beta Was this translation helpful? Give feedback.
-
There is some follow up, and an alternative method using filled rectangles over at the old forums. https://ctrlr.org/forums/topic/creating-images-using-lua/ Hopefully I'll have my Jupiter 8 panel finished soon and can start working on this with you. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have "borrowed" ;-) this code from the well respected member dnaldoog, which he posted September 25, 2020 at 7:53 am on the old Ctrlr forum. It works and draws an image on an uiCustom Component. I need to find the colour of pixels to change them if needed, and it seems logical to use getPixalAt(x,y) in the image. But (as usually) I don't seem to get it working -:(
I know that a = Image:getPixelAt(30,30) is wrong, but I don't know what is the right code. TIA!
function graphicsLCD(mod,g)
frResource=resources:getResource("KurzScreen")
if frResource~=nil then
frImage = Image()
frImage = frResource:asImage()
g:setOpacity(1.0) -- 0.0 - 1.0
g:drawImageAt(frImage,0,0,false) -- x,y position in uiComponent
end -- image found
a = Image:getPixelAt(30,30)
console("color :"..a)
end
Beta Was this translation helpful? Give feedback.
All reactions