What do you use SmallBASIC for?

Started by jagtalon, August 13, 2023, 13:42:25

Previous topic - Next topic

jagtalon

I just learned about SmallBASIC the other day, and I'm already loving it! It's so easy to pick up I got my own little weather app running in no time

https://git.sr.ht/~jagtalon/smallbasic-tools/tree/master/item/weather/weather.bas

I'm hoping to make small tools with this language. What do you all use SmallBASIC / BASIC for?




bplus

Art work:
'fall foliage.bas SmallBASIC 0.12.9 (B+=MGA) 2017-10-21

'test landscape and portrait views for Android
xmx = min(xmax, 800) : ymx = min(600, ymax) 'portrait
'OK it's just plain better in landscape view

'now for full viewing enjoyment
xmx = xmax : ymx = ymax

n = 3
while 1
  if n < 15 then n = n + 3
  horizon = rand(.8 * ymx, .9 * ymx)
  for i= 0 to horizon
    midInk 0, 0, 128, 10, 120, 128, i/horizon
    line 0, i, xmx, i
  next
  for i = horizon to ymx
    midInk 70, 108, 30, 60, 10, 5, (i-horizon)/(ymx-horizon)
    line 0, i, xmx, i
  next
  for i = 1 to xmx * ymx * .00018
    leaf rand(0, xmx), rand(horizon * 1.002, ymx)
  next
  if n < .01 * xmx then trees = n else trees = rand(.01 * xmx, .03 * xmx)
  for i = 1 to trees
    y = horizon + .04 * ymx + i / trees * (ymx - horizon - .1 * ymx)
    r = .01 * y : h = rand(y * .15, y * .18)
    branch rand(10, xmx - 10), y, r, 90, h, 0
  next
  rect xmx, 0, xmax, ymax, 0 filled
  rect 0, ymx, xmx, ymax, 0 filled
  showpage
  delay 2000
wend

sub branch(x, y, startr, angD, length, lev)
  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
  bc = rgb(30 + 6 * lev, 15 + 3 * lev, 5 + 2 * lev)
  for i = 0 to length
    circle x + dx * i, y + dy * i, startr, 1, bc filled
  next
  if lev > 1 then leaf x2, y2
  if .8 * startr < .1 or lev > 7 or length < 3 then exit sub
  lev += 1
  branch x2, y2, .8 * startr, angD + 22 + rand(-10, 19), rand(.75 * length, .9 * length), lev
  branch x2, y2, .8 * startr, angD - 22 - rand(-10, 19), rand(.75 * length, .9 * length), lev
end

sub leaf(x, y)
  local sp, n, c, xoff, yoff, woff, hoff
  sp = 15 : leafs = rand(xmx * ymx * .00001, xmx * ymx * .00002)
  for n = 1 to leafs
      c = rgb(rand(50, 250), rand(25, 255), rand(0, 40))
      xoff = x + rnd * sp - rnd * sp
      yoff = y + rnd * sp - rnd * sp
      woff = 3 + rnd * 3
      hoff = 3 + rnd * 3
      rect xoff, yoff step woff, hoff, c filled
  next
end

sub midInk(r1, g1, b1, r2, g2, b2, fr)
  color rgb(r1 + (r2 - r1) * fr, g1 + (g2 - g1) * fr, b1 + (b2 - b1) * fr)
end

def rand(lo, hi) = (rnd * (hi - lo + 1)) \ 1 + lo


Welcome to sb board @jagtalon
1 person likes this

bplus

#2
Another use?

Crazy fun stuff!
' Pentacle Flux Capacitor #3.bas SmallBASIC 0.12.9 (B+=MGA) 2017-08-25
' based on mods made in Just Basic version

' Pentacle Flux Capacitor 2.bas SmallBASIC 0.12.9 (B+=MGA) 2017-08-23
'Pentacle Flux Capacitor 2.bas for QB64 fork 2017-08-23
'translated from: Pentacle Flux Capacitor 2.txt for JB (B+=MGA) 2017-08-23

'Some dancing music for the Dancing figure

'Electric Light Orchestra (ELO) It's a Livin' Thing...
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  https://www.youtube.com/watch?v=i2d45tOgBl0&index=1&list=RDi2d45tOgBl0
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

RANDOMIZE TIMER
'COMMON SHARED xc, yc, dist, tp(), tp2()
xc = xmax / 2
yc = ymax / 2
DIM tp(4, 1), tp2(4, 1)
drawPFC
PFC = Image(0, 0, xmax, ymax)
while 1
  cls
  PFC.show(0, 0, 1, 50) ' use image transparency
  color rgb(rand(100, 255), rand(100, 255), rand(200, 255))
  Lightning xc, yc - 90, xc, yc + 10, 135
  FOR i = 0 TO 4
    xe = tp2(i, 0)
    ye = tp2(i, 1)
    d = rand(.1 * dist, .7 * dist)
    SELECT CASE i
    CASE 0
      Lightning xc, yc - 90, xe, ye, .65*d
      Lightning xc, yc - 90, xe, ye, .65*d
    CASE 1, 4
      Lightning xc, yc - 70, xe, ye, d
    CASE 2, 3
      Lightning xc, yc + 10, xe, ye, d
    END SELECT
  NEXT
  Showpage
  delay 30
WEND

SUB drawPFC
  local pRadius, cRadius, a3, r, ao, a, rr, i, xx, yy, dGray, dis, pnt, midx, midy
  'keep global tp(), tp2(), xc, yc, dist
  '3 main points for array tp()
  pRadius = 40: cRadius = 1.5 * pRadius
  a3 = PI * (2 / 5): r = ymax / 2 - cRadius - 20
  ao = PI* (-1 / 2): a = ao
  FOR rr = ymax/2-20 TO 0 STEP -1
    midInk 0, 0, 0, 128, 0, 0, rr / r
    Circle xc, yc, rr filled
  NEXT
  FOR i = 0 TO 4
    tp(i, 0) = xc + r * COS(a)
    tp(i, 1) = yc + r * SIN(a)
    FOR rr = cRadius TO pRadius STEP -1
      COLOR RGB((rr - pRadius) /(cRadius - pRadius) * 255 * (cRadius - rr + pRadius) / cRadius, 0, 0)
      xx = tp(i, 0): yy = tp(i, 1)
      Circle xx, yy, rr filled
    NEXT
    a = a + a3
  NEXT
  xx = tp(0, 0): yy = tp(0, 1)
  dist = distance(xx, yy, xc, yc) 'global
  FOR pnt = 0 TO 4
    FOR dis = 0 TO .5 * dist STEP 10
      dGray = 255 * dis / dist
      xx = tp(pnt, 0): yy = tp(pnt, 1)
      midpoint xx, yy, xc, yc, dis / dist, midx, midy
      FOR r = pRadius * (dist - dis) / dist TO 0 STEP -1
        midInk dGray, dGray, dGray, 255, 255, 255, (pRadius - r) / pRadius
        Circle midx, midy, r filled
      NEXT
    NEXT
    tp2(pnt, 0) = midx
    tp2(pnt, 1) = midy
  NEXT
END SUB

SUB Lightning (x1, y1, x2, y2, d)
  local mx, my
  IF d < 5 THEN
    LINE x1, y1, x2, y2
  ELSE
    mx = (x2 + x1) / 2
    my = (y2 + y1) / 2
    mx = mx + -.5 * RND * d * .4 * rand(-2, 2)
    my = my + -.5 * RND * d * .4 * rand(-2, 2)
    Lightning x1, y1, mx, my, d / 2
    Lightning x2, y2, mx, my, d / 2
  END IF
END SUB

SUB midpoint (x1, y1, x2, y2, fraction, byref midx, byref midy)
  midx = (x2 - x1) * fraction + x1
  midy = (y2 - y1) * fraction + y1
END SUB

SUB midInk (r1, g1, b1, r2, g2, b2, fr)
  COLOR RGB(r1 + (r2 - r1) * fr, g1 + (g2 - g1) * fr, b1 + (b2 - b1) * fr)
END SUB

FUNC distance(x1, y1, x2, y2)
  distance = ((x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5
END

FUNC rand(lo, hi)
  rand = INT(RND * (hi - lo + 1)) + lo
END
1 person likes this

jagtalon

Amazing! How different is QB64 from SmallBASIC is in your experience?


bplus

Quote from: jagtalon on August 13, 2023, 17:56:40Amazing! How different is QB64 from SmallBASIC is in your experience?
SmallBASIC is very portable interpreter pretty fast and does really nice stuff with arrays including Jason maps which aren't quite arrays.

QB64 has much more user friendly IDE with formatting, syntax checking, block comment/uncomment automatic indenting easy access to stuff and some nice tools. I like graphics, sound and font loading and using much more than sb and of course it's compiled so runs wicked fast compared to sb, though the compiling can take some time.
1 person likes this

bprlhe

@bplus Where do you get the equations for these nice looking graphs? :o


bplus

Quotebplus Where do you get the equations for these nice looking graphs? :o

From hanging out in Basic Forums (9 years now) and my heart luvs animated math!

@bprlhe from your awesome Basic lists/ link I can tell you are huge fan too!
1 person likes this