Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
|
|
@ -1,42 +0,0 @@
|
|||
# -*- coding: utf-8 -*- #
|
||||
|
||||
line OF class image := (REF IMAGE picture, POINT start, stop, PIXEL color)VOID:
|
||||
BEGIN
|
||||
REAL dx = ABS (x OF stop - x OF start),
|
||||
dy = ABS (y OF stop - y OF start);
|
||||
REAL err;
|
||||
POINT here := start,
|
||||
step := (1, 1);
|
||||
IF x OF start > x OF stop THEN
|
||||
x OF step := -1
|
||||
FI;
|
||||
IF y OF start > y OF stop THEN
|
||||
y OF step := -1
|
||||
FI;
|
||||
IF dx > dy THEN
|
||||
err := dx / 2;
|
||||
WHILE x OF here /= x OF stop DO
|
||||
picture[x OF here, y OF here] := color;
|
||||
err -:= dy;
|
||||
IF err < 0 THEN
|
||||
y OF here +:= y OF step;
|
||||
err +:= dx
|
||||
FI;
|
||||
x OF here +:= x OF step
|
||||
OD
|
||||
ELSE
|
||||
err := dy / 2;
|
||||
WHILE y OF here /= y OF stop DO
|
||||
picture[x OF here, y OF here] := color;
|
||||
err -:= dx;
|
||||
IF err < 0 THEN
|
||||
x OF here +:= x OF step;
|
||||
err +:= dy
|
||||
FI;
|
||||
y OF here +:= y OF step
|
||||
OD
|
||||
FI;
|
||||
picture[x OF here, y OF here] := color # ensure dots to be drawn #
|
||||
END # line #;
|
||||
|
||||
SKIP
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
#!/usr/bin/a68g --script #
|
||||
# -*- coding: utf-8 -*- #
|
||||
|
||||
PR READ "prelude/Bitmap.a68" PR; # c.f. [[rc:Bitmap]] #
|
||||
PR READ "prelude/Bitmap.a68" PR;
|
||||
PR READ "prelude/Bitmap/Bresenhams_line_algorithm.a68" PR;
|
||||
|
||||
### The test program: ###
|
||||
test:(
|
||||
(
|
||||
REF IMAGE x = INIT LOC[1:16, 1:16]PIXEL;
|
||||
(fill OF class image)(x, white OF class image);
|
||||
(line OF class image)(x, ( 1, 8), ( 8,16), black OF class image);
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
; Bitmap object definition
|
||||
define :bitmap [
|
||||
init: method [width :integer height :integer][
|
||||
\width: width
|
||||
\height: height
|
||||
\grid: array.of:@[width height] false
|
||||
]
|
||||
|
||||
setOn: method [x :integer y :integer][
|
||||
\grid\[y]\[x]: true
|
||||
]
|
||||
|
||||
line: method [x0 :integer y0 :integer x1 :integer y1 :integer][
|
||||
[dx,dy]: @[abs x1 - x0, abs y1 - y0]
|
||||
[x,y]: @[x0, y0]
|
||||
sx: (x0 > x1) ? -> neg 1 -> 1
|
||||
sy: (y0 > y1) ? -> neg 1 -> 1
|
||||
|
||||
switch dx > dy [
|
||||
err: dx // 2
|
||||
while [x <> x1][
|
||||
\setOn x y
|
||||
if negative? err: <= err - dy ->
|
||||
[y, err]: @[y + sy, err + dx]
|
||||
|
||||
x: x + sx
|
||||
]
|
||||
][
|
||||
err: dy // 2
|
||||
while [y <> y1][
|
||||
\setOn x y
|
||||
if negative? err: <= err - dx ->
|
||||
[x, err]: @[x + sx, err + dy]
|
||||
y: y + sy
|
||||
]
|
||||
]
|
||||
\setOn x y
|
||||
]
|
||||
|
||||
string: method [][
|
||||
join.with:"\n" @[
|
||||
"+" ++ (repeat "-" \width) ++ "+"
|
||||
join.with:"\n" map 0..dec \height 'y [
|
||||
"|" ++ (join.with:"" map 0..dec \width 'x ->
|
||||
\grid\[dec \height-y]\[x] ? -> "@" -> " "
|
||||
) ++ "|"
|
||||
]
|
||||
"+" ++ (repeat "-" \width) ++ "+"
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
; Create bitmap
|
||||
bitmap: to :bitmap @[17 17]!
|
||||
|
||||
; and... draw a diamond shape
|
||||
points: @[
|
||||
[1 8 8 16]
|
||||
[8 16 16 8]
|
||||
[16 8 8 1]
|
||||
[8 1 1 8]
|
||||
]
|
||||
|
||||
loop points 'p ->
|
||||
bitmap\line p\0 p\1 p\2 p\3
|
||||
|
||||
print bitmap
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
' using Twips
|
||||
' twipsX is 15 twips. So for 96 dpi, we have 1440/96=15 twips/pixel
|
||||
Module Bresenham_s_line_algorithm {
|
||||
Module Br_line(x0 As Long, y0 As Long, x1 As Long, y1 As Long, Col=15) {
|
||||
Long dx = Abs(x1 - x0), dy = Abs(y1 - y0)
|
||||
Long sx = If(x0 < x1-> TWIPSX, -TWIPSX)
|
||||
Long sy = If(y0 < y1-> TWIPSY, -TWIPSY)
|
||||
Long er = If(dx > dy-> dx, -dy) div 2, e2
|
||||
Do
|
||||
PSet col, x0, y0
|
||||
If abs(x0-x1)<=TWIPSX And abs(y0-y1)<=TWIPSY Then Exit
|
||||
e2 = er
|
||||
If e2 > -dx Then Er -= dy : x0 += sx
|
||||
If e2 < dy Then Er += dx : y0 += sy
|
||||
Always
|
||||
}
|
||||
cls ,0
|
||||
Br_line scale.x*.2, scale.y*.2, scale.x*.8, scale.y*.8 , #FFbb77
|
||||
}
|
||||
Bresenham_s_line_algorithm
|
||||
Loading…
Add table
Add a link
Reference in a new issue