Since size is changing for every Tessellation function call I think you
have to do that.

 

Best,

Scuri

 

From: Victor Bombi [mailto:[email protected]] 
Sent: terça-feira, 14 de janeiro de 2014 13:03
To: IUP discussion list.
Subject: Re: [Iup-users] teselation sample

 

Yes, I will try OpenGL but it is much more complicated than pure CD canvas.

I would have like to know if I was using things correctly with so much image
and canvas creation and killing?

I tried to do all that only with IM but I coud not find how to clip to
triangular shape.

I was also intrigued by server images.

 

Best

victor

----- Original Message ----- 

From: Antonio Scuri <mailto:[email protected]>  

To: IUP discussion list. <mailto:[email protected]>  

Sent: Tuesday, January 14, 2014 1:40 AM

Subject: Re: [Iup-users] teselation sample

 

  Fantastic sample! Just added to the IM samples. 

 

  If you need graphics speed I suggest you do use OpenGL:

 

http://luagl.sourceforge.net/

 

Thanks,

Scuri

 

 

On Mon, Jan 13, 2014 at 8:36 PM, Victor Bombi <[email protected]> wrote:

Hello,

this is a sample i have made for testing cdCanvas and image.
You only have to set the path for your image file.

I am mailing this for two reasons:
1- I would like to have a sample like this one for learning some im and cd
functions that were not in the examples folder
2- I would like to know if something could be done better (a faster
alternative...)

-------------------------------------Sample begins
require"imlua"
require"cdlua"
require"cdluaim"
require"iuplua"
require"iupluacd"
require"imlua_process"

filename =
[[C:\LUA\im-3.8.2_Win32_dllw4_lib\im-3.8.2_Examples\im\html\examples\flower.
jpg]]
 --set your file

anchosc = 500 -- window width
heightfac=math.sqrt(3)*0.5;

image=im.FileImageLoad(filename)
cnv = iup.canvas{rastersize =  anchosc .."x".. anchosc*heightfac, border =
"NO"}

function cnv:map_cb()       -- the CD canvas can only be created when the
IUP canvas is mapped
  self.canvas = cd.CreateCanvas(cd.IUP, self)
  self.canvas:Background(cd.BLACK)
end

mouseX,mouseY=0,0
nostatus=(" "):rep(10)
function cnv:motion_cb(x,y,status)
 if status == nostatus then
  mouseX = x
  mouseY = y
  iup.Update(cnv)
 end
end

function EQTriangle(can,len,mode)
 mode = mode or cd.FILL
 can:Begin(mode)
 can:Vertex(0,0)
 can:Vertex(len,0)
 can:Vertex(len*0.5,0.5*len*math.sqrt(3))
 can:End()
end

function clip(val,mini,maxi)
 return math.max(mini,math.min(val,maxi))
end
function linearmap(v,s,e,ds,de)
 return ((de-ds)*(v-s)/(e-s)) + ds
end
function imResize(im1,w,h)
 local im2 = im.ImageCreateBased(im1,w,h)
 im.ProcessResize(im1,im2,3)
 return im2
end
function MaskTriang(img,size)
 local im2 = img:Clone()
 im2:AddAlpha()
 local imcv = im2:cdCreateCanvas()
 EQTriangle(imcv,size,cd.CLIP)
 imcv:Clip(cd.CLIPPOLYGON)
 img:cdCanvasPutImageRect(imcv, 0, 0, 0, 0, 0, 0, 0, 0)
 imcv:Kill()
 return im2
end
function Teselate(img,size)
 local im2 = im.ImageCreateBased(img,size*2,size*2)
 local imcv = im2:cdCreateCanvas()
 --local ident = imcv:GetTransform()
 --print("imcv:GetTransformation",imcv.GetTransform,ident)
 img:cdCanvasPutImageRect(imcv, 0, 0, 0, 0, 0, 0, 0, 0)

 imcv:TransformTranslate(1.5*size, size*0.5*math.sqrt(3))
 imcv:TransformRotate(120)
 img:cdCanvasPutImageRect(imcv, 0, 0, 0, 0, 0, 0, 0, 0)

 imcv:Transform({1,0,0,1,0,0}) --reset identity
 imcv:TransformTranslate(1.5*size, size*0.5*math.sqrt(3))
 imcv:TransformRotate(-120)
 img:cdCanvasPutImageRect(imcv, 0, 0, 0, 0, 0, 0, 0, 0)

 imcv:TransformScale(1,-1)
 img:cdCanvasPutImageRect(imcv, 0, 0, 0, 0, 0, 0, 0, 0)

 imcv:Kill()
 img:Destroy()
 return im2
end
function EndTeselate(img,size)
 local im2 = im.ImageCreateBased(img,size*2,size*2)
 local imcv = im2:cdCreateCanvas()

 img:cdCanvasPutImageRect(imcv, 0, 0, 0, 0, 0, 0, 0, 0)

 imcv:TransformTranslate(1.5*size, size*0.5*math.sqrt(3))
 imcv:TransformRotate(-120)
 imcv:TransformScale(1,-1)
 img:cdCanvasPutImageRect(imcv, 0, 0, 0, 0, 0, 0, 0, 0)

 imcv:Transform({1,0,0,1,0,0}) --reset identity
 imcv:TransformRotate(120)
 imcv:TransformScale(1,-1)
 img:cdCanvasPutImageRect(imcv, 0, 0, 0, 0, 0, 0, 0, 0)

 imcv:Kill()
 img:Destroy()
 return im2
end

function cnv:action()

 local width = anchosc
 local lado = clip(mouseX,10,width)

 self.canvas:Activate()

 local size = lado
 local imm = imResize(image,size,size)
 local im2 = MaskTriang(imm,size)
 while size < width do
  im2 = Teselate(im2,size)
  size = size * 2
 end
 im2 = EndTeselate(im2,size)
 im2:cdCanvasPutImageRect(self.canvas, 0, 0, 0, 0, 0, 0, 0, 0)

 imm:Destroy()
 im2:Destroy()
end

dlg = iup.dialog{cnv}

function dlg:close_cb()
  image:Destroy()
  cnv.canvas:Kill()
  self:destroy()
  return iup.IGNORE -- because we destroy the dialog
end

dlg:show()
iup.MainLoop()
-------------------------Sample ends

Best Regards
victor bombi



----------------------------------------------------------------------------
--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431
<http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktr
k> &iu=/4140/ostg.clktrk
_______________________________________________
Iup-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/iup-users

 

  _____  

----------------------------------------------------------------------------
--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431
<http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktr
k> &iu=/4140/ostg.clktrk 

  _____  

_______________________________________________
Iup-users mailing list
 <mailto:[email protected]> [email protected]
 <https://lists.sourceforge.net/lists/listinfo/iup-users>
https://lists.sourceforge.net/lists/listinfo/iup-users

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Iup-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/iup-users

Reply via email to