Author Topic: Aquarium  (Read 402 times)

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Aquarium
« on: August 28, 2016 »
Code: [Select]
'aquarium.txt for NaaLaa 6 [B+=MGA] 2016-08-27
'tranlated from previous code

xmax = 1200
ymax = 700
set window 80, 40, xmax, ymax
set redraw false
radians
n = 30
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(2) + 1
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

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
for i = 0 to n-1
x[i] = x[i] + dx[i]
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] * 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] + 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
      _DrawFilledCircle x[i] + int( 0.25 * float#(l[i]) ), y[i], int( 0.1 * float#(l[i]) )
set colori 0xFFFF00
      _DrawCircle x[i] + int(0.25 * float#(l[i]) ), y[i], int( 0.06 * float#(l[i]) )
else
set colori 0x000000
      _DrawFilledCircle x[i] - int(0.25 * float#(l[i]) ), y[i], int( 0.1 * float#(l[i]) )
set colori 0xFFFF00
      _DrawCircle x[i] - int(0.25 * float#(l[i])), y[i], int( 0.06 * float#(l[i]) )
endif
next
redraw
wend

procedure DrawCircle(x0, y0, radius)
x = radius
y = 0
err = 0
while x >= y
draw pixel x0 + x, y0 + y
draw pixel x0 - x, y0 + y
draw pixel x0 + y, y0 + x
draw pixel x0 - y, y0 + x
draw pixel x0 - x, y0 - y
draw pixel x0 + x, y0 - y
draw pixel x0 - y, y0 - x
draw pixel x0 + y, y0 - x
y = y + 1
err = err + 1 + 2*y
if 2*(err - x) + 1 > 0
x = x - 1
err = err + 1 - 2*x
endif
wend
endproc

procedure DrawFilledCircle(x0, y0, radius)
x = radius
y = 0
err = 0
while x >= y
x2 = x*2; y2 = y*2
draw rect x0 - x, y0 + y, x2, 1, true
draw rect x0 - y, y0 + x, y2, 1, true
draw rect x0 - x, y0 - y, x2, 1, true
draw rect x0 - y, y0 - x, y2, 1, true
y = y + 1
err = err + 1 + 2*y
if 2*(err - x) + 1 > 0
x = x - 1
err = err + 1 - 2*x
endif
wend
endproc
B+