I want to draw a circle (with 1 or 2 for loops) using pixels position (starts from top left and ends at bottom right)
I successfully drew a rectangle with this method:
private void drawrect(int width,int height,int x,int y) {
int top=y;
int left=x;
if(top<0){
height+=top;
top=0;
}
if(left<0){
width+=left;
left=0;
}
for (int j = 0; j <width; j++) {
for (int i = 0; i <height; i++) {
pixels[((i+top)*w)+j+left] = 0xffffff;//white color
}
}
}
The pixels array contains the pixel index followed by it's color.
pixels[index]=color;
Before that I use this code for "image" and "pixels" array (if this helps you)
img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
But how can I draw only the white pixels like in this image and ignore the other pixels?