Display Array of Pixels
in
Programming Questions
•
1 year ago
I've written a code to display a array of pixels.
I'm quite new to programming and would like to learn how to code more efficient.
So my questions is, if there is a much faster way to do this, cause i'm about to programm a little game upon this function.
Thank you!
I'm quite new to programming and would like to learn how to code more efficient.
So my questions is, if there is a much faster way to do this, cause i'm about to programm a little game upon this function.
- final int QUANT = 4; // size of 'game pixels'
- void setup(){
- size(200,200);
- background(255);
- // defines the bitmap image that should be displayed
- byte[][] bild =
- {{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0},
- {0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0},
- {0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1},
- {0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0},
- {0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0},
- {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
- // calls the function to display the image at x=1,y=3
- draw_img(1,3,bild);
- }
- void draw_img(int _x,int _y, byte[][] img){
- // following loops go through every pixel of the image
- for(int y = 0; y < img.length; y++){
- for(int x = 0; x < img[y].length; x++){
- // checks if current pixel is black (1)
- if(img[y][x]==1){
- // draws pixels in size of QUANT
- for(int i = 0; i < QUANT; i++){
- for(int j = 0; j < QUANT; j++){
- set(x*QUANT+j+_x*QUANT, y*QUANT+i+_y*QUANT, color(0));
- }
- }
- }
- }
- }
- }
Thank you!
1