m5stack / M5GFX

Graphics library for M5Stack series
MIT License
166 stars 47 forks source link

Question: How can I draw a masked shape? #98

Closed botamochi6277 closed 3 months ago

botamochi6277 commented 4 months ago

I want to draw a masked shape in display. For example, circle A masked by circle B in the following picture. Frame 1

Would you have any ideas to draw the A AND B?

I have a rough idea using bool computation like this. I am worry about amount of memories with this approach. And, is it able with M5GFX?

uint32_t img[HEIGHT][WIDTH]; 
uint32_t masked_img[HEIGHT][WIDTH]; 
uint8_t mask[HEIGHT][WIDTH]; 

fillCircle(img,10,50,100); // draw circle A
fillCircle(mask,50,10,100); // draw circle B
bitwise_and(img,mask,mask_img); // masking

display(masked_img);
lovyan03 commented 3 months ago

Hello, @botamochi6277

Currently M5GFX does not have the functionality to handle bitmasks, so it must be implemented entirely in user code.

Other suggestions include the following functionality:

#include <M5GFX.h>

M5GFX gfx;
M5Canvas cv;

void setup() {
    gfx.begin();

    cv.setColorDepth(2);
    cv.createSprite(160, 160);

    cv.drawCircle(50, 90, 50, 2);
    cv.drawCircle(90, 50, 50, 2);

    cv.floodFill(70, 70, 3);

    cv.setPaletteColor(3, TFT_YELLOW);

    cv.pushSprite(&gfx, 0, 0);
}

void loop() {}

image

botamochi6277 commented 3 months ago

Thanks for your reply. Sorry for the delay in commenting. Oh, I got to know 🪣 M5Canvas::floodFill method. Your proposed code succeeds in my M5Stack and looks good. I will try to use this approach. Thx.