Author Topic: Morph Curve on Plasma  (Read 1859 times)

B+

  • Guest
Morph Curve on Plasma
« on: April 11, 2017, 06:38:29 PM »
Code: [Select]
' Morph Curve on Plasma.bas  SmallBASIC 0.12.8 [B+=MGA] 2017-04-11
'from SpecBAS version Paul Dunn Dec 2, 2015
'https://www.youtube.com/watch?v=j2rmBRLEVms
' mods draw lines segments with drawpoly, add plasma, play with numbers

pts = 1200 : interps = 30
dim p(pts + 1, 1), q(pts + 1, 1), s(pts + 1, 1), i(interps)
l = 0 : cx = xmax/2 : cy = ymax/2 : sc = cy*.5 : st = 2*pi/pts
for n = 1 to interps
  i(n) = sin(n/interps*(pi/2))
next
while 1
  resetPlasma
  n = int(rnd*75) + 2 : m = int(rnd*500) - 250 : c = 0
  for t = 0 to 2*pi step st
    q(c, 0) = cx + sc*(cos(t) + cos(n*t)/2 + sin(m*t)/3)
    q(c, 1) = cy + sc*(sin(t) + sin(n*t)/2 + cos(m*t)/3)
    setPlasma
    if t > 0 then pline lastx, lasty, q(c, 0), q(c, 1), 10
    lastx = q(c, 0) : lasty = q(c, 1)
    c += 1
  next
  q(c, 0) = q(0, 0) : q(c, 1) = q(0, 1)
  if l = 0 then
    'drawpoly q
    l += 1
    showpage
    'delay 2000
  else
    for t = 1 to interps
      cls
      for n = 0 to pts
        s(n, 0) = q(n, 0) * i(t) + p(n, 0) *(1 - i(t))
        s(n, 1) = q(n, 1) * i(t) + p(n, 1) *(1 - i(t))
        setPlasma
        if n > 0 then pline lastx, lasty, s(n, 0), s(n, 1), 10
        lastx = s(n, 0) : lasty = s(n, 1)
      next
      s(n, 0) = s(0, 0)
      s(n, 1) = s(0, 1)
      'drawpoly s
      showpage
      'delay 40 
    next
  fi
  p = q
  'drawpoly p
  showpage
  delay 3000
wend

'fast thick line!!!
sub pline(x1, y1, x2, y2, thick) 'this draws a little rectangle
  local arr, r, dx, dy, perpA1, perpA2
  dim arr()
  r = thick/2
  dx = x2 - x1
  dy = y2 - y1
  perpA1 = atan2(dy, dx) + pi/2
  perpA2 = perpA1 - pi
  arr << x1 + r * cos(perpA1) 'corner 1
  arr << y1 + r * sin(perpA1)
  arr << x2 + r * cos(perpA1) 'corner 2
  arr << y2 + r * sin(perpA1)
  arr << x2 + r * cos(perpA2) 'corner 3
  arr << y2 + r * sin(perpA2)
  arr << x1 + r * cos(perpA2) 'corner 4
  arr << y1 + r * sin(perpA2)
  arr << x1 + r * cos(perpA1) 'back to first corner
  arr << y1 + r * sin(perpA1)
  drawpoly arr 'filled   'filled or not ?
end

sub resetPlasma() 'all globals
    plasmaR = rnd ^ 2 : plasmaG = rnd ^ 2 : plasmaB = rnd ^ 2 : plasmaN = 0
end

sub setPlasma() 'all globals
    plasmaN += .37
    color rgb(120+84*sin(plasmaR*plasmaN), 120+84*sin(plasmaG*plasmaN), 120+84*sin(plasmaB*plasmaN))
end

B+

  • Guest
Re: Morph Curve on Plasma
« Reply #1 on: April 11, 2017, 06:50:30 PM »
A version with thinner line fills:

Mike Lobanovsky

  • Guest
Re: Morph Curve on Plasma
« Reply #2 on: April 11, 2017, 10:35:11 PM »
Anti-aliasing seems to be doing much to improve the overall impression.

B+

  • Guest
Re: Morph Curve on Plasma
« Reply #3 on: April 12, 2017, 01:01:16 AM »
Yes, a shade better.  ;)

Code: [Select]
option predef antialias off

ZXDunny

  • Guest
Re: Morph Curve on Plasma
« Reply #4 on: April 12, 2017, 08:34:07 AM »
Very nice :)

I must add thick line fills to SpecBAS, when I get the time... I'm currently up to my elbows in the new editor though - wordwrapping is a pain in the ass, when you have a restriction that lines can't start with a number :)

B+

  • Guest
Re: Morph Curve on Plasma
« Reply #5 on: April 14, 2017, 11:48:24 PM »
Here is SdlBasic version that systematically increments two main variables before going into random curves mode. Using simple white lines on black background because watching these loops bend around is coolest part!:

Code: [Select]
' morph curve.sdlbas [B+=MGA] 2017-04-14
' from Morph Curve.bas  SmallBASIC 0.12.8 [B+=MGA] 2017-04-11
' from SpecBAS version Paul Dunn Dec 2, 2015
' https://www.youtube.com/watch?v=j2rmBRLEVms

function rand(n1, n2)  ' numbers between n1, n2 inclusive, no worries first and second argument
if n1 > n2 then
hi = n1 : lo = n2
else
hi = n2 : lo = n1
end if
rand = rnd(hi - lo + 2) + lo - 1
end function

randomize(timer)
option qbasic
const xmax = 700
const ymax = 700
setdisplay(xmax, ymax, 32, 1)
setcaption(" Morph Curve For SdlBasic: Systematic Simple Curves")
autoback(-10)

pts = 6000 : interps = 20 : pi = acos(-1)
dim p[pts + 1, 1], q[pts + 1, 1], s[pts + 1, 1], i[interps]
l = 0 : cx = xmax/2 : cy = ymax/2 : sc = cy*.4 : st = 2*pi/pts
for n = 1 to interps
i[n] = sin(n/interps*(pi/2))
next
n = 0 : m = 0 : rmode = 0
while 1
cls
c = 0
if rmode = 0 then
n += 1
if n > 12 then : n = 1 : m = m + 1 : end if
if m > 12 then
rmode = 1 : n = rand(2, 75) : m = rand(-250, 250)
setcaption(" Morph Curve For SdlBasic: Random Curves")
end if
else
n = rand(2, 75) : m = rand(-250, 250)
end if
text(10, 10, 16, "m = " + str(m) + "  n = " + str(n)  )
for t = 0 to 2*pi step st
q[c, 0] = cx + sc*(cos(t) + cos(n*t)/2 + sin(m*t)/3)
q[c, 1] = cy + sc*(sin(t) + sin(n*t)/2 + cos(m*t)/3)
if t > 0 then
'if lastx > 50 and lasty >50 and q[c, 0] > 50 and q[c, 1] > 50 then
line(q[c, 0], q[c, 1], lastx, lasty)
'end if
end if
lastx = q[c, 0] : lasty = q[c, 1]
c += 1
next
if l = 0 then
l += 1
screenswap
else
for t = 1 to interps
cls
text(10, 10, 16, "m = " + str(m) + "  n = " + str(n)  )
for nn = 0 to pts
s[nn, 0] = q[nn, 0] * i[t] + p[nn, 0] *(1 - i[t])
s[nn, 1] = q[nn, 1] * i[t] + p[nn, 1] *(1 - i[t])
if n > 0 then
'if lastx > 50 and lasty > 50 and s[nn, 0] > 50 and s[nn, 1] > 50 then
line(s[nn, 0], s[nn, 1], lastx, lasty)
'end if
end if
lastx = s[nn, 0] : lasty = s[nn, 1]
next
screenswap
wait(10)
next
end if
screenswap
wait(10)
for nn = 0 to pts
p[nn, 0] = q[nn, 0] : p[nn, 1] = q[nn, 1]
next
wend