Page 1 of 1

Flip Horizontal, Flip Vertical & Free Rotate

Posted: Tue Feb 09, 2016 4:28 pm
by RASHAD
Using the fantastic PB VectorDrawing library
Thanks team it is very close to Cairo and maybe more advanced
Cross platform(It should be)

Code: Select all

Procedure flipHal(img)
  ww = ImageWidth(img)
  hh = ImageHeight(img)
  fimg = CreateImage(#PB_Any,ww,hh,32)
  StartVectorDrawing(ImageVectorOutput(fimg))
  ResetCoordinates()
  MovePathCursor(ww,0)    
  FlipCoordinatesX(180)
  DrawVectorImage(ImageID(img), 255)
  StopVectorDrawing()
  ProcedureReturn fimg
EndProcedure

Procedure flipVal(img)
  ww = ImageWidth(img)
  hh = ImageHeight(img)
  fimg = CreateImage(#PB_Any,ww,hh,32)
  StartVectorDrawing(ImageVectorOutput(fimg))
  ResetCoordinates()
  MovePathCursor(0,hh)    
  FlipCoordinatesY(180)
  DrawVectorImage(ImageID(img), 255)
  StopVectorDrawing()
  ProcedureReturn fimg
EndProcedure

Procedure Rotimg(img,deg)
  ww = ImageWidth(img)
  hh = ImageHeight(img)
  ang.f = Radian(deg)
  nw = Abs(ww*Cos(ang)+hh*Sin(ang))
  nh = Abs(ww*Sin(ang)+hh*Cos(ang))  
  fimg = CreateImage(#PB_Any,nw,nh,32);,#PB_Image_Transparent)
  StartVectorDrawing(ImageVectorOutput(fimg))
  MovePathCursor(Abs(hh*Sin(ang)),0)    
  RotateCoordinates(0,0,deg)
  DrawVectorImage(ImageID(img), 255)
  StopVectorDrawing()
  ProcedureReturn fimg
EndProcedure

Procedure Rotate(img,deg)
  If deg <= 90
    fimg = Rotimg(0,deg)
  ElseIf deg > 90 And deg <= 180
    fimg = Rotimg(0,deg-90)
    fimg = Rotimg(fimg,90)
  ElseIf deg > 180 And deg <=270
    fimg = Rotimg(0,deg-180)
    fimg = Rotimg(fimg,90)
    fimg = Rotimg(fimg,90)
  Else
    fimg = Rotimg(0,deg-270)
    fimg = Rotimg(fimg,90)
    fimg = Rotimg(fimg,90)
    fimg = Rotimg(fimg,90)
  EndIf 
  ProcedureReturn fimg
EndProcedure

If OpenWindow(0, 0, 0, 400, 540, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ImageGadget(0, 10, 10, 380,70 ,0)
  ImageGadget(1, 10, 90, 380,70 ,0)
  ImageGadget(2, 10, 170, 380,70 ,0)
  ImageGadget(3, 10, 250, 380,280 ,0)
  
  LoadImage(0, #PB_Compiler_Home + "examples/Sources/Data/PureBasicLogo.bmp")
  SetGadgetState(0,ImageID(0))   
  
  fimg = flipHal(0)
  SetGadgetState(1,ImageID(fimg))
  
  fimg = flipVal(0)
  SetGadgetState(2,ImageID(fimg))
  
  fimg = Rotate(0,145)
  SetGadgetState(3,ImageID(fimg)) 
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
__________________________________________________
Code indented
09.02.2016
RSBasic

Re: Flip Horizontal, Flip Vertical & Free Rotate

Posted: Tue Feb 09, 2016 4:31 pm
by RSBasic
Image

Re: Flip Horizontal, Flip Vertical & Free Rotate

Posted: Tue Feb 09, 2016 6:23 pm
by walbus
Image

Re: Flip Horizontal, Flip Vertical & Free Rotate

Posted: Tue Feb 09, 2016 7:31 pm
by chi
To avoid the blur in the flipped images:

Code: Select all

ResetCoordinates(#PB_Coordinate_Source)

Re: Flip Horizontal, Flip Vertical & Free Rotate

Posted: Tue Feb 09, 2016 8:28 pm
by davido
Nice demo, thanks RASHAD.

Re: Flip Horizontal, Flip Vertical & Free Rotate

Posted: Wed Feb 10, 2016 7:44 am
by dige
Very useful. Thank you!

Re: Flip Horizontal, Flip Vertical & Free Rotate

Posted: Wed Feb 10, 2016 3:03 pm
by RASHAD
@RSBasic
You are doing a very good organized job
Thanks

@walbus,@chi,@davido and @dige
Thanks guys
Much appreciated

Re: Flip Horizontal, Flip Vertical & Free Rotate

Posted: Wed Feb 10, 2016 11:06 pm
by Andre
@RASHAD: very cool, thanks a lot! :D

@chi: I don't see any blur!?

Re: Flip Horizontal, Flip Vertical & Free Rotate

Posted: Thu Feb 11, 2016 6:23 am
by RASHAD
Hi Andre
Keep the good work
Thanks

Re: Flip Horizontal, Flip Vertical & Free Rotate

Posted: Thu Feb 11, 2016 2:20 pm
by Kwai chang caine
Works great
Thanks for sharing 8)

Re: Flip Horizontal, Flip Vertical & Free Rotate

Posted: Thu Feb 11, 2016 6:47 pm
by chi
@Andre: But I do ;)
Image

Re: Flip Horizontal, Flip Vertical & Free Rotate

Posted: Thu Feb 11, 2016 8:14 pm
by IdeasVacuum
These functions are such a commonplace requirement - I think they should be built into the lib.