05-02-2022, 03:10 AM
Tessellating fish
Code: (Select All)
defdbl a-z
dim shared pi, a1, a2, a, b, w1, w2, h
pi = 4*atn(1)
a1 = 14
a2 = 4
w = 30*7
w1 = w*5/7
w2 = w - w1
h = w*2/7
a = -h/a2/sin(pi*w/w1)
a = exp(log(a)/w)
b = a1*pi/w1/w2
sw = w*4 + w2
sh = h*8 + 114
screen _newimage(sw, sh, 32)
line (0,0)-(sw, sh),_rgb(255,255,255),bf
for i=-1 to 4
for j=-1 to 4
fish w2 + i*w, 50 + h*j*2, w, i and 1
fish sw - w2 - i*w, 50 + h*j*2 + h, -w, i and 1
next
next
sleep
system
function f(x, aa)
f = aa*(a^x)*sin(pi*x/w1)
end function
function g(x, v)
g = b*x*(x - v)
end function
sub fish(x0, y0, ww, u)
dim c1 as _unsigned long
dim c2 as _unsigned long
c1 = _rgb(200,200,200)
c2 = _rgb(255,255,255)
if u then swap c1, c2
w = abs(ww)
s = sgn(ww)
'background
color c1
for x=w to w1 step -1
line (x0 + s*(x - w), y0 - f(x, a2))-(x0 + s*(x - w), y0 - g(x - w, -w2))
next
for x=0 to w1
line (x0 + s*x, y0 - f(x, a2))-(x0 + s*x, y0 + h - f(w1 - x, a1))
next
for x=0 to w2
line (x0 + s*(w - x), y0 + h - g(-x, -w2))-(x0 + s*(w - x), y0 - f(w - x, a2))
next
for xx=0 to w1/3/7
if xx>0 and xx<w1/3/7 then
x = xx*3*7 + 3
ox = x0 + s*x
oy = y0 - f(x, a1)
oy2 = y0 + h - f(w1 - x, a2)
for zz=0 to 3*7 + 2
z = xx*3*7 + zz
line (ox, oy)-(x0 + s*z, y0 - f(z, a2))
line (ox, oy2)-(x0 + s*z, y0 + h - f(w1 - z, a1))
next
end if
next
color _rgb(0,0,0)
'closed shape
pset (x0, y0)
for x=0 to w
line -(x0 + s*x, y0 - f(x, a2))
next
for x=0 to w2
line -(x0 + s*(w - x), y0 + h - g(-x, -w2))
next
for x=0 to w1
line -(x0 + s*(w1 - x), y0 + h - f(x, a1))
next
for x=w to w1 step -1
line -(x0 + s*(x - w), y0 - f(x, a2))
next
for x=0 to w2
line -(x0 - s*(w2 - x), y0 - g(x, w2))
next
for x=0 to w1
line -(x0 + s*x, y0 - f(x, a1))
next
'flourish
circle (x0 + s*w1, y0 + 21), 3, c2
paint (x0 + s*w1, y0 + 21), c2
circle (x0 + s*w1, y0 + 21), 3
for xx=0 to w1/3/7
if xx=1 then
x = xx*3*7 + 3
pset (x0 + s*x, y0 - f(x, a1))
elseif xx>1 and xx<w1/3/7 - 1 then
x = xx*3*7
line -(x0 + s*x, y0 - f(x, a2))
x = x + 3
line -(x0 + s*x, y0 - f(x, a1))
end if
next
for xx=0 to w1/3/7
if xx=0 then
x = (xx + 1)*3*7 + 3
pset (x0 + s*x, y0 + h - f(w1 - x, a2))
elseif xx>0 and xx<w1/3/7 then
x = xx*3*7
line -(x0 + s*x, y0 + h - f(w1 - x, a1))
x = x + 3
line -(x0 + s*x, y0 + h - f(w1 - x, a2))
end if
next
for xx=1 to w2/8 - 1
x = w - xx*8
x2 = w - xx*6.5 - 7
line (x0 + s*(x - w), y0 - f(x, a2))-(x0 + s*(x2 + 2*7-w), y0 - f(x2, a2))
next
end sub