Author Topic: Text Rotation Fun  (Read 1197 times)

B+

  • Guest
Text Rotation Fun
« on: February 03, 2018, 04:45:32 AM »
Code: [Select]
'text rotation fun.bas for SmallBASIC 0.12.11 (B+=MGA) 2017-02-02

'global variables
message = "abcdefghijklmnopqrstuvwxyz""
secWide = txtw(message) + 2
secHigh = txth(message) + 2
dim sect(secWide, secHigh) 'array to store message points
color rgb(200, 200, 200),0 : cls
rect 0, 0, secWide, secHigh, 9

? message
loadSect 0, 0 'load array
'debug checks
'for y = 0 to secHigh
'  for x = 0 to secWide
'    if sect(x, y) then pset x + 200, y + 200
'  next
'next
'input "OK ";ok

dim plasma(5, 3)
for i = 0 to 5
  plasma(i, 0) = rnd * rnd
  plasma(i, 1) = rnd * rnd
  plasma(i, 2) = rnd * rnd
next

cls
cx = xmax/2 : cy = ymax/2
while 1
  cls
  dp 0
  yaxis cx, cy/4, a, 2
  dp 1
  xaxis cx, 3*cy/4, a, 5
  dp 2
  rotate cx/2, cy, a, 1
  dp 3
  rotate 3*cx/2, cy, a -90, 2.5
  dp 4
  rotate cx, cy/2, -4*a + 90, 2
  dp 5
  rotate cx, 3*cy/2, 2*a + 180, 4.5
  showpage
  delay 10
  a = a + 1
  if a = 360 then a = 0
wend
pause

sub dp(i)
  color rgb(128 + 127*sin(plasma(i,0)*a), 128 + 127*sin(plasma(i, 1)*a), 128 + 127*sin(plasma(i, 2)*a))
end

sub loadSect(xstart, ystart)
  local x, y, p, black
  'these are all global
  black = rgb(100 ,100, 100)
  for y = 0 to secHigh
    for x = 0 to secWide
      p = POINT(xstart + x, ystart + y)
      if p < black then sect(x, y) = 1 '<== data from screen points
    next
  next
end

sub rotate(cx, cy, angle, scale) 'and scale
  local cax, cay, ra, cc, d, anew, ax,ay

  cax = secWide/2 : cay = secHigh/2  'array center
  for y = 0 to secHigh
    for x = 0 to secWide
      cc = sect(x,y)
      if (x-cax) <> 0  and cc <> 0 then
        d = ((x-cax)^2+(y-cay)^2)^.5
        anew = atan((y-cay)/(x-cax))
        if x-cax <  0 and y-cay  < 0 then anew = anew + pi+rad(angle)  '-x,-y
        if x-cax <  0 and y-cay >= 0 then anew = anew + pi+rad(angle) '-x,+y
        if x-cax >= 0 and y-cay  < 0 then anew = anew + rad(angle)    '+x,-y
        if x-cax >= 0 and y-cay >= 0 then anew = anew + rad(angle)   '+x,+y
        ax = d*cos(anew):ay=d*sin(anew)
        rect int(cx+ax*scale),int(cy+ay*scale) step scale+1, scale+1 filled
      end if
    next
  next
end

sub yaxis(cx, cy, angle, scale)
   local cax, cay, cc, ax,ay

  cax = secWide/2 : cay = secHigh/2  'array center
  for y = 0 to secHigh
    for x = 0 to secWide
      cc = sect(x,y)
      if cc <> 0 then
        ax = (x - cax)*cos(rad(angle)):ay= (y - cay)
        rect int(cx+ax*scale),int(cy+ay*scale) step scale+1, scale+1 filled
      end if
    next
  next
end

sub xaxis(cx, cy, angle, scale)
   local cax, cay, cc, ax,ay

  cax = secWide/2 : cay = secHigh/2  'array center
  for y = 0 to secHigh
    for x = 0 to secWide
      cc = sect(x,y)
      if cc <> 0 then
        ax = (x - cax) :ay = (y - cay) * sin( rad(angle))
        rect int(cx+ax*scale),int(cy+ay*scale) step scale+1, scale+1 filled
      end if
    next
  next
end