[blocks]

Algemene discussies en vragen omtrent Liberty BASIC programma's. Stuur zoveel mogelijk delen van listings (snippets) in als je hulp wilt.

Moderators: anthonio, Abcott

[blocks]

Berichtdoor bluatigro » do dec 01, 2016 11:16 am

explanation :
[blocks] are blocks of code that are reuseble
every [block] is is stored seperately in a file
every [block] begins whit wat it need of other [blocks]
so you can quicky build code

uitleg :
[blocks] zijn blokken van herbruikbare code
ellk [block] is apart opgeslagen in een file
elk [block] begint met wat het nodig heeft van andere blokken
op die manier kan je snel code bouwen
bluatigro
 
Berichten: 301
Geregistreerd: za sep 27, 2008 6:01 pm

[blocks] : math

Berichtdoor bluatigro » do dec 01, 2016 11:22 am

Code: Selecteer alles
''bluatigro 18 nov 2016
''math block

[math]
  global pi , golden.ratio , true , false
  pi = atn( 1 ) * 4
  golden.ratio = ( sqr( 5 ) - 1 ) / 2
  false = 0
  true = not( false )
return

function range( l , h )
  range = rnd(0) * ( h - l ) + l
end function

function rad( deg )
''from degrees to radians
  rad = deg * pi / 180
end function

sub rotate byref k , byref l , deg
  s = sin( rad( deg ) )
  c = cos( rad( deg ) )
  hk = k * c - l * s
  hl = k * s + l * c
  k = hk
  l = hl
end sub

bluatigro
 
Berichten: 301
Geregistreerd: za sep 27, 2008 6:01 pm

[blocks] : animation

Berichtdoor bluatigro » do dec 01, 2016 11:38 am

Code: Selecteer alles
''bluatigro 1 dec 2016
''animation block

function nr$( no , m )
  nr$ = right$( "00000000" ; no , m )
end function

sub saveframe f$ , no , m
  #m "getbmp screen 0 0 " ; winx ; " " ; winy
  bmpsave "screen" , f$ + nr$( no , m ) + ".bmp"
end sub

sub dia f$ , no , m , ms
  loadbmp "screen" , f$ + nr$( no , m ) + ".bmp"
  #m "background screen"
  call sleep ms
end sub

sub movie f$ , p , m , ms , k
  for i = 1 to k
    for j = 0 to p
      call dia f$ , j , m , ms
    next j
  next i
end sub

sub sleep ms
  CallDLL #kernel32, "Sleep" _
  , ms  As long _
  , ret As void
end sub

bluatigro
 
Berichten: 301
Geregistreerd: za sep 27, 2008 6:01 pm

[blocks] : color

Berichtdoor bluatigro » do dec 01, 2016 11:41 am

Code: Selecteer alles
''bluatigro 18 nov 2016
''color block
''needs math block

[color]
  global black , red , green , yellow
  global blue , magenta , cyan , white
  global pink , orange , gray , purple
  black   = rgb(   0 ,   0 ,   0 )
  red     = rgb( 255 ,   0 ,   0 )
  green   = rgb(   0 , 255 ,   0 )
  yellow  = rgb( 255 , 255 ,   0 )
  blue    = rgb(   0 ,   0 , 255 )
  magenta = rgb( 255 ,   0 , 255 )
  cyan    = rgb(   0 , 255 , 255 )
  white   = rgb( 255 , 255 , 255 )
  pink    = rgb( 255 , 127 , 127 )
  orange  = rgb( 255 , 127 ,   0 )
  gray    = rgb( 127 , 127 , 127 )
  purple  = rgb( 127 ,   0 , 127 )
return

sub setcolor kl
  r = int( kl and 255 )
  g = int( kl / 256 ) and 255
  b = int( kl / 256 / 256 ) and 255
  print #m , "backcolor " ; r ;" "; g ; " "; b
  print #m , "color " ; r ; " " ; g ; " " ; b
end sub

function rgb( r , g , b )
  rgb = ( int( r ) and 255 ) _
  + ( int( g ) and 255 ) * 256 _
  + ( int( b ) and 255 ) * 256 * 256
end function

function rainbow( x )
  r = sin( rad( x ) ) * 127 + 128
  g = sin( rad( x - 120 ) ) * 127 + 128
  b = sin( rad( x + 120 ) ) * 127 + 128
  rainbow = rgb( r , g , b )
end function

function mix( kl1 , f , kl2 )
  r1 = int( kl1 and 255 )
  g1 = int( kl1 / 256 ) and 255
  b1 = int( kl1 / 256 / 256 ) and 255
  r2 = int( kl2 and 255 )
  g2 = int( kl2 / 256 ) and 255
  b2 = int( kl2 / 256 / 256 ) and 255
  r = r1 + ( r2 - r1 ) * f
  g = g1 + ( g2 - g1 ) * f
  b = b1 + ( b2 - b1 ) * f
  mix = rgb( r , g , b )
end function

bluatigro
 
Berichten: 301
Geregistreerd: za sep 27, 2008 6:01 pm

[blocks] : sphere world

Berichtdoor bluatigro » do dec 01, 2016 11:48 am

Code: Selecteer alles
''bluatigro 18 nov 2016
''sphere world block
''needs color , basis3D and math block

[sphere]
  global height
return

sub sphere x , y , z , d , kl
  scan
  call spot x , y , z
  d = d * cam( 6 )
  dx = WindowWidth
  dy = WindowHeight
  if height = 0 then
    call setcolor black
    print #m , "goto " ; dx / 2 + x ; " " _
    ; dy * 5 / 6 - z / 4
    print #m , "down"
    print #m , "ellipsefilled " ; d * 2 ; " " ; d / 2
    print #m , "up"
  end if
  if abs( height - y ) < d then
    dd = sqr( d ^ 2 - ( height - y ) ^ 2 ) * 2
    kl = mix( kl , 1 - ( height - y ) / d / 2 + 0.5 , 0 )
    call setcolor kl
    print #m , "goto "; dx / 2 + x ;" " _
    ; dy * 5 / 6 - height - z / 4
    print #m , "down"
    print #m , "ellipsefilled "; dd ;" "; dd / 4
    print #m , "up"
  end if
end sub

sub egg x1 , y1 , z1 , d1 , x2 , y2 , z2 , d2 , dm , kl , n
  diff = sqr( ( x1 - x2 ) ^ 2 _
            + ( y1 - y2 ) ^ 2 _
            + ( z1 - z2 ) ^ 2 )
  dx = ( x2 - x1 ) / diff
  dy = ( y2 - y1 ) / diff
  dz = ( z2 - z1 ) / diff
  dd = ( d2 - d1 ) / diff
  if dm = 0 then dm = ( d1 + d2 ) / 2
  if n < 3 then n = diff
  for i = 0 to diff step diff / n
    scan
    call sphere x1 + dx * i _
    , y1 + dy * i _
    , z1 + dz * i _
    , d1 + dd * i _
    + sin( i / diff * pi ) _
    * ( dm - ( d1 + d2 ) / 2 ) _
    , kl
  next i
end sub

sub bezier x1,y1,z1,d1 , x2,y2,z2,d2 , x3,y3,z3,d3 , x4,y4,z4,d4 , kl , dist
  r = int( kl ) and 255
  g = int( kl / 256 ) and 255
  b = int( kl / 256 / 256 ) and 255
  if dist < 1 then dist = 1
  if sqr((x1-x2)^2+(y1-y2)^2+(z1-z2)^2) < dist then
    call sphere x1,y1,z1,d1,kl
  else
    ax = ( x1 + x2 ) / 2
    ay = ( y1 + y2 ) / 2
    az = ( z1 + z2 ) / 2
    ad = ( d1 + d2 ) / 2
    bx = ( x3 + x4 ) / 2
    by = ( y3 + y4 ) / 2
    bz = ( z3 + z4 ) / 2
    bd = ( d3 + d4 ) / 2
    cx = ( x3 + x2 ) / 2
    cy = ( y3 + y2 ) / 2
    cz = ( z3 + z2 ) / 2
    cd = ( d3 + d2 ) / 2
    a1x = ( ax + cx ) / 2
    a1y = ( ay + cy ) / 2
    a1z = ( az + cz ) / 2
    a1d = ( ad + cd ) / 2
    b1x = ( bx + cx ) / 2
    b1y = ( by + cy ) / 2
    b1z = ( bz + cz ) / 2
    b1d = ( bd + cd ) / 2
    c1x = ( a1x + b1x ) / 2
    c1y = ( a1y + b1y ) / 2
    c1z = ( a1z + b1z ) / 2
    c1d = ( a1d + b1d ) / 2
    scan
    call bezier x1,y1,z1,d1 , ax,ay,az,ad , a1x,a1y,a1z,a1d , c1x,c1y,c1z,c1d , kl , dist
    call bezier c1x,c1y,c1z,c1d , b1x,b1y,b1z,b1d , bx,by,bz,bd , x4,y4,z4,d4 , kl , dist
  end if
end sub

bluatigro
 
Berichten: 301
Geregistreerd: za sep 27, 2008 6:01 pm

[blocks] : basis3D

Berichtdoor bluatigro » do dec 01, 2016 11:51 am

Code: Selecteer alles
''bluatigro 18 nov 2016
''3d engine block
''needs math block

[basis3D]
  global mmax
  mmax = 20
  dim m( ( mmax + 5 ) * 4 * 4 + 16 ) , cam( 6 )
  dim skx( 64 ) , sky( 64 ) , skz( 64 )
  global rotx , roty , rotz  , trans , temp , number , pi
  trans = mmax + 1
  rotx = mmax + 2
  roty = mmax + 3
  rotz = mmax + 4
  temp = mmax + 5
  pi = atn( 1 ) * 4
  global xyz , xzy , yxz , yzx , zxy , zyx
  xzy = 1
  yxz = 2
  yzx = 3
  zxy = 4
  zyx = 5
  call startmatrix
return

function pend( fase , amp )
  pend = sin( rad( fase ) ) * amp
end function

sub skelet lim , x , y , z
''for animating avatar lim's
  skx( lim ) = x
  sky( lim ) = y
  skz( lim ) = z
end sub

sub child no , x , y , z , lim , ax , p
''for creating lim's of a avatar
  if lim < 0 or lim > 64 then exit sub
  call link no , x , y , z _
  , sky( lim ) , skx( lim ) , skz( lim ) , ax , p
end sub

sub link no , x , y , z , xz , yz , xy , ax , p
''set draw matrix : wil efect future drawing

''no : number new matrix
''x,y,z : translation
''xz,yz,xy : rotation in degrees
''ax : sequence of axes
''p : number old matrix

  if no < 1 or no > mmax then exit sub
  if p < 0 or p > mmax then exit sub
  if no < 1 or no > mmax then exit sub
  if p < 0 or p > mmax then exit sub
  if p = no then exit sub
''copy matrix 0 into matrix's
  call copy 0 , rotx
  call copy 0 , roty
  call copy 0 , rotz
  call copy 0 , trans
''create rotation matrix's
  m( in( rotx , 1 , 1 ) ) = cos( rad( yz ) )
  m( in( rotx , 1 , 2 ) ) = 0-sin( rad( yz ) )
  m( in( rotx , 2 , 1 ) ) = sin( rad( yz ) )
  m( in( rotx , 2 , 2 ) ) = cos( rad( yz ) )

  m( in( roty , 0 , 0 ) ) = cos( rad( xz ) )
  m( in( roty , 0 , 2 ) ) = 0-sin( rad( xz ) )
  m( in( roty , 2 , 0 ) ) = sin( rad( xz ) )
  m( in( roty , 2 , 2 ) ) = cos( rad( xz ) )

  m( in( rotz , 0 , 0 ) ) = cos( rad( xy ) )
  m( in( rotz , 0 , 1 ) ) = 0-sin( rad( xy ) )
  m( in( rotz , 1 , 0 ) ) = sin( rad( xy ) )
  m( in( rotz , 1 , 1 ) ) = cos( rad( xy ) )
''create translation matrix
  m( in( trans , 3 , 0 ) ) = x
  m( in( trans , 3 , 1 ) ) = y
  m( in( trans , 3 , 2 ) ) = z
''select axes sequence [ 1 of 6 ] and act on i
  select case ax
    case xyz
      call multiply rotx , roty , temp
      call multiply temp , rotz , no
      call multiply no , trans , temp
      call multiply temp , p , no
    case xzy
      call multiply rotx , rotz , temp
      call multiply temp , roty , no
      call multiply no , trans , temp
      call multiply temp , p , no
    case yxz
      call multiply roty , rotx , temp
      call multiply temp , rotz , no
      call multiply no , trans , temp
      call multiply temp , p , no
    case yzx
      call multiply roty , rotz , temp
      call multiply temp , rotx , no
      call multiply no , trans , temp
      call multiply temp , p , no
    case zxy
      call multiply rotz , rotx , temp
      call multiply temp , roty , no
      call multiply no , trans , temp
      call multiply temp , p , no
    case zyx
      call multiply rotz , roty , temp
      call multiply temp , rotx , no
      call multiply no , trans , temp
      call multiply temp , p , no
    case else
      call multiply rotx , roty , temp
      call multiply temp , rotz , no
      call multiply no , trans , temp
      call multiply temp , p , no
  end select
  number = no
end sub

sub copy a , b
''matrix( b ) = matrix( a )
  for i = 0 to 3
    for j = 0 to 3
      m( in( b , i , j ) ) = m( in( a , i , j ) )
    next j
  next i
end sub

sub spot byref x , byref y , byref z
'''lokal coordinates to world coordinates
''x,y,z = matrix( number ) * x,y,z
  no = number
  hx = m( in( no , 0 , 0 ) ) * x _
     + m( in( no , 1 , 0 ) ) * y _
     + m( in( no , 2 , 0 ) ) * z _
     + m( in( no , 3 , 0 ) )
  hy = m( in( no , 0 , 1 ) ) * x _
     + m( in( no , 1 , 1 ) ) * y _
     + m( in( no , 2 , 1 ) ) * z _
     + m( in( no , 3 , 1 ) )
  hz = m( in( no , 0 , 2 ) ) * x _
     + m( in( no , 1 , 2 ) ) * y _
     + m( in( no , 2 , 2 ) ) * z _
     + m( in( no , 3 , 2 ) )
  x = hx - cam( 0 )
  y = hy - cam( 1 )
  z = hz - cam( 2 )
  call rotate x , y , 0 - cam( 5 )
  call rotate y , z , 0 - cam( 4 )
  call rotate x , z , 0 - cam( 3 )
  if cam( 6 ) = 0 then cam( 6 ) = 1
  x = x * cam( 6 )
  y = y * cam( 6 )
  z = z * cam( 6 )
end sub

sub camara x,y,z,pan,tilt,rol,zoom
  cam( 0 ) = x
  cam( 1 ) = y
  cam( 2 ) = z
  cam( 3 ) = pan
  cam( 4 ) = tilt
  cam( 5 ) = rol
  cam( 6 ) = zoom
end sub

sub multiply a , b , c
''matrix( c ) = matrix( a ) * matrix( b )
  for i = 0 to 3
    for j = 0 to 3
      m( in( c , i , j ) ) = 0
      for k = 0 to 3
        m( in( c , i , j ) ) = m( in( c , i , j ) ) _
        + m( in( a , i , k ) ) * m( in( b , k , j ) )
      next k
    next j
  next i
end sub

sub startmatrix
''set startmatrix to unity
  for x = 0 to 3
    for y = 0 to 3
      m( in( 0,x,y ) ) = 0
    next y
    m( in( 0,x,x ) ) = 1
  next x
end sub

function in( no , x , y )
''LB4 has no 3d array's
''so i simulate them
  in = x + y * 4 + no * 16
end function

bluatigro
 
Berichten: 301
Geregistreerd: za sep 27, 2008 6:01 pm

[blocks] : ray world

Berichtdoor bluatigro » do dec 01, 2016 12:40 pm

Code: Selecteer alles
''bluatigro 18 nov 2016
''ray casting world block
''needs vector3D , basis3D , color and math block

[ray]
  global great , smal
  great = 1e7
  smal = 1e-7
  global smax , stel
  smax = 1000
  dim s.x(smax),s.y(smax),s.z(smax),s.r(smax),s.r2(smax),s.kl(smax)
  global tmax , ttel
  tmax = 1000
  dim t.x0(tmax),t.y0(tmax),t.z0(tmax) _
        ,t.x1(tmax),t.y1(tmax),t.z1(tmax) _
        ,t.x2(tmax),t.y2(tmax),t.z2(tmax) _
        ,t.xn(tmax),t.yn(tmax),t.zn(tmax),t.kl(tmax)
return

function render(ox,oy,oz,dx,dy,dz,dept)
  scan
  s = great
  for i = 0 to stel - 1
    sdist = sphere.hit(i,ox,oy,oz,dx,dy,dz)
    if sdist < s then
      s = sdist
      si = i
    end if
  next i
  t = great
  for i = 0 to ttel - 1
    tdist = tri.hit(i,ox,oy,oz,dx,dy,dz)
    if tdist < t then
      t = tdist
      ti = i
    end if
  next i
  uit = black
  if t = great and s = great then exit function
  if t < s then
    a = angle(t.xn(ti),t.yn(ti),t.zn(ti) , 0,1,0)
    uit = mix( t.kl(ti) , cos(a)/2+0.5 , black )
  else
      ''d = d - cam
      call v.min dx,dy,dz , dx,dy,dz , ox,oy,oz
      ''d.normalize
      call v.normalize dx,dy,dz , dx,dy,dz
      ''q = cam + d * s
      call v.add qx,qy,qz , ox,oy,oz , dx*s,dy*s,dz*s
      ''normal = q - s.center
      call v.min x,y,z , qx,qy,qz , s.x(si),s.y(si),s.z(si)
      ''a = angle( normal , light )
      a = angle( x,y,z , 0,1,0 )
      kl = mix( s.kl(si) , cos(a)/2+0.5 , black )
      uit = kl
  end if
  render = uit
end function

sub sphere x,y,z , d , kl
  if stel > smax then exit sub
  call spot x,y,z
  d = d * cam( 6 )
  s.x(stel)=x
  s.y(stel)=0-y
  s.z(stel)=z
  s.r(stel)=d
  s.r2(stel)=d*d
  s.kl(stel)=kl
  stel=stel+1
end sub

function sphere.hit(no,ox,oy,oz,dx,dy,dz)
  call v.min x,y,z , ox,oy,oz , s.x(no),s.y(no),s.z(no)
  a = dot(dx,dy,dz , dx,dy,dz)
  b = 2 * dot(x,y,z , dx,dy,dz)
  c = dot(x,y,z , x,y,z)-s.r2(no)
  disc = b*b-4*a*c
  if disc < 0 then
    uit = great
  else
    e = sqr(disc)
    demon = 2*a
    t = ( 0-b - e ) / demon
    if t > smal then
      uit = t
    end if
    t = ( 0-b + e ) / demon
    if t > smal then
      uit = t
    end if
  end if
  sphere.hit = uit
end function

sub tri x0,y0,z0,x1,y1,z1,x2,y2,z2,kl
  call spot x0,y0,z0
  call spot x1,y1,z1
  call spot x2,y2,z2
  t.x0(ttel)=x0
  t.y0(ttel)=y0
  t.z0(ttel)=z0
  t.x1(ttel)=x1
  t.y1(ttel)=y1
  t.z1(ttel)=z1
  t.x2(ttel)=x2
  t.y2(ttel)=y2
  t.z2(ttel)=z2
  t.kl(ttel)=kl
  call v.min ax,ay,az , x2,y2,z2 , x0,y0,z0
  call v.min bx,by,bz , x1,y1,z1 , x0,y0,z0
  call v.cross xn,yn,zn , ax,ay,az , bx,by,bz
  t.xn(ttel)=xn
  t.yn(ttel)=yn
  t.zn(ttel)=zn
  ttel=ttel+1
end sub

function tri.hit(no,ox,oy,oz,dx,dy,dz)
  call v.min e1x,e1y,e1z , t.x1(no),t.y1(no),t.z1(no) , t.x0(no),t.y0(no),t.z0(no)
  call v.min e2x,e2y,e2z , t.x2(no),t.y2(no),t.z2(no) , t.x0(no),t.y0(no),t.z0(no)
  call v.cross qx,qy,qz , dx,dy,dz , e2x,e2y,e2z
  a = dot(e1x,e1y,e1z , qx,qy,qz)
  if abs( a ) < smal then
    tri.hit = great
    exit function
  end if
  f = 1 / a
  call v.min x,y,z , ox,oy,oz , t.x0(no),t.y0(no),t.z0(no)
  u = f*dot(x,y,z , qx,qy,qz)
  if u < 0 or u > 1 then
    tri.hit = great
    exit function
  end if
  call v.cross x,y,z , x,y,z , e1x,e1y,e1z
  v = f*dot(dx,dy,dz , x,y,z)
  if v < 0 or u + v > 1 then
    tri.hit = great
    exit function
  end if
  tri.hit = f*dot(e2x,e2y,e2z , x,y,z)
end function
bluatigro
 
Berichten: 301
Geregistreerd: za sep 27, 2008 6:01 pm

[blocks] : avartars

Berichtdoor bluatigro » do dec 01, 2016 12:54 pm

Code: Selecteer alles
''bluatigro 1 dec 2016
''avartar block
''needs sphere|ray world , color , basis3D and math block

[avartar]
  global arm , elbow , wrist
  arm = 0
  elbow = 1
  wrist = 2
  global leg , knee , enkle
  leg = 3
  knee = 4
  enkle = 5
  global neck , head , eye
  neck = 6
  head = 7
  eye = 8
  global thumb , index , midle , ring
  thumb = 9
  index = 12
  midle = 15
  ring = 18
  global tail , body , lr
  tail = 21
  body = 22
  lr = 32
  global ileg,iknee,iwing,ineck,iarm,ielbow
  global iwrist,ithumb,ifinger,ieye,itail
  ileg = 0
  iknee = 5
  iwing = 10
  ineck = 12
  iarm = 13
  ielbow = 14
  iwrist = 15
  ithumb = 16
  ifinger = 17
  ieye = 18
  itail = 19
  global istand,ileftlegs,irightlegs,ileftbox
  global irightbox,ifly,isting,home,dogwalk,manwalk
  istand = 0
  ileftlegs = 1
  irightlegs = 2
  ileftbox = 3
  irightbox = 4
  ifly = 5
  isting = 6
  home = 7
  dogwalk = 8
  manwalk = 9
return

Sub kop qq , kl
    call link 15, 0, 0, 0, 0, 0, 0 , xyz , number
        call sphere 0, 0, 0, 30, kl
    If qq = 1 Then
        call sphere 25, 25, 0, 9, kl
        call sphere -25, 25, 0, 9, kl
        call sphere 0, 0, -40, 10, gray
    Else
        call sphere 30, 0, 0, 9, kl
        call sphere -30, 0, 0, 9, kl
        call sphere 0, 0, -40, 12, kl
    End If
        call child 16, 14, 14, -14, eye ,xyz, 15
          call sphere 0, 0, 0, 13, white
          call sphere 0, 0, -10, 7, black
        call child 16, -14, 14, -14, eye + lr,xyz, 15
          call sphere 0, 0, 0, 13, white
          call sphere 0, 0, -10, 7, black
end sub

sub man trui , broek
    call child 9, 0, 0, 0, body+lr , xyz , number
    call child 10, 0, 0, 0, body , xyz , 9
        call sphere 0, 50, 0, 30, trui
        call sphere 0, 25, 0, 23, broek
        call sphere 0, 0, 0, 15, broek
    call child 11, 0, 70, 0, neck, xyz, 10
    call child 12, 0, 30, 0, neck+lr, xyz, 11
        call kop 0, pink
    call child 11, 20, -10, 0, leg, yzx, 9
        call sphere 0, 0, 0, 16, broek
        call sphere 0, -20, 0, 16, broek
    call child 12, 0, -40, 0, knee, xyz, 11
        call sphere 0, 0, 0, 16, broek
        call sphere 0, -20, 0, 16, broek
    call child 13, 0, -40, 0, enkle, xzy, 12
        call sphere 0, 0, 0, 12, gray
        call sphere 0, 0, -20, 12, gray
    call child 11, -20, -10, 0, leg+lr , yzx, 10
        call sphere 0, 0, 0, 16, broek
        call sphere 0, -20, 0, 16, broek
    call child 12, 0, -40, 0, knee+lr, xyz, 11
        call sphere 0, 0, 0, 16, broek
        call sphere 0, -20, 0,16, broek
    call child 13, 0, -40, 0,enkle+lr, xzy, 12
        call sphere 0, 0, 0, 12, gray
        call sphere 0, 0, -20, 12, gray
    call child 11, 40, 60, 0, arm, xzy, 10
        call sphere 0, 0, 0, 16, trui
        call sphere 6, -20, 0, 12, trui
    call child 12, 6, -40, 0, elbow, xyz, 11
        call sphere 0, 0, 0, 12, trui
        call sphere 0, -20, 0, 12, trui
        call sphere 0, -42, 0, 8, pink
    call child 11, -40, 60, 0, arm+lr, xzy, 10
        call sphere 0, 0, 0, 16, trui
        call sphere -6, -20, 0, 12, trui
    call child 12, -6, -40, 0, elbow+lr, xyz, 11
        call sphere 0, 0, 0, 12, trui
        call sphere 0, -20, 0, 12, trui
        call sphere 0, -42, 0, 8, pink
end sub

sub pilko kl
call  sphere 0,0,0,30 , kl
call  sphere 0,0,50,30 , kl
call  child 2 , 0,20,-20 , neck , xyz , 1
call    child 3 , 0,20,-20 , neck + lr , zyx , 2
call      kop 1 , kl
call  child 11, 20, -10, 50, leg, yzx, 1
call    sphere 0, 0, 0, 16, kl
call    sphere 0, -20, 0, 16, kl
call    child 12, 0, -40, 0, knee, xyz, 11
call      sphere 0, 0, 0, 16, kl
call      sphere 0, -20, 0, 16, kl
call      child 13, 0, -40, 0, enkle, xzy, 12
call        sphere 0, 0, 0, 12, kl
call        sphere 0, 0, -20, 12, kl
call  child 11, -20, -10, 50, leg+lr, yzx, 1
call    sphere 0, 0, 0, 16, kl
call    sphere 0, -20, 0, 16, kl
call    child 12, 0, -40, 0, knee+lr, xyz, 11
call      sphere 0, 0, 0, 16, kl
call      sphere 0, -20, 0, 16, kl
call      child 13, 0, -40, 0, enkle+lr, xzy, 12
call        sphere 0, 0, 0, 12, kl
call        sphere 0, 0, -20, 12, kl
call  child 11, 20, -10, 0, arm, yzx, 1
call    sphere 0, 0, 0, 16, kl
call    sphere 0, -20, 0, 16, kl
call    child 12, 0, -40, 0, elbow, xyz, 11
call      sphere 0, 0, 0, 16, kl
call      sphere 0, -20, 0, 16, kl
call      child 13, 0, -40, 0, wrist, xzy, 12
call        sphere 0, 0, 0, 12, kl
call        sphere 0, 0, -20, 12, kl
call  child 11, -20, -10, 0, arm+lr, yzx, 1
call    sphere 0, 0, 0, 16, kl
call    sphere 0, -20, 0, 16, kl
call    child 12, 0, -40, 0, elbow+lr, xyz, 11
call      sphere 0, 0, 0, 16, kl
call      sphere 0, -20, 0, 16, kl
call      child 13, 0, -40, 0, wrist+lr, xzy, 12
call        sphere 0, 0, 0, 12, kl
call        sphere 0, 0, -20, 12, kl
call  child 3 , 0,14,90 , tail , xyz , 2
    for i = 0 to 5
call      sphere 0,i*12,0,10 , kl
    next i

end sub

sub animation anim , frame , amp
  select case anim
  case manwalk
call    skelet leg , pend( frame , amp ) , 0 , 0
call    skelet knee , pend( frame - 90 , amp ) + amp  , 0 , 0
call    skelet leg + lr , pend( frame + 180 , amp ) , 0 , 0
call    skelet knee + lr , pend( frame + 90 , amp ) + amp , 0 , 0
call    skelet arm , pend( frame + 180 , amp ) , 0 , 0
call    skelet elbow , 0 -amp , 0 , 0
call    skelet arm + lr , pend( frame , amp ) , 0 , 0
call    skelet elbow + lr , 0 -amp , 0 , 0
  case dogwalk
call    skelet leg , pend( frame , amp ) , 0 , 0
call    skelet knee , pend( frame - 90 , amp ) + amp  , 0 , 0
call    skelet leg + lr , pend( frame + 180 , amp ) , 0 , 0
call    skelet knee + lr , pend( frame + 90 , amp ) + amp , 0 , 0
call    skelet arm , pend( frame , amp ) , 0 , 0
call    skelet elbow , pend( frame - 90 , amp ) + amp  , 0 , 0
call    skelet arm + lr , pend( frame + 180 , amp ) , 0 , 0
call    skelet elbow + lr , pend( frame + 90 , amp ) + amp , 0 , 0
call    skelet tail , -45 , pend( frame * 2 , amp ) , 0
    case ileftlegs
      for i = 0 to 4
call          skelet ileg+i , 0,0,pend(frame+180*i,amp)
call          skelet iknee+i , pend(frame+180+180*i,amp),0,0
        next i
    case irightlegs
      for i = 0 to 4
call          skelet ileg+i+lr , 0,0,pend(frame+180*i,amp)
call          skelet iknee+i+lr , pend(frame+180+180*i,amp),0,0
      next i
    case isting
call      skelet itail , 90/7+pend(frame,amp) , 0 , 0
call      skelet itail+lr , 90/7-pend(frame,amp) , 0 , 0
    case ifly
call      skelet iwing , 0 , 0 , pend(frame,amp)
call      skelet iwing+1 , 0 , 0 , pend(frame,amp)
call      skelet iwing+lr , 0 , 0 , 0-pend(frame,amp)
call      skelet iwing+1+lr , 0 , 0 , 0-pend(frame,amp)
    case ileftbox
call      skelet iarm , 0 , pend(frame,amp)-20 , 0
call      skelet ielbow , 0 , 30-pend(frame,amp) , 0
    case irightbox
call      skelet iarm+lr , 0 , 20-pend(frame,amp) , 0
call      skelet ielbow+lr , 0 , pend(frame,amp)-30 , 0
    case home
      for i = 0 to 64
call        skelet i , 0 , 0 , 0
      next i
    case else
call    skelet itail , 90/7,0,0
call    skelet itail+lr , 90/7,0,0
call    skelet iarm , 0,-20,0
call    skelet ielbow , 0,30,0
call    skelet iarm+lr , 0,20,0
call    skelet ielbow+lr , 0,-30,0
call    skelet ineck+lr , 20,0,0
call    skelet ieye , -20,0,0
call    skelet ieye+lr , -20,0,0
  end select
end sub
bluatigro
 
Berichten: 301
Geregistreerd: za sep 27, 2008 6:01 pm

[blocks] : example : raycasting 3.0

Berichtdoor bluatigro » do dec 01, 2016 1:21 pm

Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
gosub [math]
gosub [color]
gosub [ray]
gosub [basis3D]
gosub [avartar]
nomainwin
open "ray 3.0" for graphics as #m
  #m "trapclose [qiut]"
  call camara 0,0,0 , 0,0,0 , 1
  call link 1 , -100,100,0 , 30,0,0 , 0 , 0
  call man yellow , blue
  call link 1 , 100,100,0 , 30,0,0 , 0 , 0
  call pilko orange

  for x = 0-winx/2 to winx/2
    for y = 0-winy/2 to winy/2
      kl = render(0,0,-1000 , x,y,1000 , 0)
      call setcolor kl
      #m "goto ";winx/2+x;" ";winy/2+y
      #m "down"
      #m "set ";winx/2+x;" ";winy/2+y
      #m "up"
    next y
  next x
  call saveframe "ray" , 0 , 2
  notice "ready"
wait
[quit]
  close #m
end
''add blocks :
''math
''color
''ray world
''basis3D
''vector3D
''avartars
''animation

bluatigro
 
Berichten: 301
Geregistreerd: za sep 27, 2008 6:01 pm

[blocks] : lijn | wire world

Berichtdoor bluatigro » do dec 01, 2016 2:06 pm

Code: Selecteer alles
''bluatigro 1 dec 2016
''wire world block
''needs basis3D , color and math block

sub okto x , y , z , dx , dy , dz , t , kl
  call wire x,y+dy,z,x,y,z+dz,t,kl
  call wire x,y,z+dz,x,y-dy,z,t,kl
  call wire x,y-dy,z,x,y,z-dz,t,kl
  call wire x,y,z-dz,x,y+dy,z,t,kl
  call wire x+dx,y,z,x,y,z+dz,t,kl
  call wire x,y,z+dz,x-dx,y,z,t,kl
  call wire x-dx,y,z,x,y,z-dz,t,kl
  call wire x,y,z-dz,x+dx,y,z,t,kl
  call wire x+dx,y,z,x,y+dy,z,t,kl
  call wire x,y+dy,z,x-dx,y,z,t,kl
  call wire x-dx,y,z,x,y-dy,z,t,kl
  call wire x,y-dy,z,x+dx,y,z,t,kl
end sub

sub dodecahedron x , y , z , d , dik , kl
  f = ( sqr( 5 ) - 1 ) / 2
  ''(±1, ±1, ±1)
  ''(0, ±1/f, ±f)
  ''(±1/f, ±f, 0)
  ''(±f, 0, ±1/f)
  call wire x + d , y + d , z + d , x , y + 1/f*d , z + f*d ,dik,kl
  call wire x + d , y + d , z + d , x + 1/f*d , y + f*d , z ,dik,kl
  call wire x + d , y + d , z + d , x + f*d , y , z + 1/f*d ,dik,kl
  call wire x - d , y - d , z - d , x , y - 1/f*d , z - f*d ,dik,kl
  call wire x - d , y - d , z - d , x - 1/f*d , y - f*d , z ,dik,kl
  call wire x - d , y - d , z - d , x - f*d , y , z - 1/f*d ,dik,kl
end sub

sub cube mx , my , mz , dx , dy , dz , dik , kl
  call wire mx - dx , my - dy , mz - dz _
     , mx + dx , my - dy , mz - dz , dik , kl
  call wire mx - dx , my + dy , mz - dz _
     , mx + dx , my + dy , mz - dz , dik , kl
  call wire mx - dx , my - dy , mz + dz _
     , mx + dx , my - dy , mz + dz , dik , kl
  call wire mx - dx , my + dy , mz + dz _
     , mx + dx , my + dy , mz + dz , dik , kl
  call wire mx - dx , my - dy , mz - dz _
     , mx - dx , my + dy , mz - dz , dik , kl
  call wire mx + dx , my - dy , mz - dz _
     , mx + dx , my + dy , mz - dz , dik , kl
  call wire mx - dx , my - dy , mz + dz _
     , mx - dx , my + dy , mz + dz , dik , kl
  call wire mx + dx , my - dy , mz + dz _
     , mx + dx , my + dy , mz + dz , dik , kl
  call wire mx - dx , my - dy , mz - dz _
     , mx - dx , my - dy , mz + dz , dik , kl
  call wire mx + dx , my - dy , mz - dz _
     , mx + dx , my - dy , mz + dz , dik , kl
  call wire mx - dx , my + dy , mz - dz _
     , mx - dx , my + dy , mz + dz , dik , kl
  call wire mx + dx , my + dy , mz - dz _
     , mx + dx , my + dy , mz + dz , dik , kl
end sub

sub wire x1 , y1 , z1 , x2 , y2 , z2 , dik , kl
   call spot x1 , y1 , z1
   call spot x2 , y2 , z2
   ax = winx / 2 + x1 / ( z1 + 1000 ) * 1000
   ay = winy / 2 - y1 / ( z1 + 1000 ) * 1000
   bx = winx / 2 + x2 / ( z2 + 1000 ) * 1000
   by = winy / 2 - y2 / ( z2 + 1000 ) * 1000
   #m "size "; dik
   call setcolor kl
   #m "down"
   #m "line "; ax ;" "; ay ;" "; bx ;" "; by
   #m "up"
end sub

sub bol x , y , z , d , dik , kl
  call spot x , y , z
  d = d * cam( 6 )
  call setcolor kl
  d = d / ( z + 1000 ) * 1000
  x = winx / 2 + x / ( z + 1000 ) * 1000
  y = winy / 2 - y / ( z + 1000 ) * 1000
  print #m , "go "; x ;" "; y
  print #m , "down"
  print #m , "circle "; d
  print #m , "up"
end sub
bluatigro
 
Berichten: 301
Geregistreerd: za sep 27, 2008 6:01 pm


Keer terug naar Liberty BASIC Code

Wie is er online

Gebruikers op dit forum: Geen geregistreerde gebruikers. en 1 gast

cron