Ooops
October 28, 2020, 06:29:57 AM

Author Topic: [bb] TexTile by BlitzSupport [ 1+ years ago ]  (Read 1105 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] TexTile by BlitzSupport [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : TexTile
Author : BlitzSupport
Posted : 1+ years ago

Description : Lets you view and create tiled textures. READ THE IMPORTANT information in the source before doing anything!

Code :
Code: BlitzBasic
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8. ; READ IMPORTANT INFORMATION FIRST!!!!!!
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. ; ---------------------------------------------------------------
  17. ; Textile -- james@hi-toro.com -- Public Domain
  18. ; ---------------------------------------------------------------
  19. ; Crude little util for creating/editing B3D tileable textures.
  20. ; ---------------------------------------------------------------
  21.  
  22. ; Load a texture to see it tiled, or load a large image and create
  23. ; a new texture, eg. from the bricks of a building...
  24.  
  25. ; ***************************************************************
  26.  
  27. ; IMPORTANT!!! Seems to be a BB bug that saves the image into
  28. ; the boot drive root folder (eg. "C:"), instead of the
  29. ; current directory... so look there after quitting the program!
  30.  
  31. ; IMPORTANT 2!!! Don't try to run it from here! CREATE AS AN
  32. ; EXECUTABLE. Drag the image you want to load onto the
  33. ; program's icon to load it.
  34.  
  35. ; ***************************************************************
  36.  
  37. ; ---------------------------------------------------------------
  38. ; Controls
  39. ; ---------------------------------------------------------------
  40.  
  41. ; Use mouse to position box
  42. ; Use cursors to scroll around picture
  43. ; Use Ctrl + cursors to resize box
  44. ; Use < and > (actually , and .) to rotate (slowly!)
  45. ; Use < and > with Shift for larger rotation
  46. ; ESC quits and saves the texture
  47.  
  48. AppTitle "Textile"
  49.  
  50. ; Set display mode (windowed) and double-buffering:
  51. Graphics 640, 480, 0, 2
  52. SetBuffer BackBuffer ()
  53.  
  54. ; Source image position and limits to keep on screen:
  55. Global sourceImage, sourceCopy, sx, sy, maxsx, maxsy
  56. Global bw, resizing, rotation#
  57.  
  58. ; Load source image:
  59. a$ = CommandLine$ ()
  60. LoadSource (a$)
  61.  
  62. ; Resulting texture info:
  63. Global textureImage = CopyImage (sourceImage);CreateImage (TextureWidth, TextureHeight)
  64. Global texWidth = 64;ImageWidth (textureImage)
  65. Global texHeight = 64;ImageHeight (textureImage)
  66.  
  67. TFormFilter False
  68.  
  69. Repeat
  70.  
  71.         RotateSource ()
  72.         PositionSource ()      
  73.         CopyToTexture ()
  74.         ResizeTexture ()       
  75.         PrintInfo ()
  76.        
  77.         Flip
  78.  
  79. Until KeyHit (1)
  80.  
  81. SaveTexture ()
  82. End
  83.  
  84. ; ---------------------------------------------------------------
  85.  
  86. Function LoadSource (a$)
  87.         ; Weird, Win2000 adds quotes round the command line that Blitz chokes on, whereas 98 doesn't!
  88.         If Left (a$, 1) = Chr (34) And Right (a$, 1) = Chr (34)
  89.                 a$ = Mid (a$, 2, Len (a$) - 2)
  90.         EndIf
  91.         sourceImage = LoadImage (a$)
  92.         If sourceImage = 0 Then RuntimeError "[Guru Meditation]" + Chr (10) + Chr (10) + "Cannot load image. Throwing dollies out of pram...": End
  93.         sourceCopy = CopyImage (sourceImage)
  94.         If ImageWidth (sourceImage) > GraphicsWidth ()
  95.                 maxsx = - (ImageWidth (sourceImage) - GraphicsWidth ())
  96.         Else
  97.                 maxsx = 0
  98.         EndIf
  99.         If ImageHeight (sourceImage) > GraphicsHeight () / 2
  100.                 maxsy = - (ImageHeight (sourceImage) - (GraphicsHeight () / 2) + 1)
  101.         Else
  102.                 maxsy = 0
  103.         EndIf
  104.         sx = 0
  105.         sy = 0
  106. End Function
  107.  
  108. Function PositionSource ()
  109.  
  110.         Viewport 0, 0, GraphicsWidth (), (GraphicsHeight () / 2) - 1
  111.         Cls
  112.  
  113.         If Not resizing
  114.  
  115.                 If (KeyDown (42)) Or (KeyDown (54))
  116.                         jump = 32
  117.                 Else
  118.                         jump = 1
  119.                 EndIf
  120.        
  121.                 If maxsx <> 0
  122.                         If KeyDown (203)
  123.                                 sx = sx + jump
  124.                         EndIf
  125.                         If KeyDown (205)
  126.                                 sx = sx - jump
  127.                         EndIf
  128.                 EndIf
  129.        
  130.                 If maxsy <> 0
  131.                         If KeyDown (208)
  132.                                 sy = sy - jump
  133.                         EndIf
  134.                         If KeyDown (200)
  135.                                 sy = sy + jump
  136.                         EndIf
  137.                 EndIf
  138.                
  139.                 If sx > 0 Then sx = 0
  140.                 If sy > 0 Then sy = 0
  141.        
  142.                 If sx < maxsx Then sx = maxsx
  143.                 If sy < maxsy Then sy = maxsy
  144.  
  145.         EndIf
  146.        
  147.         DrawImage sourceImage, sx, sy
  148.  
  149. End Function
  150.  
  151. Function DrawBox ()
  152.         If bw Then c = 255 Else c = 0
  153.         Color c, c, c
  154.         Rect MouseX (), MouseY (), texWidth, texHeight, 0
  155. End Function
  156.  
  157. Function CopyToTexture ()
  158.         If MouseHit (1)
  159.                 FreeImage textureImage
  160.                 textureImage = CreateImage (texWidth, texHeight)
  161.                 GrabImage textureImage, MouseX (), MouseY ()
  162.         EndIf
  163.         DrawBox ()
  164.         bw = 1 - bw
  165.         Viewport 0, (GraphicsHeight () / 2) + 1, GraphicsWidth (), (GraphicsHeight () / 2) - 1
  166.         Cls
  167.         TileImage textureImage, 0, (GraphicsHeight () / 2) + 1
  168. End Function
  169.  
  170. Function ResizeTexture ()
  171.  
  172.         resizing = False
  173.        
  174.         If (KeyDown (29)) Or (KeyDown (157))
  175.  
  176.                 resizing = True
  177.                 changed = 0
  178.  
  179.                 If (KeyDown (42)) Or (KeyDown (54))
  180.                         jump = 16
  181.                 Else
  182.                         jump = 1
  183.                 EndIf
  184.  
  185.                 If KeyDown (203)
  186.                         texWidth = texWidth - jump
  187.                         changed = True
  188.                 EndIf
  189.  
  190.                 If KeyDown (205)
  191.                         texWidth = texWidth + jump
  192.                         changed = True
  193.                 EndIf
  194.        
  195.                 If KeyDown (200)
  196.                         texHeight = texHeight - jump
  197.                         changed = True
  198.                 EndIf
  199.  
  200.                 If KeyDown (208)
  201.                         texHeight = texHeight + jump
  202.                         changed = True
  203.                 EndIf
  204.  
  205.                 If texWidth < 2 Then texWidth = 2
  206.                 If texHeight < 2 Then texHeight = 2
  207.  
  208. ;               If changed
  209. ;                       FreeImage textureImage
  210. ;                       textureImage = CreateImage (texWidth, texHeight)
  211. ;               EndIf
  212.  
  213.         EndIf
  214.  
  215. End Function
  216.  
  217. Function PrintInfo ()
  218.         Color 0, 0, 0
  219.         Text 20, (GraphicsHeight () / 2) + 20, "Texture width: " + texWidth
  220.         Text 20, (GraphicsHeight () / 2) + 40, "Texture height: " + texHeight
  221.         Color 255, 255, 255
  222.         Text 21, (GraphicsHeight () / 2) + 21, "Texture width: " + texWidth
  223.         Text 20, (GraphicsHeight () / 2) + 41, "Texture height: " + texHeight
  224. End Function
  225.  
  226. Function SaveTexture ()
  227.         texture$ = "Texture.html"      
  228.         counter = 1
  229.         Repeat
  230.                 counter = counter + 1
  231.                 texture$ = "Texture" + counter + ".bmp"
  232.         Until FileType (texture$) = 0
  233.         SaveImage textureImage, CurrentDir$ () + "" + texture$
  234. End Function
  235.  
  236. Function RotateSource ()
  237.  
  238.         changed = False
  239.        
  240.         If (KeyDown (42)) Or (KeyDown (54))
  241.                 jump# = 0.5
  242.         Else
  243.                 jump# = 0.05
  244.         EndIf
  245.  
  246.         If KeyDown (51)
  247.                 FreeImage sourceImage
  248.                 sourceImage = CopyImage (sourceCopy)
  249.                 MidHandle sourceImage
  250.                 rotation = rotation - jump
  251.                 changed = True
  252.         EndIf
  253.  
  254.         If KeyDown (52)
  255.                 FreeImage sourceImage
  256.                 sourceImage = CopyImage (sourceCopy)
  257.                 MidHandle sourceImage
  258.                 rotation = rotation + jump
  259.                 changed = True
  260.         EndIf
  261.  
  262.         If changed
  263.                 RotateImage sourceImage, rotation
  264.                 HandleImage sourceImage, 0, 0
  265.                 If ImageWidth (sourceImage) > GraphicsWidth ()
  266.                         maxsx = - (ImageWidth (sourceImage) - GraphicsWidth ())
  267.                 Else
  268.                         maxsx = 0
  269.                 EndIf
  270.                 If ImageHeight (sourceImage) > GraphicsHeight () / 2
  271.                         maxsy = - (ImageHeight (sourceImage) - (GraphicsHeight () / 2) + 1)
  272.                 Else
  273.                         maxsy = 0
  274.                 EndIf
  275.         EndIf
  276.  
  277. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal