Bool Sprite Draw

Geef hier je beste Liberty BASIC tips door. (Hier geen hulp vragen)

Moderators: anthonio, Abcott

Bool Sprite Draw

Berichtdoor bluatigro » di maart 23, 2010 2:22 pm

dit programma herkent de volgende comandos
up = andcolor
down = orcolor
for a 'normal' sprite up = black
clear spritewidth , spriteheight
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
bezier x1,y1,x2,y2,x3,y3,x4,y4,thick,down,up
save spr$

je moet het path in sub save
aanpassen aan jouw systeem

dit kan ook gebruikt worden voor geanimeede sprites
of voor tegels voor beweegende achtergronden

ik heb er alle comandos die in liberty zitten
ingestopt plus 2 uitbrijdingen
als je meer nodig hebt vraag dan

Code: Selecteer alles
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
winy = WindowHeight
winx = WindowWidth
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 "Boolean Sprites Draw" for graphics as #m
  #m "trapclose [quit]"
  call clear 64 , 64

  for i = 0 to 360
    call drawline 31 , 31 _
    , sin( rad( i ) ) * 27 + 31  _
    , cos( rad( i ) ) * 27 + 31  _
    , 3 , rainbow( i ) , black
  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 " ; sprx ; " " ; spry * 2
     bmpsave "bmp", DefaultDir$ + "\BMP\" _
    + spr$ + ".bmp"
end sub
sub clear x , y
  #m "cls"
  #m "color white"
  #m "backcolor white"
  #m "goto 0 0"
  #m "down"
  #m "boxfilled " ; x ; " " ; y
  #m "up"
  #m "goto 0 " ; y + 1
  #m "down"
  #m "color black"
  #m "backcolor black"
  #m "boxfilled " ; x ; " " ; 2 * y
  #m "up"
  sprx = x
  spry = y
end sub
sub pie x , y , h , w , b , e , t , down , up
  #m "size " ; t
  call setcolor up
  #m "goto "; x ; " "; y
  #m "down"
  #m "piefilled " ; w ; " " ; h ; " " ; b ; " " ; e
  #m "up"
  call setcolor down
  #m "goto "; x ; " "; y + spry
  #m "down"
  #m "piefilled " ; w ; " " ; h ; " " ; b ; " " ; e
  #m "up"
end sub
sub piefil x , y , h , w , b , e , down , up
  call setcolor up
  #m "goto "; x ; " "; y
  #m "down"
  #m "piefilled " ; w ; " " ; h ; " " ; b ; " " ; e
  #m "up"
  call setcolor down
  #m "goto "; x ; " "; y + spry
  #m "down"
  #m "piefilled " ; w ; " " ; h ; " " ; b ; " " ; e
  #m "up"
end sub
sub drawline x1 , y1 , x2 , y2 , thick , down , up
  #m "size " ; thick
  call setcolor up
  #m "color black"
  #m "down"
  #m "line "; x1 ; " "; y1 ; " " ; x2 ; " " ; y2
  #m "up"
  call setcolor down
  #m "down"
  #m "line "; x1 ; " "; y1 + spry ; " " ; x2 ; " " ; y2 + spry
  #m "up"
end sub
sub arc mx , my , dx , dy , b , e , down , up
    call setcolor up
    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
      #m "up"
    next i
    call setcolor down
    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 + spry
      #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
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 , t , down , up
  #m "size " ; t
  #m "goto " ; x ; " " ; y
  call setcolor up
  #m "down"
  #m "box " ; w ; " " ; h
  #m "up"
  #m "goto " ; x ; " " ; y + spry
  call setcolor down
  #m "down"
  #m "box " ; w ; " " ; h + spry
  #m "up"
end sub
sub boxfil x , y , w , h , down , up
  #m "goto " ; x ; " " ; y
  call setcolor up
  #m "down"
  #m "boxfilled " ; w ; " " ; h
  #m "up"
  #m "goto " ; x ; " " ; y + spry
  call setcolor down
  #m "down"
  #m "boxfilled " ; w ; " " ; h + spry
  #m "up"
end sub
sub elipse x , y , dx , dy , t , down , up
  #m "size " ; t
  #m "goto " ; x ; " " ; y
  call setcolor up
  #m "down"
  #m "ellipse " ; dx ; " " ; dy
  #m "up"
  #m "goto " ; x ; " " ; y + spry
  call setcolor down
  #m "down"
  #m "ellipse " ; dx ; " " ; dy
  #m "up"
end sub
sub elipse x , y , dx , dy , down , up
  #m "goto " ; x ; " " ; y
  call setcolor up
  #m "down"
  #m "ellipsefilled " ; dx ; " " ; dy
  #m "up"
  #m "goto " ; x ; " " ; y + spry
  call setcolor down
  #m "down"
  #m "ellipsefilled " ; dx ; " " ; dy
  #m "up"
end sub
sub bezier x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 , t , d , u
  if ( abs( x1 - x2 ) <= 1 ) _
  and ( abs( y1 - y2 ) <= 1 ) then
    call drawline x1 , y1 , x2 , y2 , t , d , u
  else
    ax = ( x1 + x2 ) / 2
    ay = ( y1 + y2 ) / 2
    bx = ( x3 + x4 ) / 2
    by = ( y3 + y4 ) / 2
    cx = ( x3 + x2 ) / 2
    cy = ( y3 + y2 ) / 2
    a1x = ( ax + cx ) / 2
    a1y = ( ay + cy ) / 2
    b1x = ( bx + cx ) / 2
    b1y = ( by + cy ) / 2
    c1x = ( a1x + b1x ) / 2
    c1y = ( a1y + b1y ) / 2
    call bezier x1,y1 , ax,ay , a1x,a1y , c1x,c1y , kl,thick
    call bezier c1x,c1y , b1x,b1y , bx,by , x4,y4 , kl,thick
  end if
end sub
Laatst bijgewerkt door bluatigro op ma apr 12, 2010 2:03 pm, in totaal 1 keer bewerkt.
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: Bool Sprite Draw

Berichtdoor bluatigro » wo maart 24, 2010 2:22 pm

update :
voeg 2 subs toe
pixel x , y , down , up
pxls no , kl$
pxls :
teken n horizontale lijn no met kleuren kl$
B = zwart
R = rood
G = groen
Y = geel
b = blauw
M = magenta
C = cyaan
W = wit
o = oranje
p = roze
g = grijs
P = paars
ik stel n . voor als transparant
maar iets anders doet t ook
en zet je ide font op courier new
Code: Selecteer alles
sub pixel x , y , down , up
  #m "goto " ; x ; " " ; y
  call setcolor up
  #m "down"
  #m "set " ; x ; " " ; y
  #m "up"
  #m "goto " ; x ; " " ; y + spry
  call setcolor down
  #m "down"
  #m "set " ; x ; " " ; y + spry
  #m "up"
end sub
sub pxls no , kl$
  for i = 1 to len( kl$ )
    q$ = mid$( kl$ , i , 1 )
    select case q$
      case "B"
        call pixel i , no , black , black
      case "R"
        call pixel i , no , red , black
      case "G"
        call pixel i , no , green , black
      case "Y"
        call pixel i , no , yellow , black
      case "b"
        call pixel i , no , blue , black
      case "M"
        call pixel i , no , magenta , black
      case "C"
        call pixel i , no , cyan , black
      case "W"
        call pixel i , no , white , black
      case "o"
        call pixel i , no , orange , black
      case "p"
        call pixel i , no , pink , black
      case "g"
        call pixel i , no , gray , black
      case "P"
        call pixel i , no , purple , black
      case else ''transparent
        call pixel i , no , black , white
    end select
  end if
end sub
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: Bool Sprite Draw

Berichtdoor Gordon » do maart 25, 2010 11:33 pm

Ik vind het jammer dat er steeds fouten in jouw listings blijven.
De blezier sub klopt niet. Te veel en de verkeerde parameters.
De listing geeft ook een error omdat de sub elipse dubbel
voor komt.
In de laatste extra sub staat ook een end if zonder betekenis.

Gordon

p.s. Je kunt je bericht(en) wijzigen.
Avatar gebruiker
Gordon
Site Admin
 
Berichten: 684
Geregistreerd: zo mei 22, 2005 12:50 am

Re: Bool Sprite Draw

Berichtdoor bluatigro » ma apr 12, 2010 2:17 pm

update 13-mei-2010

code verhuist naar :

http://www.basic.wikispaces.com
member pages | bluatigro | how to draw your Sprites

main code :
Draw Bool Sprites
example code [ last updated ] :
DBS and or [ 24-apr-2010 ]
DBS ball [ 12-apr-2010 ]
DBS molecule [ 7-apr-2010 ]
DBS monkey [ 7-apr-2010 ]
DBS triangle [ 24-apr-2010 ]
DBS pacman [ 7-apr- 2010 ]

the folowing sprite-draw-comands are there [ 13-apr-2010 ]
clr = { black , red , green , yellow , blue , magenta , cyan , white
, pink , gray , purple , orange }
clr = rgb( r , g , b )
clr = rainbow( degrees )
clr = mix( clr1 , 0 ... 1 , clr2 )
up = andcolor
down = orcolor
for a 'normal' sprite up = black
clear spritewidth , spriteheight
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
REM : the begin and end are in degrees
REM : and can be different setiings for same results
arc x , y , dx , dy , begin , end , thick , 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
tri x1 , y1 , x2 , y2 , x3 , y3 , down , up
tri2 x1,y1,d1,u1,x2,y2,d2,u2,x3,y3,d3,u3
==== 3D ====
REM : if midden = (0,0,0) then in midden sprite
REM : needs a for height = 0-spry/2 to spry/2 loop
sphere x , y , z , d , kl
egg x1,y1,z1,d1 , x2,y2,z2,d2 , dm , kl
REM : q is in degrees and rotates the spheres Yas
REM : mat = { chaos , dot , dot6 , block , marble }
REM : if mat = < 0 then tranparant
REM : step .5
sphere2 x , y , z , d , kl1 , kl2 , q,mat
save spr$

als je r meer wilt doe dan maar n voorstel en ik kijk r naar

sprites gemaakt met deze code of delen erven zijn copyright-free
zolang je de code en zijn maker vermeld in je credits
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm


Keer terug naar Tips en informatie

Wie is er online

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

cron