SPRITE DRAW

Start hier uw open source projecten

SPRITE DRAW

Berichtdoor bluatigro » vr maart 19, 2010 10:18 am

dit is n programma dat sprites tekent
met comandos
geanimeerde sprites zijn mogelijk
of tegels voor n bewegende achtergrond

als je meer comandos nodig hebt
vraag dan
Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global height , pi , WinY
global black , red , green , yellow
global blue , magenta , cyan , white
global pink , purple , gray , orange
WinY = WidowHeight
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 )
nocolor = -1
nomainwin
open "Sprites" for graphics as #m
  #m "trapclose [quit]"
''the folowing sprite-draw-comands are there
''kl = color
''if kl = nocolor then it draws transparent
''clear
''drawline x1 , y1 , z2 , y2 , thick , kl
''elipse x , y , dx , dy , kl
''box x1 , y1 , x2 , y2 , kl
''the begin and end are in degrees
''and can be different setiings for same results
''arc x , y , dx , dy , begin , end , kl
''pie x , y , dx , dy , begin , end , kl
''ring x , y , dx , dy , d , kl
''  ring you have to call twice 1 whit nocolor
''  and 2 whit the color you want and you do y+64
''save spr$
  call clear

  for i = 0 to 360
    call drawline 31 , 31 _
    , sin( rad( i ) ) * 27 + 31  _
    , cos( rad( i ) ) * 27 + 31 , 3 , rainbow( i )
  next i
wait
function nr$( no , max )
  nr$ = right$( "00000000" + str$( no ) , max )
end function
[quit]
  close #m
end
sub save spr$
    #m "getbmp bmp 0 0 64 128"
    bmpsave "bmp", DefaultDir$ + "\BMP\" _
    + spr$ + ".bmp"
end sub
sub clear
    #m "cls"
    #m "color white"
    #m "backcolor white"
    #m "goto 0 0"
    #m "down"
    #m "boxfilled 64 64"
    #m "up"
    #m "goto 0 65"
    #m "down"
    #m "color black"
    #m "backcolor black"
    #m "boxfilled 64 128"
    #m "up"
end sub
sub pie x , y , h , w , b , e , kl
  if kl = nocolor then
    #m "color white"
    #m "goto "; x ; " "; y
    #m "down"
    #m "piefilled " ; w ; " " ; h ; " " ; w ; " " ; h
    #m "up"
    #m "color black"
    #m "goto "; x ; " " ; y + 64
    #m "down"
    #m "piefilled " ; w ; " " ; h ; " " ; w ; " " ; h
    #m "up"
  else
    #m "color black"
    #m "goto "; x ; " "; y
    #m "down"
    #m "piefilled " ; w ; " " ; h ; " " ; w ; " " ; h
    #m "up"
    call setcolor kl
    #m "goto "; x ; " "; y + 64
    #m "down"
    #m "piefilled " ; w ; " " ; h ; " " ; w ; " " ; h
    #m "up"
  end if
end sub

sub drawline x1 , y1 , x2 , y2 , thick , kl
  #m "size " ; thick
  if kl = nocolor then
    #m "color white"
    #m "down"
    #m "line "; x1 ; " "; y1 ; " " ; x2 ; " " ; y2
    #m "up"
    #m "color black"
    #m "down"
    #m "line "; x1 ; " "; y1 + 64 ; " " ; x2 ; " " ; y2 + 64
    #m "up"
  else
    #m "color black"
    #m "down"
    #m "line "; x1 ; " "; y1 ; " " ; x2 ; " " ; y2
    #m "up"
    call setcolor kl
    #m "down"
    #m "line "; x1 ; " "; y1 + 64 ; " " ; x2 ; " " ; y2 + 64
    #m "up"
  end if
end sub
sub ring mx , my , dx , dy , d , clr
  WinX = 0
  WinY = 0
  for i = 0 to 90 step 90 / ( dx + dy )
    x = sin( rad( i ) )
    y = cos( rad( i ) )
    kl = mix( clr , 0 - i / 90 , black )
    if clr = nocolor then kl = black
    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
    #m "down"
    #m "line " ; x * dx + WinX / 2 + mx ; " " _
    ; y * dy + WinY / 2 + my ; " " _
    ; x * dx + d + WinX / 2 + mx ; " " _
    ; y * dy + WinY / 2 + my
    #m "up"
    #m "down"
    #m "line " ; x * ( dx - d ) + WinX / 2 + mx ; " " _
    ; WinY / 2 - y * ( dy - d ) + my ; " " _
    ; x * ( dx - d ) + WinX / 2 + d + mx ; " " _
    ; WinY / 2 -y * ( dy - d ) + my
    #m "up"
    kl = mix( clr , 0 - i / 90 , white)
    if clr = -1 then kl = black
    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
    #m "down"
    #m "line " ; WinX / 2 - x * ( dx - d ) + mx ; " " _
    ; WinY / 2 + y * ( dy - d ) + my ; " " _
    ; WinX / 2 - x * ( dx - d ) + d + mx ; " " _
    ; WinY / 2 + y * ( dy - d ) + my
    #m "up"
    #m "down"
    #m "line " ; WinX / 2 - x * dx + mx ; " " _
    ; WinY / 2 - y * dy + my ; " " _
    ; WinX / 2 - x * dx + d + mx ; " " _
    ; WinY / 2 - y * dy + my
    #m "up"
  next i
  if clr = nocolor then clr = black
  for i = 0 to d
    call arc WinX / 2 + mx , WinY / 2 + my , dx - i , dy - i _
    , -90 , 90 , clr
    call arc WinX / 2 + d +mx, WinY / 2 +my , dx - i , dy - i _
    , 90 , 270 , clr
  next i
end sub
sub arc mx , my , dx , dy , b , e , kl
  call setcolor kl
  if kl = nocolor then
    for i = b to e step 50 / ( dx + dy )
      x = sin( rad( i ) ) * dx + mx
      y = cos( rad( i ) ) * dy + my
      #m "color white"
      #m "down"
      #m "set " ; x ; " " ; y
      #m "up"
      #m "color black"
      #m "down"
      #m "set " ; x ; " " ; y + 64
      #m "up"
    next i
  else
    for i = b to e step 50 / ( dx + dy )
      x = sin( rad( i ) ) * dx + mx
      y = cos( rad( i ) ) * dy + my
      #m "down"
      #m "set " ; x ; " " ; y + 64
      #m "up"
    next i
  end if
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
sub sphere x , y , z , d , kl
  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
    dx = WindowWidth
    dy = WindowHeight
    print #m , "goto "; x ;" " _
    ; dy - height - z / 4
    print #m , "down"
    print #m , "ellipsefilled "; dd ;" "; dd / 4
    print #m , "up"
  end if
end sub
function rad( deg )
  rad = deg * pi / 180
end function
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
sub box x , y , w , h , kl
  if kl = nocolor then
    #m "goto " ; x ; " " ; y
    #m "color white"
    #m "backcolor white"
    #m "down"
    #m "boxfilled " ; w ; " " ; h
    #m "up"
    #m "goto " ; x ; " " ; y + 64
    #m "color black"
    #m "backcolor black"
    #m "down"
    #m "ellipsefilled " ; w ; " " ; h
  else
    #m "goto " ; x ; " " ; y
    #m "color black"
    #m "backcolor black"
    #m "down"
    #m "boxfilled " ; w ; " " ; h
    #m "up"
    #m "goto " ; x ; " " ; y + 64
    call setcolor kl
    #m "down"
    #m "boxfilled " ; w ; " " ; h + 64
    #m "up"
  end if
end sub
sub elipse x , y , dx , dy , kl
  if kl = nocolor then
    #m "goto " ; x ; " " ; y
    #m "color white"
    #m "backcolor white"
    #m "down"
    #m "ellipsefilled " ; dx ; " " ; dy
    #m "up"
    #m "goto " ; x ; " " ; y + 64
    #m "color black"
    #m "backcolor black"
    #m "down"
    #m "ellipsefilled " ; dx ; " " ; dy
  else
    #m "goto " ; x ; " " ; y
    call setcolor kl
    #m "down"
    #m "ellipsefilled " ; dx ; " " ; dy
    #m "up"
    #m "goto " ; x ; " " ; y + 64
    #m "color " ; clr$
    #m "backcolor " ; clr$
    #m "down"
    #m "ellipsefilled " ; dx ; " " ; dy
    #m "up"
  end if
end sub


Edit Gordon: Ontbrekende end sub geplaatst.
bluatigro
 
Berichten: 301
Geregistreerd: za sep 27, 2008 6:01 pm

Re: SPRITE DRAW

Berichtdoor bluatigro » za apr 10, 2010 7:10 pm

code verhuist naar :

http://www.basic.wikispaces.com

zie member pages | bluatigro | how to draw your Sprites

main code :
Draw Bool Sprites
example code :
DBS pacman
DBS molecule
DBS ball
DBS monkey

comando lijst :

constanten :
black red geen yellow blue magenta cyan white
gray pink orange purple
clr = rainbow( degrees )
clr = mix( clrl1 , 0 ... 1 , clr2 )
clr = rgb( r , g , b )

clear spritewidth , spriteheight

==== 2D ====
[ whit a "normal" sprite up = black ]
drawline x1 , y1 , z2 , y2 , thick , down , up
elipse x , y , dx , dy , thick , down , up
elipsefil x , y , dx , dy , down , up
box x1 , y1 , x2 , y2 , thick , down , up
boxfil x1 , y1 , x2 , y2 , down , up
the begin and end are in degrees
and can be different setiings for same results
arc x , y , dx , dy , begin , end , down , up
pie x , y , dx , dy , begin , end , thick , down , up
piefil x , y , dx , dy , begin , end , down , up
blezier x1,y1 , x2,y2 , x3,y3 , x4,y4 , thick,down,up

==== 3D ====
[ this needs a for height = 0 - spry to spry loop ]
sphere x , y , z , d , clr
q is in degrees and rotates the spheres Yas
sphere2 x , y , z , d , clr1 , clr2 , q
egg x1,y1,z1,d1 , x2,y2,z2,d2 , dm , clr

save spr$
[ dont forget : change path in sub save if needed ]

NIET buiten de sprite tekenen !!!!

als iemand nog uitbreidingen wil vraag dan
bluatigro
 
Berichten: 301
Geregistreerd: za sep 27, 2008 6:01 pm


Keer terug naar OPEN SOURCE PROJECTEN

Wie is er online

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

cron