### Author Topic: Aquarium with swaying kelp  (Read 555 times)

#### B+

• Full Member
• Posts: 215
##### Aquarium with swaying kelp
« on: October 14, 2016 »
Well I got the kelp to sway but the movie is a little blinky...

Code: [Select]
'aquarium with kelp.txt for NaaLaa 6 [B+=MGA] 2016-10-14
'tranlated from previous code

randomize(time())

visible:
xmax = 600
ymax = 300
pi# = 3.1415
kelp[xmax + 1][ymax + 1]

set window 180, 40, xmax, ymax
set redraw false

hidden:
'setup n fish x, y, length, dx (x speed), plasma colors r,b,g
n = 26
r# = 0.0 ; g# = 0.0 ; b# = 0.0
x[n]; y[n]; l[n]; dx[n]; rr#[n]; gg#[n]; bb#[n]
for i = 0 to n-1
x[i] = rnd(xmax)
y[i] = rnd(ymax)
l[i] = int(float(rnd(xmax)) * 0.0625 + 18.0)
dx[i] = rnd(4) + 2
d = rnd(2)
if d <> 0 then dx[i] = dx[i] * -1
r# = r# + 0.2     ; if r# > 0.5 then r# = 0.02   ; rr#[i] = r#
g# = g# + 0.005   ; if g# > 0.5 then g# = 0.005  ; gg#[i] = g#
b# = b# + 0.01    ; if b# > 0.5 then b# = 0.01   ; bb#[i] = b#
next

'setup kelp
set color 0, 128, 0
set caret 100, 130
wln "Please wait, growing the kelp..."
redraw
_growKelp
z = 0
while 1
for i = 0 to ymax-1
set color 0, 0, 255 - int( float#(i) / float#(ymax)  * 255.0 )
draw line 0, i, xmax, i
next
z = z + 1
z = z % 20
_showKelp z
'draw fish
for i = 0 to n-1
x[i] = x[i] + dx[i] + rnd(3)
if float#(x[i]) + 1.25 * float#(l[i]) < 0.0 then dx[i] = -1 * dx[i]
if float#(x[i]) - 1.25 * float#(l[i]) > float#(xmax) then dx[i] = -1 * dx[i]
y[i] = y[i] + rnd(3) - 1
for ra = 1 to l[i]
rd = int(127.0 + 127.0 * sin(rr#[i] * 3.0 * float#(ra)))
gn = int(127.0 + 127.0 * sin(gg#[i] * 3.0 * float#(ra)))
bl = int(127.0 + 127.0 * sin(bb#[i] * 3.0 * float#(ra)))
set color rd, gn, bl
if dx[i] < 0 then
draw line x[i] + ra, y[i] - ra, x[i] + ra, y[i] + ra
else
draw line x[i] - ra, y[i] - ra, x[i] - ra, y[i] + ra
endif
next
for ra = 5 to int(0.3 * float#(l[i]))
rd = int(127.0 + 127.0 * sin(rr#[i] * float#(ra)))
gn = int(127.0 + 127.0 * sin(gg#[i] * float#(ra)))
bl = int(127.0 + 127.0 * sin(bb#[i] * float#(ra)))
set color rd, gn, bl
if dx[i] < 0 then
draw line x[i] + l[i] + ra, y[i] - ra, x[i] + l[i] + ra, y[i] + ra
else
draw line x[i] - l[i] - ra, y[i] - ra, x[i] - l[i] - ra, y[i] + ra
endif
next
if dx[i] < 0 then
set colori 0
_rmDisk x[i] + int( 0.25 * float#(l[i]) ), y[i], int( 0.1 * float#(l[i]) )
set colori 0xFFFF00
_circByLine x[i] + int(0.25 * float#(l[i]) ), y[i], int( 0.06 * float#(l[i]) )
else
set colori 0x000000
_rmDisk x[i] - int(0.25 * float#(l[i]) ), y[i], int( 0.1 * float#(l[i]) )
set colori 0xFFFF00
_circByLine x[i] - int(0.25 * float#(l[i])), y[i], int( 0.06 * float#(l[i]) )
endif
next
redraw
wait 25
wend

procedure circByLine(x, y, r) 'may 25, 2015
rsq = r * r; ly = 0
for cx = r downto 0
cy = int(sqr#(float(rsq - cx * cx)))
x1 = x + cx; x2 = x - cx; y1 = y + ly; y2 = y+cy; y3 = y - ly; y4 = y - cy
draw line x1, y1, x1, y2
draw line x1, y3, x1, y4
draw line x2, y1, x2, y2
draw line x2, y3, x2, y4
ly = cy
next
endproc

procedure rmDisk(x, y, r)
rsq = r * r
for a = 0 to r
b = int(sqr(float(rsq - a * a)))
x1 = x + a; x2 = x - a; y1 = y - b; y2 = y + b
draw line x1, y1, x1, y2
draw line x2, y1, x2, y2
next
endproc

procedure growKelp()
d = 1
while d <= ymax
x = rnd(xmax)
y = d
c = 0
while y <> 0 and c = 0
if y - 1 >= 0 and x + 1 <= xmax + 1 and x - 1 >= 0
c = kelp[x][ y - 1]
if rnd(2) = 1 and kelp[x - 1][ y - 1] <> 0 then c = kelp[x - 1][y - 1]
if c = 0
c = kelp[x - 1][y - 1]
c = kelp[x + 1][y - 1]
y = y - 1
endif
else
c = (x % 23) + 1
endif
wend
if c = 0 then c = (x % 23) + 1
kelp[x][y] = c
if y = d - 1 then d = d + 1
wend
endproc

procedure showKelp(z)
for y = 0 to ymax
dy# = (float(y) * pi# / 180.0 + float(z)) * (float(y) / float(ymax))
xoff = int(5.0 * sin(float(dy#)))
for x = 0 to xmax
if kelp[x][y] > 0 and kelp[x][y] < 16 then
set color 0, kelp[x][y] * 16, 0
set pixel x + xoff, ymax - y
endif
next
next
endproc
B+

#### Marcus

• Hero Member
• Posts: 549
##### Re: Aquarium with swaying kelp
« Reply #1 on: November 03, 2016 »
Sorry for being late again, has been a busy time

Awesome demo without external Graphics!
.\\\opz

#### B+

• Full Member
• Posts: 215
##### Re: Aquarium with swaying kelp
« Reply #2 on: November 03, 2016 »
Sorry for being late again, has been a busy time

Awesome demo without external Graphics!

Thanks Marcus, "without external Graphics" is usually my MO (Modus Operendi = routine or habitually) because I missed all the classes on sprites in my BASIC training. So I parasitically use OP's such as yours in "Shooting Down Gorillas" and Johnno's in Flappy 3.

BTW, did you accidentally Cut instead of Copy code from Flappy 3 thread? The last code posted is missing everything except initial comments. (Sorry, I know you are busy guy!)
B+