Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,61 @@
|
|||
%screen = Bitmap object
|
||||
%startPoint = [x0,y0]
|
||||
%endPoint = [x1,y1]
|
||||
%color = [red,green,blue]
|
||||
|
||||
function bresenhamLine(screen,startPoint,endPoint,color)
|
||||
|
||||
if( any(color > 255) )
|
||||
error 'RGB colors must be between 0 and 255';
|
||||
end
|
||||
|
||||
%Check for vertical line, x0 == x1
|
||||
if( startPoint(1) == endPoint(1) )
|
||||
%Draw vertical line
|
||||
for i = (startPoint(2):endPoint(2))
|
||||
setPixel(screen,[startPoint(1) i],color);
|
||||
end
|
||||
end
|
||||
|
||||
%Simplified Bresenham algorithm
|
||||
dx = abs(endPoint(1) - startPoint(1));
|
||||
dy = abs(endPoint(2) - startPoint(2));
|
||||
|
||||
if(startPoint(1) < endPoint(1))
|
||||
sx = 1;
|
||||
else
|
||||
sx = -1;
|
||||
end
|
||||
|
||||
if(startPoint(2) < endPoint(2))
|
||||
sy = 1;
|
||||
else
|
||||
sy = -1;
|
||||
end
|
||||
|
||||
err = dx - dy;
|
||||
pixel = startPoint;
|
||||
|
||||
while(true)
|
||||
|
||||
screen.setPixel(pixel,color); %setPixel(x0,y0)
|
||||
|
||||
if( pixel == endPoint )
|
||||
break;
|
||||
end
|
||||
|
||||
e2 = 2*err;
|
||||
|
||||
if( e2 > -dy )
|
||||
err = err - dy;
|
||||
pixel(1) = pixel(1) + sx;
|
||||
end
|
||||
|
||||
if( e2 < dx )
|
||||
err = err + dx;
|
||||
pixel(2) = pixel(2) + sy;
|
||||
end
|
||||
end
|
||||
|
||||
assignin('caller',inputname(1),screen); %saves the changes to the object
|
||||
end
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
>> img = Bitmap(800,600);
|
||||
>> img.bresenhamLine([400 550],[200 400],[255 255 255]);
|
||||
>> img.bresenhamLine([400 550],[600 400],[255 255 255]);
|
||||
>> img.bresenhamLine([200 400],[350 150],[255 255 255]);
|
||||
>> img.bresenhamLine([600 400],[450 150],[255 255 255]);
|
||||
>> img.bresenhamLine([350 150],[450 150],[255 255 255]);
|
||||
>> img.bresenhamLine([400 550],[400 150],[255 255 255]);
|
||||
>> disp(img)
|
||||
Loading…
Add table
Add a link
Reference in a new issue