I want to draw pixels in bigger sizes with more simple methods

Hi,

I want a simple way to draw pixels in bigger shapes. I want to test basic pixel draw functions; like, lines, circles, rectangles … etc. With small resolutions like 128 x 64.

Even if you know a simple library that can be found on a C compiler, then that would be nice too. I tried to work with

graphics.h

In codeblocks but I got an error saying “cannot find -lbgi” and it got more complicated to setup this library.

So I thought to go back to processing because I remember I was able to draw some pixels before so I’m trying now and having some problems with the pixel size, that it’s too small for the resolution I want to work on.

I tried this simple example:

size(800, 800);
// Before we deal with pixels
loadPixels();
// Loop through every pixel
for (int i = 0; i < pixels.length; i++) {
  // Pick a random number, 0 to 255
  float rand = random(255);
  // Create a grayscale color based on random number
  color c = color(rand);
  // Set pixel at that location to random color
  pixels[i] = c;
}
// When we are finished dealing with pixels
updatePixels();

But as I mentioned the pixels are too small for me.

I want to simulate my pixels draw functions in C with processing or any other C compiler instead of uploading the code constantly to the microcontroller.

I want to practice on my computer monitor, for fast work process.

1 Like

Hi,

I solved the problem, I found an old snippet that worked for me and I put it in my C draw line function and it worked.

PImage img;
boolean glcd_func_lock, glcd_func_flag;
int px, py, st_x, st_y, end_x, end_y, st_p, end_p, h, w;
int dir0, dir1;


void setup() {
  size(1280, 640);
  background(255);
  img = createImage(1,1,RGB);  
  scale(10);
  img.loadPixels();
  
  
  glcd_func_flag = false;
  while(glcd_func_flag != true){glcd_line(0,128,0,64);}

  
  

}

void glcd_line(int x0, int x1, int y0, int y1){
  if((x0 > 128) || (x0 < 0) || (x1 > 128) || (x1 < 0) ||
  (y0 > 64) || (y0 < 0) || (y1 > 64) || (y1 < 0)){ return; }
  
  if(!glcd_func_lock){
    
    if      (x0 > x1)  { w = x0 - x1; st_x = x1; end_x = st_x + w; }
    else if (x1 > x0)  { w = x1 - x0; st_x = x0; end_x = st_x + w; }
    //else if (x0 == x1) { w = 1; dir = 0; px = st_x = end_x = x0; }
    
    if      (y0 > y1)  { h = y0 - y1; st_y = y1; end_y = st_y + h; }
    else if (y1 > y0)  { h = y1 - y0; st_y = y0; end_y = st_y + h; }
    //else if (y0 == y1) { h = 1; dir = 0; py = st_y = end_y = y0; }
    
    if(w > h){ st_p = st_x; end_p = end_x; dir0 = w; dir1 = h; }
    else     { st_p = st_y; end_p = end_y; dir0 = h; dir1 = w; }
    
    glcd_func_lock = true;
  }
  
  if((st_p < end_p)){
    py = st_y + dir1 * (px - st_x) / dir0;
    image(img, px, py);
    px++;
  }
  else{
    glcd_func_lock = false; glcd_func_flag = true;
  }  
}

It works but I have to improve the function more.

1 Like