Skip to content

Instantly share code, notes, and snippets.

@2DArray
Created April 15, 2018 17:41
Show Gist options
  • Save 2DArray/4b933f062793225c9a958fa96c088edb to your computer and use it in GitHub Desktop.
Save 2DArray/4b933f062793225c9a958fa96c088edb to your computer and use it in GitHub Desktop.
function drawfish(cfish,fishx,fishy,scale)
srand(cfish.seed)
local length=flr(20+cfish.size*5)
length=min(length,120)
local keycount=-flr(-length/(5+rnd(20)))
local keys={}
keys[1]=0
for i=2,keycount do
keys[i]=(rnd(length/8)+length/16)*scale
if i==keycount-2 then
keys[i]*=.5
end
end
local bcol=flr(rnd(15))
local qual=cfish.quality/2
local cqual=mid(qual,0,1)
local colstepx=flr(rnd(15)*cqual)
local colstepy=flr(rnd(4)*cqual)
local colstepk=flr(rnd(4)*cqual)
local colsize=flr(rnd(25)*(1-cqual)+7)
local colsize2=flr(rnd(25)*(1-cqual)+7)
local fcoloff=rnd(colsize)
local stripes=flr(rnd(3)*cqual+1)
local finpos=rnd(.3)+.3
local finmult=rnd(.8)*qual+.7
local finexp=rnd(3)+2
local xwob=-rnd(length/20)
local ywob=rnd(length/20)
local wobspeed=(rnd(.5)+.5)*cfish.live
local eyexpos=rnd(.15)+.1
local eyeypos=rnd(.6)+.2
local eyesize=2+rnd(length/40)
local dcolbody=flr(rnd(9))+2
local dcolfin=flr(rnd(9))+2
pupilcol=rnd(15)
local eyex,eyey
local bdithers=cfish.bdithers
local fdithers=cfish.fdithers
local oldx=fishx-length*scale/2
for i=0,length-1,1/scale do
local t=i/length
local ki=flr(t*(keycount-1))+1
local kf=t*(keycount-1)-ki+1
kf=3*kf*kf-2*kf*kf*kf
local rad=keys[ki]+(keys[ki+1]-keys[ki])*kf
local coli=flr(i/colsize)
local coli2=flr((i+fcoloff)/colsize2)
local xoff=cos(time()*wobspeed-t)*(1+xwob*t)
local x=fishx+(-length/2+i+xoff)*scale
local y=fishy+(sin(time()*wobspeed-t)*(1+ywob*t))*scale
fillp(band(rotr(bdithers[flr((xoff+fishx)%4)+1],flr(y%4)*4),bnot(0b0.1)))
if i<length*eyexpos and i+1/scale>=length*eyexpos then
eyex=x
eyey=y-rad*eyeypos
end
for j=0,stripes-1 do
y1=y-rad+j*rad*2/stripes
y2=y-rad+(j+1)*rad*2/stripes
local col=((colstepx*coli+colstepy*(j%2))%8+bcol)%15+1
rectfill(oldx+1,y1,x,y2,col+16*dcolbody)
end
for i=0,rad/2 do
if rnd()*cqual>(i/(rad/2)) then
for j=-1,1,2 do
pset(x,y+(rad-i)*j,pget(x,y+(rad-i)*j)-1)
end
end
end
local fin=(1-mid(abs(t-finpos)/finpos,0,1))^finexp+mid(1-abs(t-.95)*2,0,1)^finexp
local frad=length/3*fin*finmult*scale
frad=min(frad,60)
if frad>rad then
fillp(band(rotr(fdithers[flr((xoff+fishx)%4)+1],flr(y%4)*4),bnot(0b0.1)))
col=((colstepx*coli2+colstepk)%8+bcol)%15+1
rectfill(oldx+1,y-frad,x,y-rad-2,col+16*dcolfin)
rectfill(oldx+1,y+rad+2,x,y+frad,col+16*dcolfin)
line(x,y-frad-1,x,y-frad-2,0)
line(x,y+frad+1,x,y+frad+2,0)
for i=0,(frad-rad)/2 do
if rnd()*cqual>(i/((frad-rad)/2)) then
local col=pget(x,y-frad+i)
pset(x,y-frad+i,col-1)
local col2=pget(x,y+frad-i)
pset(x,y+frad-i,col2-1)
end
end
end
rect(oldx,y-rad-1,x,y-rad-2,0)
rect(oldx,y+rad+1,x,y+rad+2,0)
oldx=x
end
fillp()
circfill(eyex,eyey+1,eyesize*scale,5)
circfill(eyex,eyey,eyesize*scale,6)
circfill(eyex,eyey,(eyesize-1)*scale,7)
if cfish.live>0 then
circfill(eyex-eyesize/3,eyey,eyesize/2*scale,pupilcol)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment