December 04, 2020, 10:59:49 AM

Author Topic: [bb] Colour Chart by Rob Farley [ 1+ years ago ]  (Read 768 times)

Offline BlitzBot

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

Description : This shows the complete colour chart.

Click on the colour you want and it will copy the r,g,b ready for you to paste into your code.

There's a delay 50 in the main loop to free up processor time so you should be able to keep this open the whole time (or as long as you need it at least)

I realised I created the original of this 29-Jan-2003... Quite a while ago now! So I suppose it's due for the 18-May-2004 update!


Code :
Code: BlitzBasic
  1. ; http://www.mentalillusion.co.uk
  2. ;
  3. ; Click on a colour and it will copy to the clipboard,
  4. ; Thanks For JimB For the clipboard Decl And functions
  5. ;
  6. ;
  7. ; There's a delay 50 in the main loop to free up processor time, this means you should be able to run
  8. ; other stuff at the same time as this without slowdown. Blitz hogs all the processor otherwise.
  9.  
  10.  
  11.  
  12. ; Clipboard Text Read / Write
  13. ; ===========================
  14. ; Syntax Error & Ed from Mars
  15. ; userlib declarations - 'user32.decls'
  16. ; *********************************************
  17. ; .lib "user32.dll"
  18. ; OpenClipboard%(hwnd%):"OpenClipboard"
  19. ; CloseClipboard%():"CloseClipboard"
  20. ; ExamineClipboard%(format%):"IsClipboardFormatAvailable"
  21. ; EmptyClipboard%():"EmptyClipboard"
  22. ; GetClipboardData$(format%):"GetClipboardData"
  23. ; SetClipboardData%(format%,txt$):"SetClipboardData"
  24. ; *********************************************
  25.  
  26.  
  27.  
  28.  
  29. AppTitle "Colour Picker"
  30. Graphics 256,270,32,2
  31.  
  32. SetBuffer BackBuffer()
  33.  
  34.  
  35. Dim colour(1536,3)
  36. For n=0 To 255
  37.         colour(n,1)=255
  38.         colour(n,2)=n
  39.         colour(n,3)=0
  40.         colour(n+256,1)=255-n
  41.         colour(n+256,2)=255
  42.         colour(n+256,3)=n
  43.         colour(n+512,1)=0
  44.         colour(n+512,2)=255-n
  45.         colour(n+512,3)=255
  46.         colour(n+768,1)=n
  47.         colour(n+768,2)=0
  48.         colour(n+768,3)=255-n
  49.         colour(n+1024,1)=colour(n,1)
  50.         colour(n+1024,2)=colour(n,2)
  51.         colour(n+1024,3)=colour(n,3)
  52.         colour(n+1280,1)=colour(n+256,1)
  53.         colour(n+1280,2)=colour(n+256,2)
  54.         colour(n+1280,3)=colour(n+256,3)
  55. Next
  56.  
  57.  
  58. colourchart=CreateImage (256,256)
  59. LockBuffer ImageBuffer(colourchart)
  60.  
  61. For y=0 To 255 Step 2
  62.         For x=0 To 1023 Step 4
  63.                 yy#=Float(y)/255
  64.                 r=colour(x,1)*yy
  65.                 g=Colour(x,2)*yy
  66.                 b=Colour(x,3)*yy
  67.                 writergb(colourchart,x/4,y/2,r,g,b)
  68.                 r=255-(colour(x+512,1)*yy)
  69.                 g=255-(Colour(x+512,2)*yy)
  70.                 b=255-(Colour(x+512,3)*yy)
  71.                 writergb(colourchart,x/4,255-(y/2),r,g,b)
  72.         Next
  73. Next
  74.  
  75. UnlockBuffer ImageBuffer(colourchart)
  76.  
  77.  
  78. Repeat
  79.  
  80.         DrawBlock colourchart,0,0
  81.        
  82.         LockBuffer BackBuffer()
  83.                 argb=ReadPixelFast(MouseX(),MouseY(),BackBuffer())
  84.                 r = (ARGB Shr 16) And $ff
  85.                 g = (ARGB Shr 8) And $ff
  86.                 b = ARGB And $ff
  87.                
  88.                 WritePixelFast (MouseX()-2,MouseY(),0,BackBuffer())
  89.                 WritePixelFast (MouseX()+2,MouseY(),0,BackBuffer())
  90.                 WritePixelFast (MouseX(),MouseY()-2,0,BackBuffer())
  91.                 WritePixelFast (MouseX(),MouseY()+2,0,BackBuffer())
  92.                
  93.                 WritePixelFast (MouseX()-1,MouseY()-1,0,BackBuffer())
  94.                 WritePixelFast (MouseX()-1,MouseY()+1,0,BackBuffer())
  95.                 WritePixelFast (MouseX()+1,MouseY()-1,0,BackBuffer())
  96.                 WritePixelFast (MouseX()+1,MouseY()+1,0,BackBuffer())
  97.         UnlockBuffer BackBuffer()
  98.        
  99.         Color r,g,b
  100.         Rect 0,256,256,14
  101.                
  102.         Color 255-r,255-g,255-b
  103.         Text 128,263,"R:"+r+" G:"+g+" B:"+b,True,True
  104.  
  105.        
  106.         If MouseHit(1)=True Then WriteClipboardText "color "+r+","+g+","+b
  107.         Delay 50
  108.         Flip
  109. Until KeyHit(1)
  110.  
  111. Function WriteClipboardText(txt$)
  112.         Local cb_TEXT=1
  113.         If txt$="" Then Return
  114.         If OpenClipboard(0)
  115.                 EmptyClipboard
  116.                 SetClipboardData cb_TEXT,txt$
  117.                 CloseClipboard
  118.         EndIf
  119. End Function
  120.  
  121. Function writergb(image_name,x,y,red,green,blue)
  122.         argb=blue + (green Shl 8) + (red Shl 16); + ($ff000000)
  123.         WritePixelFast x,y,argb,ImageBuffer(image_name)
  124. End Function


Comments :


Rob Farley(Posted 1+ years ago)

 Note: This now is pretty pointless as the debug log doesn't work like it used to... Could be handy though... maybe!


Perturbatio(Posted 1+ years ago)

 works fine if you change it to windowed mode instead of full screen.


Floyd(Posted 1+ years ago)

 ... or put a Stop command at the end.


Bremer(Posted 1+ years ago)

 You could have it save the colors in a text file as data statements or something like that.


Rob Farley(Posted 1+ years ago)

 Updated... I think it's quite useful now!


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal