Run-length encoding: Difference between revisions
Content added Content deleted
mNo edit summary |
mNo edit summary |
||
Line 2,836: | Line 2,836: | ||
<syntaxhighlight lang=FutureBasic> |
<syntaxhighlight lang=FutureBasic> |
||
Dynamic a(1, 1) as Short // Self-fulfilling array |
Dynamic a(1, 1) as Short // Self-fulfilling array, so don't need width and height |
||
local fn encode( string as CFStringRef) as CFStringRef |
local fn encode( string as CFStringRef) as CFStringRef |
||
Line 2,883: | Line 2,884: | ||
for i = 0 to len( string ) - 2 // Final char is ! |
for i = 0 to len( string ) - 2 // Final char is ! |
||
ch = mid( string, i, 1 ) |
ch = mid( string, i, 1 ) |
||
if intval( ch ) == 0 |
if intval( ch ) == 0 |
||
rl = 1 |
rl = 1 |
||
else |
else |
||
Line 2,890: | Line 2,891: | ||
ch = mid( string, i, 1 ) |
ch = mid( string, i, 1 ) |
||
end if |
end if |
||
select ch // Decode character |
select ch // Decode character as: |
||
case @"$" : f = -1 // new line |
case @"$" : f = -1 // - new line |
||
case @"b" : f = 0 // dead |
case @"b" : f = 0 // - dead |
||
case @"o" : f = 1 // live |
case @"o" : f = 1 // - live |
||
case else : // Ignore |
case else : // Ignore |
||
end select |
end select |
||
Line 2,900: | Line 2,901: | ||
x = 0 : y ++ : v = 0 // New line |
x = 0 : y ++ : v = 0 // New line |
||
else |
else |
||
a(x, y) = f |
a(x, y) = f |
||
x ++ : v ++ : if v > w then w = v |
|||
end if |
end if |
||
next // run |
next // run |