December 03, 2020, 08:50:56 PM

Author Topic: [bb] 2D Image Transition by jfk EO-11110 [ 1+ years ago ]  (Read 411 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] 2D Image Transition by jfk EO-11110 [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : 2D Image Transition
Author : jfk EO-11110
Posted : 1+ years ago

Description : A warning - this is one of the first Programs I wrote in Blitz. There might be better Solutions. Especially when you own Blitz3D it is 100 times faster to use the 2 Pictures as Textures on alpha-transparent Meshes and crossfade them using EntityAlpha(). However, I let this code here as long as we have enough Space.

Code :
Code: BlitzBasic
  1. ; This Prog will fade from one Picture to an other one and back in 2D.
  2. ; Don't forget to turn off the Debugger.
  3.  
  4. Graphics 640,480
  5.  
  6. SetBuffer BackBuffer()
  7. bild1=LoadImage("s1.jpg") ; use 2 Pictures with 640*480 Pixels
  8. bild2=LoadImage("s3.jpg")
  9.  
  10. bild_op=CreateImage(640,1440)
  11. VWait 10
  12. SetBuffer ImageBuffer(bild_op)
  13. DrawImage bild1,0,0
  14. DrawImage bild1,0,480
  15. DrawImage bild2,0,960
  16. SetBuffer BackBuffer()
  17. DrawImage bild_op,0,0
  18.  
  19. bmax=15
  20.  
  21. ; mainloop
  22. While a<>27
  23.         a=GetKey()
  24.         Gosub myfader12
  25.         Gosub myfader21
  26. Wend
  27. End
  28.  
  29. .myfader12
  30. For b=0 To bmax
  31.         SetBuffer ImageBuffer(bild_op):LockBuffer:fx=0:fy=0:Gosub zeichne:UnlockBuffer:SetBuffer BackBuffer():DrawImage bild_op,0,0:Flip
  32.         SetBuffer ImageBuffer(bild_op):LockBuffer:fx=1:fy=0:Gosub zeichne:UnlockBuffer:SetBuffer BackBuffer():DrawImage bild_op,0,0:Flip
  33.         SetBuffer ImageBuffer(bild_op):LockBuffer:fx=0:fy=1:Gosub zeichne:UnlockBuffer:SetBuffer BackBuffer():DrawImage bild_op,0,0:Flip
  34.         SetBuffer ImageBuffer(bild_op):LockBuffer:fx=1:fy=1:Gosub zeichne:UnlockBuffer:SetBuffer BackBuffer():DrawImage bild_op,0,0:Flip
  35.         If KeyHit(1) Then Exit
  36. Next
  37. Return
  38. .myfader21
  39. For b=bmax To 0 Step -1
  40.         SetBuffer ImageBuffer(bild_op):LockBuffer:fx=0:fy=0:Gosub zeichne:UnlockBuffer:SetBuffer BackBuffer():DrawImage bild_op,0,0:Flip
  41.         SetBuffer ImageBuffer(bild_op):LockBuffer:fx=1:fy=0:Gosub zeichne:UnlockBuffer:SetBuffer BackBuffer():DrawImage bild_op,0,0:Flip
  42.         SetBuffer ImageBuffer(bild_op):LockBuffer:fx=0:fy=1:Gosub zeichne:UnlockBuffer:SetBuffer BackBuffer():DrawImage bild_op,0,0:Flip
  43.         SetBuffer ImageBuffer(bild_op):LockBuffer:fx=1:fy=1:Gosub zeichne:UnlockBuffer:SetBuffer BackBuffer():DrawImage bild_op,0,0:Flip
  44. If KeyHit(1) Then Exit
  45. Next
  46. Return
  47.  
  48. .zeichne
  49. For y = 0 To 479 Step 2
  50.         For x = 0 To 639 Step 2
  51.  
  52.                 f1=ReadPixelFast(x+fx,y+480+fy) And $ffffff
  53.                 f1r=f1 And $ff0000
  54.                 f1g=f1 And $ff00
  55.                 f1b=f1 And $ff
  56.  
  57.                 f2=ReadPixelFast(x+fx,y+960+fy) And $ffffff
  58.                 f2r=f2 And $ff0000
  59.                 f2g=f2 And $ff00
  60.                 f2b=f2 And $ff
  61.  
  62.                 b2#=b
  63.                 bma#=bmax
  64.                 bbm#=b2#/bma#
  65.                 b2m#=(bma#-b2#)/bma#
  66.  
  67.                 f3r=((f2r*bbm#)+(f1r*b2m#)) And $ff0000
  68.                 f3g=((f2g*bbm#)+(f1g*b2m#)) And $ff00
  69.                 f3b=((f2b*bbm#)+(f1b*b2m#)) And $ff
  70.  
  71.                 f3=f3r Or f3g Or f3b
  72.                 WritePixelFast x+fx,y+fy,f3
  73.         Next
  74. Next
  75. Return


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal