Bitmap/Bresenham's line algorithm: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
(Added solution for Action!) |
||
Line 323: | Line 323: | ||
...|.................... |
...|.................... |
||
</pre> |
</pre> |
||
=={{header|Action!}}== |
|||
Part of the task is available in [http://www.rosettacode.org/wiki/Category:Action!_Bitmap_tools#RGBLINE.ACT RGBLINE.ACT]. |
|||
{{libheader|Action! Bitmap tools}} |
|||
<lang Action!>INCLUDE "H6:RGBLINE.ACT" ;from task Bresenham's line algorithm |
|||
RGB black,yellow,violet,blue |
|||
PROC DrawImage(RgbImage POINTER img BYTE x,y) |
|||
RGB POINTER ptr |
|||
BYTE i,j |
|||
ptr=img.data |
|||
FOR j=0 TO img.h-1 |
|||
DO |
|||
FOR i=0 TO img.w-1 |
|||
DO |
|||
IF RgbEqual(ptr,yellow) THEN |
|||
Color=1 |
|||
ELSEIF RgbEqual(ptr,violet) THEN |
|||
Color=2 |
|||
ELSEIF RgbEqual(ptr,blue) THEN |
|||
Color=3 |
|||
ELSE |
|||
Color=0 |
|||
FI |
|||
Plot(x+i,y+j) |
|||
ptr==+RGBSIZE |
|||
OD |
|||
OD |
|||
RETURN |
|||
PROC Main() |
|||
RgbImage img |
|||
BYTE CH=$02FC,width=[81],height=[51],st=[5] |
|||
BYTE ARRAY ptr(12393) |
|||
BYTE c,i,n |
|||
INT x,y,nx,ny |
|||
RGB POINTER col |
|||
Graphics(7+16) |
|||
SetColor(0,13,12) ;yellow |
|||
SetColor(1,4,8) ;violet |
|||
SetColor(2,8,6) ;blue |
|||
SetColor(4,0,0) ;black |
|||
RgbBlack(black) |
|||
RgbYellow(yellow) |
|||
RgbViolet(violet) |
|||
RgbBlue(blue) |
|||
InitRgbImage(img,width,height,ptr) |
|||
FillRgbImage(img,black) |
|||
nx=width/st ny=height/st |
|||
FOR n=0 TO 2*nx+2*ny-1 |
|||
DO |
|||
IF n MOD 3=0 THEN col=yellow |
|||
ELSEIF n MOD 3=1 THEN col=violet |
|||
ELSE col=blue FI |
|||
IF n<nx THEN |
|||
x=n*st y=0 |
|||
ELSEIF n<nx+ny THEN |
|||
x=width-1 y=(n-nx)*st |
|||
ELSEIF n<2*nx+ny THEN |
|||
x=width-1-(n-nx-ny)*st y=height-1 |
|||
ELSE |
|||
x=0 y=height-1-(n-2*nx-ny)*st |
|||
FI |
|||
RgbLine(img,width/2,height/2,x,y,col) |
|||
OD |
|||
DrawImage(img,(160-width)/2,(96-height)/2) |
|||
DO UNTIL CH#$FF OD |
|||
CH=$FF |
|||
RETURN</lang> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Bresenham's_line_algorithm.png Screenshot from Atari 8-bit computer] |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |