drawline problem

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

drawline problem

karam
hello
im trying to implement the algorithm
of drawline() in screen class
i did exactly as the slides say
but when i try to run the program nothing is printed on the screen
ther is no error


function void drawLine(int x1, int y1, int x2, int y2) {
        var int a,b,diff,dx,dy;
        let a=0;
        let b=0;
  let diff=0;
        let dx=x2-x1;
        let dy=y2-y1;

        while(~(a>dx) & ~(b>dy)){
           if(diff<0){
             let a=a+1;
             let diff=diff+dy;
           }
           else{
            let b=b+1;
            let diff=diff-dx;
           }
           do Screen.drawPixel(x1 + a, y1 + b);
        }
        return;
    }
Reply | Threaded
Open this post in threaded view
|

Re: drawline problem

WBahn
Administrator
Are you sure that the values your are using result in dx and dy both being positive?

Have you confirmed that your drawPixel() function is working properly?
Reply | Threaded
Open this post in threaded view
|

Re: drawline problem

karam
in the drawpixel() i get the x%16 bit as the slide say
and i set that bit to 1 if the color desire is black else white
 here is my code :
function void drawPixel(int x, int y) {
        var int address,value,modulo;
        let address=16384 +(32 * y) + (x / 16);
        let value=Memory.peek(address);
        let modulo=x-((x/16)*16);
        if(setblack){
          let value=value | twoToThe[modulo];
        }
        else{
         let value=value & (~twoToThe[modulo]);
        }
        do Memory.poke(address,value);
        return;
    }