MINIONS

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

Moderators: anthonio, Abcott

MINIONS

Berichtdoor bluatigro » vr jul 10, 2015 10:43 am

deze code tekent n paar minions

WARNING : t duurt wel lang

Code: Selecteer alles
''bluatigro 6 jul 2015
''sphere world : minion
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global height , pi , winx , winy , sprx , spry
global black , red , green , yellow
global blue , magenta , cyan , white
global pink , purple , gray , orange
global bmpx , bmpy , number
winy = WindowHeight
winx = WindowWidth
dim m( 26 * 4 * 4 ) , sk( 64 , 2 )
m(in(0,0,0))=1
m(in(0,1,1))=1
m(in(0,2,2))=1
m(in(0,3,3))=1
global trans,rotx,roty,rotz,temp
trans=25
rotx=24
roty=23
rotz=22
temp=21
pi = atn( 1 ) * 4
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 )
global xyz,xzy,yxz,yzx,zxy,zyx
xyz=0
xzy=1
yxz=2
yzx=3
zxy=4
zyx=5
global arm,elbow,wrist,leg,knee,enkle,eye,lr
arm=0
elbow=1
wrist=2
leg=3
knee=4
enkle=5
eye=6
lr=32
nomainwin
open "minion" for graphics as #m
  #m "trapclose [quit]"
''the folowing BMP-draw-comands are there
''sphere x , y , z , d
''egg x,y,z,d,x1,y1,z1,d1,dm,kl,no
''ring x,y,z,dgr,dkl,kl,no
''save bmp$
'' = nr$( no , max )
''==================== BEGIN BMP DRAW CODE
  call man.walk 0 , 30
  for height = 0-winy/2 to winy/2
    call link 1 , -300,0,0 , 90,0,0 , xyz , 0
      call minion               
    call link 1 , 0,0,0 , 45,0,0 , xyz , 0
      call minion               
    call link 1 , 300,0,0 , 0,0,0 , xyz , 0
      call minion               
  next height
''==================== END BMP DRAW CODE
notice "ready"
#m "flush"
wait
sub man.walk fase , amp
''example animation
  call skelet leg , pend( fase , amp ) , 0 , 0
  call skelet knee , pend( fase - 90 , amp ) + amp  , 0 , 0
  call skelet leg + lr , pend( fase + 180 , amp ) , 0 , 0
  call skelet knee + lr , pend( fase + 90 , amp ) + amp , 0 , 0
  call skelet arm , pend( fase + 180 , amp ) , 0 , 0
  call skelet elbow , 0-amp , 0 , 0
  call skelet arm + lr , pend( fase , amp ) , 0 , 0
  call skelet elbow + lr , 0-amp , 0 , 0
end sub

sub minion
''example avatar
  call egg 0,0,0 , 50 , 0,90,0 , 50 , 50 , yellow , 0
  call sphere 50,0,0 , 15 , yellow
  call sphere -50,0,0 , 15 , yellow
  call egg 0,-50,0 , 50 , 0,0,0 , 50 , 50 , blue , 0
  call link 2 , 25,70,-45 , 0,90,0 , xyz , 1
    call ring 0,0,0,27,5,gray,0
  call link 2 , -25,70,-45 , 0,90,0 , xyz , 1
    call ring 0,0,0,27,5,gray,0
  call child 2 , 25,70,-40 , eye , xyz , 1
    call sphere 0,0,0 , 20 , white
    call sphere 0,0,-20 , 7 , black
  call child 2 , -25,70,-40 , eye+lr , xyz , 1
    call sphere 0,0,0 , 20 , white
    call sphere 0,0,-20 , 7 , black
  call child 2 , 60,0,0 , arm , xzy , 1
    call egg 0,0,0,8 , 0,-50,0,8 , 8 , yellow , 0
    call child 3 , 0,-50,0 , elbow , xyz , 2
      call egg 0,0,0,8 , 0,-50,0,8 , 8 , yellow , 0
      call child 4 , 0,-50,0 , wrist , yzx , 3
        call egg 0,0,0,8 , 0,-30,0,1 , 10 , yellow , 0
  call child 2 , -60,0,0 , arm+lr , xzy , 1
    call egg 0,0,0,8 , 0,-50,0,8 , 8 , yellow , 0
    call child 3 , 0,-50,0 , elbow+lr , xyz , 2
      call egg 0,0,0,8 , 0,-50,0,8 , 8 , yellow , 0
      call child 4 , 0,-50,0 , wrist+lr , yzx , 3
        call egg 0,0,0,8 , 0,-30,0,1 , 10 , yellow , 0
  call child 2 , 25,-85,0 , leg , yzx , 1
    call egg 0,0,0,20 , 0,-30,0,20 , 20 , blue , 0
    call child 3 , 0,-30,0 , knee , xyz , 2
      call egg 0,0,0,20 , 0,-30,0,20 , 20 , blue , 0
      call child 4 , 0,-30,0 , enkle , xyz , 3
        call egg 0,0,0,25 , 0,-30,-50,1 , 13 , yellow , 0
        call egg 0,0,0,25 , 20,-30,-50,1 , 13 , yellow , 0           
        call egg 0,0,0,25 , -20,-30,-50,1 , 13 , yellow , 0
  call child 2 , -25,-85,0 , leg+lr , yzx , 1
    call egg 0,0,0,20 , 0,-30,0,20 , 20 , blue , 0
    call child 3 , 0,-30,0 , knee+lr , xyz , 2
      call egg 0,0,0,20 , 0,-30,0,20 , 20 , blue , 0
      call child 4 , 0,-30,0 , enkle+lr , xyz , 3
        call egg 0,0,0,25 , 0,-30,-50,1 , 13 , yellow , 0
        call egg 0,0,0,25 , 20,-30,-50,1 , 13 , yellow , 0           
        call egg 0,0,0,25 , -20,-30,-50,1 , 13 , yellow , 0
end sub

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

[quit]
  close #m
end

sub save bmp$
    #m "getbmp bmp 0 0 " ; winx ; " " ; winy
     bmpsave "bmp", DefaultDir$ + "\bmp\" + bmp$ + ".bmp"
end sub

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

function rad( deg )
  rad = deg * pi / 180
end function

''    color math

function rainbow( deg )
  rainbow = rgb( sin( rad( deg ) ) * 127 + 128 _
               , sin( rad( deg - 120 ) ) * 127 + 128 _
               , sin( rad( deg + 120 ) ) * 127 + 128 )
end function

function rgb( r , g , b )
  rgb = ( r and 255 ) _
  + ( g and 255 ) * 256 _
  + ( b and 255 ) * 256 * 256
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
  dr = r2 - r1
  dg = g2 - g1
  db = b2 - b1
  dr = dr * f
  dg = dg * f
  db = db * f
  r = r1 + dr
  g = g1 + dg
  b = b1 + db
  mix = rgb( r and 255 , g and 255 , b and 255 )
end function

''    graphics

sub sphere x , y , z , d , clr
  call spot x , y , z
  mat = abs( mat )
  if abs( height - y ) < d then
    dd = sqr( d ^ 2 - ( height - y ) ^ 2 + .001 )
    clr = mix( black , ( height - y ) / d / 2 -.5, clr )
    call setcolor clr
    #m "goto " ; x + px + winx / 2 _
    ; " " ; winy / 2 - height - ( z + pz ) / 4
    #m "down"
    #m "ellipsefilled " ; dd * 2 ; " " ; dd / 2
    #m "up"
  end if
end sub

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

sub ring x,y,z,dg,dk,kl,no
  if no = 0 or no > dg * 4 then
    no = dg * 4
  end if
  for n = 0 to 2 * pi step 2*pi/no
    s = sin( n ) * dg
    c = cos( n ) * dg
    call sphere x+s,y,z+c,dk,kl
  next n
end sub
''    3d engine stuf

function pend( fase , amp )
''for natural movement of lim
  pend = sin( rad( fase ) ) * amp
end function

sub skelet lim , x , y , z
''set the angles of a lim
  if lim < 0 or lim > 64 then exit sub
  sk( lim , 0 ) = x
  sk( lim , 1 ) = y
  sk( lim , 2 ) = z
end sub

sub child no , x , y , z , lim , ax , p
''link a lim on a avatar root or lim
  if lim < 0 or lim > 64 then exit sub
  call link no , x , y , z _
  , sk( lim , 1 ) , sk( lim , 0 ) , sk( lim , 2 ) , ax , p
end sub

sub link no , x , y , z , xz , yz , xy , ax , p
''link a new matrix to a old one
  if no < 1 or no > 20 then exit sub
  if p < 0 or p > 20 then exit sub
  if no = p then exit sub

  call copy 0 , rotx
  call copy 0 , roty
  call copy 0 , rotz
  call copy 0 , trans

  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 ) )

  m( in( trans , 3 , 0 ) ) = x
  m( in( trans , 3 , 1 ) ) = y
  m( in( trans , 3 , 2 ) ) = z

  select case ax
    case xyz
      call keer rotx , roty , rotz , no , p
    case xzy
      call keer rotx , rotz , roty , no , p
    case yxz
      call keer roty , rotx , rotz , no , p
    case yzx
      call keer roty , rotz , rotx , no , p
    case zxy
      call keer rotz , rotx , roty , no , p
    case zyx
      call keer rotz , roty , rotx , no , p
    case else
      call keer rotx , roty , rorz , no , p
  end select

  number = no
end sub

sub keer a , b , c , no , p
''calculate new rotation + translation matrix
  call maal a , b , temp
  call maal temp , c , no
  call maal no , trans , temp
  call maal temp , p , no
end sub

function in( no , x , y )
''for 3D array
  in = no * 16 + x * 4 + y
end function

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

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

sub spot byref x , byref y , byref z
''from lokal to world coordinates
  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
  y = hy
  z = hz
end sub 


bluatigro
 
Berichten: 306
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