Page Turn Effect?

Just starting out? Need help? Post your questions and find answers here.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Page Turn Effect?

Post by IdeasVacuum »

I would like to have a 'page turn' effect in my app -each 'page' will be a single window with image and text gadgets loaded when the page is 'turned'. If you have ever used Lotus Organizer, you will know what I mean.

Here is a similar sort of thing on line: library_events
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Michael Vogel
Addict
Addict
Posts: 2806
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Page Turn Effect?

Post by Michael Vogel »

Not sure, how perfect you want to simulate the paper turning, but a quick approach could be something like this...

Code: Select all

#X=400
#Y=600

Procedure.s RandomLine()

	Protected s.s
	Protected i,c

	c='A'
	For i=1 To 40
		s=s+Chr(c+Random(25))
		If c<'a'
			c='a'
		ElseIf Random(10)=0
			Select Random(10)
			Case 0
				s+". "
				c='A'
			Case 1
				s+" "
				c='A'
			Default
				s+" "
			EndSelect
		EndIf
	Next i

	ProcedureReturn s

EndProcedure
Procedure Page(p)

	Protected i,j
	Protected x

	#Z=10

	For i=1 To #Z
		x=MulDiv_(#X,i,#Z)
		StartDrawing(CanvasOutput(0))
		DrawImage(ImageID(p+3),#X,0)
		DrawImage(ImageID(p+1),#X,0,#X-x,#Y)
		StopDrawing()
		Delay(20)
	Next i
	For i=1 To #Z
		x=MulDiv_(#X,i,#Z)
		StartDrawing(CanvasOutput(0))
		DrawImage(ImageID(p),0,0)
		DrawImage(ImageID(p+2),#X-x,0,x,#Y)
		StopDrawing()
		Delay(20)
	Next i

EndProcedure
Procedure Init()

	Protected i,j,x,m,n,c
	Protected s.s

	OpenWindow(0,0,0,#X+#X,#Y,"")
	CanvasGadget(0,0,0,#X+#X,#Y)

	For i=1 To 20
		CreateImage(i,#X,#Y)
		StartDrawing(ImageOutput(i))
		Box(0,0,#X,#Y,#White)
		
		If i&1
			m=#X
			n=-1
		Else
			m=0
			n=1
		EndIf
		
		For j=0 To 15
			c=$10101*j*8+$808080
			LineXY(m,0,m,#Y,c)
			m+n
		Next j
		
		For j=1 To 28
			DrawText(24,20*j,RandomLine(),#Black,#White)
		Next j

		s=Str(i)
		If i&1
			x=10
		Else
			x=#X-10-TextWidth(s)
		EndIf
		DrawText(x,#Y-20,Str(i),#Red,#White)
		StopDrawing()
	Next i

	StartDrawing(CanvasOutput(0))
	DrawImage(ImageID(1),0,0)
	DrawImage(ImageID(2),#X,0)
	StopDrawing()

EndProcedure

Procedure Main()

	Init()

	p=1

	Repeat
		Select WaitWindowEvent()
		Case #WM_CHAR
			Page(p)
			If p<17
				p+2
			Else
				p=1
			EndIf
		Case #PB_Event_CloseWindow
			End
		EndSelect
	ForEver
EndProcedure

Main()
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 544
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: Page Turn Effect?

Post by bbanelli »

Michael Vogel wrote:Not sure, how perfect you want to simulate the paper turning, but a quick approach could be something like this...
I rarely have the need to barge in to a thread like this, but this is absolutely brilliant!
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Page Turn Effect?

Post by IdeasVacuum »

Wow! That is just excellent, thank you Michael.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: Page Turn Effect?

Post by heartbone »

Very cool code Michael Vogel. 8)
But on Windows® only. :(
Keep it BASIC.
ebs
Enthusiast
Enthusiast
Posts: 561
Joined: Fri Apr 25, 2003 11:08 pm

Re: Page Turn Effect?

Post by ebs »

heartbone wrote:But on Windows® only. :(
Just substitute this:

Code: Select all

x=(#X*i)/#Z
for this:

Code: Select all

x=MulDiv_(#X,i,#Z)
and no more Windows only!

Brilliant code, by the way!

Regards,
Eric
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: Page Turn Effect?

Post by heartbone »

:lol: ebs, I'm sure that is true after those annoying color constants are defined or replaced.

No.. not quite, I'll still need to figure out the Wal-Mart character. #WM_CHAR
Keep it BASIC.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Page Turn Effect?

Post by IdeasVacuum »

the Wal-Mart character. #WM_CHAR
So that's what it is! :mrgreen:
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
ebs
Enthusiast
Enthusiast
Posts: 561
Joined: Fri Apr 25, 2003 11:08 pm

Re: Page Turn Effect?

Post by ebs »

heartbone wrote:No.. not quite, I'll still need to figure out the Wal-Mart character. #WM_CHAR
It just catches a keypress to turn the page. You can use a keyboard shortcut instead:

Code: Select all

Procedure Main()
  
  Init()
  
  p=1

  AddKeyboardShortcut(0, #PB_Shortcut_Space, 1)

  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Menu
        If EventMenu() = 1
          Page(p)
          If p<17
            p+2
          Else
            p=1
          EndIf
        EndIf
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndProcedure
User avatar
JHPJHP
Addict
Addict
Posts: 2257
Joined: Sat Oct 09, 2010 3:47 am

Re: Page Turn Effect?

Post by JHPJHP »

Hi IdeasVacuum,

Comic Book version based on Michael Vogel's page-turning effect:
- Comic Book / Magnifying Glass

Cheers!
Last edited by JHPJHP on Wed Feb 18, 2015 4:11 pm, edited 7 times in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Page Turn Effect?

Post by IdeasVacuum »

That is a thing of beauty JHPJHP 8)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Karellen
User
User
Posts: 83
Joined: Fri Aug 16, 2013 2:52 pm
Location: Germany

Re: Page Turn Effect?

Post by Karellen »

Nice one, Michael, thanks for sharing!
Also thanks to JHPJHP, nice example!
Stanley decided to go to the meeting room...
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Page Turn Effect?

Post by davido »

@Michael Vogel

Brilliant!
Thank you for sharing. :D
DE AA EB
User avatar
JHPJHP
Addict
Addict
Posts: 2257
Joined: Sat Oct 09, 2010 3:47 am

Re: Page Turn Effect?

Post by JHPJHP »

Thank you IdeasVacuum, Karellen,

Applied a small update after noticing a slight flicker.
- page turning now initiated by mouse click
- should now be cross-platform

NB*: Update also includes various other improvements.

Cheers!
Last edited by JHPJHP on Fri Feb 13, 2015 1:55 am, edited 3 times in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
mk-soft
Always Here
Always Here
Posts: 6244
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Page Turn Effect?

Post by mk-soft »

Very Nice :D

On Mac no effects without EventWindow...

Code: Select all

Procedure Page(p)

   Protected i,j
   Protected x

   #Z=10

   For i=1 To #Z
      x=MulDiv_(#X,i,#Z)
      StartDrawing(CanvasOutput(0))
      DrawImage(ImageID(p+3),#X,0)
      DrawImage(ImageID(p+1),#X,0,#X-x,#Y)
      StopDrawing()
      Delay(10)
      While WindowEvent() : Wend
   Next i
   For i=1 To #Z
      x=MulDiv_(#X,i,#Z)
      StartDrawing(CanvasOutput(0))
      DrawImage(ImageID(p),0,0)
      DrawImage(ImageID(p+2),#X-x,0,x,#Y)
      StopDrawing()
      Delay(10)
      While WindowEvent() : Wend
   Next i

EndProcedure
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply