Flip Horizontal, Flip Vertical & Free Rotate

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Flip Horizontal, Flip Vertical & Free Rotate

Post 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
Last edited by RASHAD on Mon Jan 30, 2017 12:59 pm, edited 3 times in total.
Egypt my love
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Flip Horizontal, Flip Vertical & Free Rotate

Post by RSBasic »

Image
Image
Image
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Flip Horizontal, Flip Vertical & Free Rotate

Post by walbus »

Image
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

Re: Flip Horizontal, Flip Vertical & Free Rotate

Post by chi »

To avoid the blur in the flipped images:

Code: Select all

ResetCoordinates(#PB_Coordinate_Source)
Et cetera is my worst enemy
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Flip Horizontal, Flip Vertical & Free Rotate

Post by davido »

Nice demo, thanks RASHAD.
DE AA EB
dige
Addict
Addict
Posts: 1409
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: Flip Horizontal, Flip Vertical & Free Rotate

Post by dige »

Very useful. Thank you!
"Daddy, I'll run faster, then it is not so far..."
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Flip Horizontal, Flip Vertical & Free Rotate

Post by RASHAD »

@RSBasic
You are doing a very good organized job
Thanks

@walbus,@chi,@davido and @dige
Thanks guys
Much appreciated
Egypt my love
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2139
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Flip Horizontal, Flip Vertical & Free Rotate

Post by Andre »

@RASHAD: very cool, thanks a lot! :D

@chi: I don't see any blur!?
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Flip Horizontal, Flip Vertical & Free Rotate

Post by RASHAD »

Hi Andre
Keep the good work
Thanks
Egypt my love
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Flip Horizontal, Flip Vertical & Free Rotate

Post by Kwai chang caine »

Works great
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

Re: Flip Horizontal, Flip Vertical & Free Rotate

Post by chi »

@Andre: But I do ;)
Image
Et cetera is my worst enemy
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Flip Horizontal, Flip Vertical & Free Rotate

Post by IdeasVacuum »

These functions are such a commonplace requirement - I think they should be built into the lib.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply