Author Topic: DynaTree Pulse  (Read 1685 times)

B+

  • Guest
DynaTree Pulse
« on: June 22, 2016, 09:26:07 PM »
Code: [Select]
' DynaTree Pulse.bas  SmallBASIC 0.12.6 [B+=MGA] 2016-06-22

' attempt to simulate something D did some time ago
' and combine with something Peter did some time ago
' with something I did some time ago

direction = 5 : angleChange = 30 : limit = 9
maxAngleChange = 180 : minAngleChange = 0 : aOffset = 0
while 1
  color 0, rgb(50, 100, 200) : cls
  branch xmax / 2, ymax / 2, .01 * ymax,   0 + aOffset, ymax * .1, 0
  branch xmax / 2, ymax / 2, .01 * ymax,  90 + aOffset, ymax * .1, 0
  branch xmax / 2, ymax / 2, .01 * ymax, 180 + aOffset, ymax * .1, 0
  branch xmax / 2, ymax / 2, .01 * ymax, 270 + aOffset, ymax * .1, 0
  showpage
  delay 10
  angleChange += direction
  if angleChange >= maxAngleChange then
    direction *= -1
    angleChange = maxAngleChange - 2
    if minAngleChange + 2 < maxAngleChange - 45 then minAngleChange += 2
  elif angleChange <= minAngleChange
    direction *= -1
    angleChange = minAngleChange + 1
    if maxAngleChange - 10 > minAngleChange + 45 then maxAngleChange -= 10
  fi
  aOffset ++
wend

sub branch(x, y, startr, angD, length, level)
  local x2, y2, dx, dy, bc, i
  x2 = x + cos(rad(angD)) * length : y2 = y - sin(rad(angD)) * length
  dx = (x2 - x) / length : dy = (y2 - y) / length
  if level >= limit or startr <= 1 or length <= 2 then
    bc = rgb(60 + rnd * 190, 0, 0)
    circle x, y, 5, 1, bc filled
  else
    bc = rgb(10 * level + 128, 0, 3 * level + 64)
    for i = 0 to length
      circle x + dx * i, y + dy * i, startr, 1, bc filled
    next
    branch x2, y2, startr - 1, angD + angleChange, .8 * length, level + 1
    branch x2, y2, startr - 1, angD - angleChange, .8 * length, level + 1
  fi
end

Here is sdlaBasic version:
Code: [Select]
'DynaTree Pulse.sdlbas 2016-06-22 translation of
' DynaTree Pulse.bas  SmallBASIC 0.12.6 [B+=MGA] 2016-06-22

' attempt to simulate something D did some time ago
' and combine with something Peter did some time ago
' with something I did some time ago

const xmax = 720
const ymax = 720
const pi = acos(-1)
const rad = pi / 180
setdisplay(xmax, ymax, 32, 1)
setcaption("DynaTree Pulse")
autoback(-2)

sub branch(x, y, startr, angD, lngth, level, angleChange)
x2 = x + cos(rad *angD) * lngth : y2 = y - sin(rad * angD) * lngth
dx = (x2 - x) / lngth : dy = (y2 - y) / lngth
if level >= 9 or startr < 1 or lngth <= 1 then
ink( rgb(60 + rnd * 190, 0, 0) )
fillcircle( x, y, 5)
else
ink( rgb(10 * level + 128, 0, 3 * level + 64) )
for i = 0 to lngth
fillcircle(x + dx * i, y + dy * i, startr +1)
next
branch(x2, y2, startr - 1, angD + angleChange, .8 * lngth, level + 1, angleChange)
branch(x2, y2, startr - 1, angD - angleChange, .8 * lngth, level + 1, angleChange)
  end if
end sub

angleChange = 30
direction = 5
maxAngleChange = 180 : minAngleChange = 0 : aOffset = 0
while key(27) = 0
ink( rgb(50, 100, 200) )
bar(0, 0, xmax, ymax)
branch( xmax / 2, ymax / 2, .01 * ymax,   0 + aOffset, ymax * .12, 0, angleChange)
branch( xmax / 2, ymax / 2, .01 * ymax,  90 + aOffset, ymax * .12, 0, angleChange)
branch( xmax / 2, ymax / 2, .01 * ymax, 180 + aOffset, ymax * .12, 0, angleChange)
branch( xmax / 2, ymax / 2, .01 * ymax, 270 + aOffset, ymax * .12, 0, angleChange)
screenswap
wait(10)
angleChange += direction
if angleChange >= maxAngleChange then
direction *= -1
angleChange = maxAngleChange - 2
if minAngleChange + 2 < maxAngleChange - 45 then
minAngleChange += 2
end if
elseif angleChange <= minAngleChange then
direction *= -1
angleChange = minAngleChange + 1
if maxAngleChange - 10 > minAngleChange + 45 then
maxAngleChange -= 10
end if
end if
aOffset +=1
wend

Aurel

  • Guest
Re: DynaTree Pulse
« Reply #1 on: June 25, 2016, 05:48:58 AM »
Amd here is dynaTree in toy528
Code: [Select]
' dynatree pulse.bas  smallbasic 0.12.6 [b+=mga] 2016-06-22
' dynatree in toy528 mod-by Aurel
float direction ,anglechange, limit, maxanglechange, minanglechange, aoffset,rad,xmax,ymax,turn
rad=3.14195/180 xmax=800 ymax=600
direction = 5  anglechange = 30  limit = 9
maxanglechange = 180  minanglechange = 0  aoffset = 0

'loop
while turn < 100
  wcolor 50,100,150  frontpen 50, 100, 200
  branch (xmax / 2, ymax / 2, 0.01 * ymax,   0 + aoffset, ymax * 0.1, 0)
  branch (xmax / 2, ymax / 2, 0.01 * ymax,  90 + aoffset, ymax * 0.1, 0)
  branch (xmax / 2, ymax / 2, 0.01 * ymax, 180 + aoffset, ymax * 0.1, 0)
  branch (xmax / 2, ymax / 2, 0.01 * ymax, 270 + aoffset, ymax * 0.1, 0)
  'showpage
  'delay 10
  anglechange = anglechange + direction
'----------------------------------------------------------------------------------------------
  if anglechange >= maxanglechange then
    direction = direction * -1
    anglechange = maxanglechange - 2
    if minanglechange + 2 < maxanglechange - 45 then minanglechange = minanglechange+2 end if
  elseif anglechange <= minanglechange then
    direction = direction * -1
    anglechange = minanglechange + 1
    if maxanglechange - 10 > minanglechange + 45 then maxanglechange =maxanglechange-10 end if
  end if
'----------------------------------------------------------------------------------------------
  aoffset=aoffset+1  turn=turn+1
wend

sub branch(float x, y, startr, angd, length, level)
  float x2, y2, dx, dy, bc, i
  x2 = x + cos(rad*angd) * length   y2 = y - sin(rad*angd) * length
  dx = (x2 - x) / length  dy = (y2 - y) / length
  if level >= limit or startr <= 1 or length <= 2 then
    frontpen 60+rand(190), 0, 0
    circle x, y, 5
  else
    frontpen 10*level+128, 0, 3*level+64
    for i = 0 to length
      circle x+dx*i, y+dy*i,startr
    next
    branch (x2, y2, startr - 1, angd + anglechange, 0.8 * length, level + 1)
    branch (x2, y2, startr - 1, angd - anglechange, 0.8 * length, level + 1)
  end if
end sub