home *** CD-ROM | disk | FTP | other *** search
/ DarkBasic Professional / DarkBasicPro.iso / data1.cab / Lang_Files_(English) / Help / examples / basic2d / basic2d1-example.dba < prev    next >
Encoding:
Text File  |  2004-09-22  |  3.2 KB  |  130 lines

  1. rem Basic2D Showcase
  2.  
  3. rem Standard Setup Code for all examples
  4. sync on : sync rate 0
  5. set text font "arial" : set text size 16
  6. set text to bold : set text transparent
  7.  
  8. rem Nice backdrop
  9. load bitmap "parchment.jpg"
  10.  
  11. rem Produce Title
  12. ink rgb(0,0,0),0 : center text (screen width()/2)+1,7,"2D Graphics Support"
  13. ink rgb(255,255,255),0 : center text screen width()/2,6,"2D Graphics Support"
  14.  
  15. rem Create an array to hold pixeldatas
  16. bitsperpixel=bitmap depth()/8
  17. workA = make memory(640*480*bitsperpixel)
  18. fill memory workA, 0, 640*480*bitsperpixel
  19.  
  20. rem Create Art Space
  21. set current bitmap 0
  22. box 48,48,640-48,450-48,rgb(255,255,0),rgb(255,200,255),rgb(255,255,200),rgb(200,255,255)
  23. lock pixels
  24. pitch=get pixels pitch() : ptr=get pixels pointer()
  25. workAptr=workA : linesize=640*bitsperpixel
  26. for y=0 to 479
  27.  copy memory workAptr, ptr, linesize : inc workAptr,640*bitsperpixel : inc ptr,pitch
  28. next y
  29. unlock pixels
  30.  
  31. rem Main loop
  32. do
  33.  
  34. rem Draw to Memory
  35. mx=mousex() : my=mousey()
  36. focus=16*(1+size)
  37. if mx>focus and mx<640-focus and my>focus and my<479-focus
  38.  for focus=1 to 16*(1+size)
  39.   for y=my-focus to my+focus
  40.    penwidth=focus-abs(y-my)
  41.    for x=mx-penwidth to mx+penwidth
  42.     workptr=workA+(x*bitsperpixel)+(y*640*bitsperpixel)
  43.     col = *workptr
  44.     colb = col && %1111111111111111
  45.     if bitsperpixel=2
  46.      cr = (col && %11111000000000000000000000000000)>>27
  47.      cg = (col && %00000111111000000000000000000000)>>21
  48.      cb = (col && %00000000000111110000000000000000)>>16
  49.      dec cr
  50.      dec cg
  51.      dec cb
  52.     endif
  53.     if bitsperpixel=4
  54.      cr = rgbr(col) - 1
  55.      cg = rgbg(col) - 1
  56.      cb = rgbb(col) - 1
  57.     endif
  58.     if nocap=0
  59.      if cr<0 then cr=0
  60.      if cg<0 then cg=0
  61.      if cb<0 then cb=0
  62.     endif
  63.     if bitsperpixel=2
  64.      col = (cr<<27)+(cg<<21)+(cb<<16)
  65.      *workptr = col+colb
  66.     endif
  67.     if bitsperpixel=4
  68.      col = rgb(cr,cg,cb)
  69.      *workptr = col
  70.     endif
  71.    next x
  72.   next y
  73.  next focus
  74. endif
  75.  
  76. rem Draw Memory to screen
  77. workAptr=workA+(640*48*bitsperpixel)
  78. ymax=450-48
  79. lock pixels
  80. linesize=(640-48-48)*bitsperpixel
  81. pitch=get pixels pitch()
  82. ptr=get pixels pointer()+(48*pitch)
  83. for y=48 to ymax
  84.  copy memory ptr+(48*bitsperpixel), workAptr+(48*bitsperpixel), linesize
  85.  inc workAptr,640*bitsperpixel
  86.  inc ptr,pitch
  87. next y
  88. unlock pixels
  89.  
  90. rem Show Buttons
  91. over=0
  92. for but=1 to 3
  93.  for high=0 to 1
  94.   if high=0 then ink rgb(20,20,20),0 : bx=-1 : by=-1
  95.   if high=1 then ink rgb(100,200,100),0 : bx=0 : by=0
  96.   if high=1 and mousey()>420 and mousey()<460
  97.    if but=1 and abs(mousex()-170)<50 then ink rgb(255,255,255),0 : over=1
  98.    if but=2 and abs(mousex()-320)<50 then ink rgb(255,255,255),0 : over=2
  99.    if but=3 and abs(mousex()-470)<50 then ink rgb(255,255,255),0 : over=3
  100.   endif
  101.   if but=1 then but$="SIZE"
  102.   if but=2 then but$="PLASMA"
  103.   if but=3 then but$="EXIT"
  104.   center text 320+bx+((but-2)*150),420+by,but$
  105.  next high
  106. next but
  107.  
  108. rem Controls
  109. if mouseclick()=1
  110.  if once=0
  111.   once=1
  112.   if over=1 then size=size+1
  113.   if over=2 then nocap=1-nocap
  114.   if size=3 then size=0
  115.   if over=3 then delete memory workA : end
  116.  endif
  117. else
  118.  once=0
  119. endif
  120.  
  121. rem Update screen
  122. sync
  123.  
  124. rem End loop
  125. loop
  126.  
  127. rem Free memory
  128. delete memory workA
  129. delete memory workB
  130.