1. hints
- Posted by jiri babor <jbabor at PARADISE.NET.NZ>
Apr 27, 2000
-
Last edited Apr 28, 2000
Hi, Everybody,
Attached is a small 'plasma' program you can explore by changing a
simple formula. It's a loose adaptation of Konrad Olejnik's TMT Pascal
code. The original source is somewhat bigger in comparison with my
effort, but only because it does not use any includes or external
modules (units). It is also significantly faster, basically because
it's compiled (hint no 1, Rob), and because it is based on a memory
array with faster indexing AND *direct* mapping (hint no 2).
Enjoy. jiri
-- plasma.ex : loose translation of K!O's plasma in pascal
-- jiri babor 00-04-27
include machine.e
include graphics.e
constant
A = #A0000, -- video memory
pi = 3.14159,
N = 320*200,
v = allocate(N) -- virtual screen
object o,p,c,s,line
atom a
integer m,n
line = repeat(0,320)
c = repeat(0,256)
s = c
p = c
for i=1 to 256 do
s[i] = floor(256*sin(2*i*pi/256)) -- sine table
c[i] = floor(128*sin(2*i*pi/256)) -- cosine table
end for
for i=0 to 127 do
p[i+1] = {i/2,i/4,i/8}
p[256-i] = p[i+1]
end for
o = graphics_mode(19)
all_palette(p)
m = 0 n = 0
while get_key()=-1 do
a = v
for y=0 to 199 do
for x=1 to 320 do
line[x] = 3*x + c[and_bits(c[and_bits(x+m,255)+1]+
s[and_bits(y+n,255)+1],255)+1]
end for
poke(a,line)
a += 320
end for
mem_copy(A,v,N)
m -= 2 n += 3
end while
o = graphics_mode(-1)