News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
slicing images
Author Message
iGame3D
Moderator
***


Posts: 231
Group: Moderators
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #1
RE: slicing images

JohnMurga Wrote:
Off-screen would work transparently for all image types too, as they'd be converted to RGB.


RGBA I hope?
Else  every off screen render will produce a black background in the resulting image.

I was having some fun with this script, my old random square test, with the off screen drawing.
But you'll see there is always a black bacground. Need that alpha!


Code:
-- random squares drawn offscreen with murgaLua
-- modification of murgaLua/examples/new/offscreen.lua

math.randomseed(os.time())
-- these values will depend on the project
   offscreenHeight, offscreenWidth  = 320, 320

-- these values are used against copy() and are randomized later in this script.
   redrawHeight , redrawWidth  = 200, 200

-- counter values keep track of the color cycling on the random filled rects
   colorcounter, basecounter, counterStep, counterLimit = 0 ,1, 7, 255

-- if the quads are larger than the grid there will be overlap
   gridSize , quadSize = 8, 8  

function random_colorsquares()
-- cycle colors
    colorcounter = colorcounter + counterStep
    if colorcounter > counterLimit then colorcounter = counterStep end
    fltk.fl_color(basecounter + colorcounter)  
-- randomized quadsize
    local Rs = math.random(quadSize-15,quadSize)
    
-- distance from center on each side of the quad  
    local quadHalf = math.floor(Rs/2)
    
    -- find a Random Point in the buffer
    local Rx, Ry = math.random(1,offscreenHeight) ,  math.random(1,offscreenWidth)
    
    -- match x,y to a valid point based on grid size
    local Px = (math.floor((Rx+(quadSize/2))/gridSize)*gridSize)-1
    local Py = (math.floor((Ry+(quadSize/2))/gridSize)*gridSize)-1
    
    -- find the top left corner of the new quad
    local Left,Top = Px-quadHalf, Py-quadHalf
    -- draw the filled rectangle
    fltk.fl_rectf(Left , Top ,Rs,Rs)
end  

function offScreenDraw(w)
    collectgarbage()
    offScreenBuffer = murgaLua.createOffscreenBuffer(offscreenWidth , offscreenHeight)
    offScreenBuffer:startOffScreenDrawing()    
  -- On Linux we have to clear the buffer (not on Mac or Win32)
    fltk.fl_color(0)
  -- Linux will segfault unless we set the font before using fl_draw
     fltk.fl_font(fltk.FL_HELVETICA_BOLD,14)
     fltk.fl_draw("OffScreen Drawing",10,20)
  -- the offscreen bufffer is now ready for input on all platforms

  -- some random colored squares
     for i = 1 , 2048 do random_colorsquares() end
      
  -- randomized redraw height for fun
     local rH = math.random(redrawHeight,redrawHeight*4)
     local rW =  math.random(redrawWidth,redrawWidth*4)
  
  -- the offscreen buffer can be copied and resized
     imageData = offScreenBuffer:getOffScreenImage():copy(rH , rW)
  
  -- insert the offscreen buffer as image data of an object
     getOffScreen_Button:image(imageData)
    getOffScreen_Button:redraw()
  
-- end the off screen drawing
    offScreenBuffer:endOffScreenDrawing()
  
end
  
  do local object = fltk:Fl_Double_Window(210, 210, "OffScreen drawing");
    window = object;
    do getOffScreen_Button = fltk:Fl_Button(5, 5, 200, 200, "Get off screen image");
    end -- Fl_Button* getOffScreen
  end
  
  getOffScreen_Button:callback(offScreenDraw);
  getOffScreen_Button:when(9)
window:show();
Fl:run();



Attached File(s)
.lua File  offScreenSquares.lua (Size: 2.77 KB / Downloads: 2)
02-28-2008 03:41 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
slicing images - mikshaw - 01-26-2008, 06:28 AM
RE: slicing images - JohnMurga - 01-26-2008, 08:48 AM
RE: slicing images - mikshaw - 01-26-2008, 08:51 AM
RE: slicing images - JohnMurga - 01-27-2008, 06:38 AM
RE: slicing images - mikshaw - 01-27-2008, 07:26 AM
RE: slicing images - mikshaw - 02-25-2008, 05:49 AM
RE: slicing images - iGame3D - 02-25-2008, 08:08 AM
RE: slicing images - mikshaw - 02-25-2008, 12:22 PM
RE: slicing images - iGame3D - 02-25-2008, 07:15 PM
RE: slicing images - iGame3D - 02-25-2008, 07:31 PM
RE: slicing images - iGame3D - 02-25-2008, 08:15 PM
RE: slicing images - mikshaw - 02-25-2008, 10:26 PM
RE: slicing images - mikshaw - 02-26-2008, 04:47 AM
RE: slicing images - iGame3D - 02-26-2008, 06:22 AM
RE: slicing images - mikshaw - 02-26-2008, 10:41 PM
RE: slicing images - Juergen - 02-27-2008, 04:42 AM
RE: slicing images - iGame3D - 02-27-2008, 05:53 AM
RE: slicing images - iGame3D - 02-27-2008, 06:30 AM
RE: slicing images - mikshaw - 02-27-2008, 07:08 AM
RE: slicing images - mikshaw - 02-27-2008, 07:18 AM
RE: slicing images - iGame3D - 02-27-2008, 07:52 AM
RE: slicing images - JohnMurga - 02-27-2008, 08:04 AM
RE: slicing images - JohnMurga - 02-27-2008, 08:28 AM
RE: slicing images - mikshaw - 02-27-2008, 08:31 AM
RE: slicing images - Juergen - 02-27-2008, 09:41 AM
RE: slicing images - mikshaw - 02-27-2008, 12:40 PM
RE: slicing images - iGame3D - 02-27-2008, 03:04 PM
RE: slicing images - mikshaw - 02-27-2008, 11:51 PM
RE: slicing images - Juergen - 02-28-2008, 03:50 AM
RE: slicing images - iGame3D - 02-28-2008, 04:22 AM
RE: slicing images - Juergen - 02-28-2008, 04:30 AM
RE: slicing images - mikshaw - 02-28-2008, 04:55 AM
RE: slicing images - iGame3D - 02-28-2008, 07:23 AM
RE: slicing images - mikshaw - 02-28-2008, 08:04 AM
RE: slicing images - JohnMurga - 02-28-2008, 08:43 AM
RE: slicing images - iGame3D - 02-28-2008 03:41 PM
RE: slicing images - mikshaw - 02-28-2008, 07:29 PM
RE: slicing images - iGame3D - 02-29-2008, 05:29 AM
RE: slicing images - mikshaw - 02-29-2008, 05:42 AM
RE: slicing images - iGame3D - 02-29-2008, 04:16 PM
RE: slicing images - mikshaw - 02-29-2008, 11:36 PM
RE: slicing images - Juergen - 03-01-2008, 04:27 AM
RE: slicing images - mikshaw - 03-01-2008, 06:57 AM
RE: slicing images - mikshaw - 03-01-2008, 09:20 AM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: