I’m a beginner trying to get accustomed to working in oF. I’m a little more familiar with p5 and I thought of trying to recreate this sketch in oF.
My strategy thus far has been to consider the function and method calls in the p5 sketch and find their equivalents in oF but I’m falling short of the mark when it comes to many of the method calls on the image object in p5 - I’ve been trying to navigate these using ‘ofImage’ and ‘ofPixels’ but I’m coming up short. Anybody care to give me a clue?
Hey @obAir , porting sketches in other languages is a great way to lear oF! Also check out all of the chapters in ofBook (scroll down a bit to find them), and there are some wonderful video tutorials on youtube too. The forum threads can be searched for specifc topics, and its an amazing resource for solving problems and learning some of the nuances of C++ and oF.
Using the online documentation for ofImage and ofPixels is the right place to search for equivalent functions to the code you posted. C++ uses a lot of “setters and getters” to set and get class members that are either protected or private within a class. So the following may offer some equivalency:
// create a couple of instances
// maybe the same as img.loadPixels() ?
pixels = image.getPixels();
// imgX and imgY: ofMap returns a float; imgX and imgY could be a floats or an ints,
// but floats may retain the rounding a bit better
float imgX = glm::round(ofMap(x, 0.f, width, 0.f, image.getWidth()));
int imgY = glm::round(ofMap(y, 0.f, height, 0.f, image.getHeight()));
// there are 2 variations of ofImage::getColor()
// get the color of the pixel in the image at coordinate (imgX, imgY).
c = image.getColor(imgX, imgY);
float grayscale = glm::round(c.r * 0.222 + c.g * 0.707 + c.b * 0.071);
Hey @TimChi - I missed this reply entirely.
Thank you for the helpful response. I’m gonna take a little further look into that book and I’ll have a look at that code you sent on.
Man thanks for the advice and I’ll keep at it.
Hey Ben @obAir I forgot to mention that oF has a ton of example projects in the /examples folder, and they are also super helpful when learning about the different classes. Have fun!