Page Turn Effect?

Just starting out? Need help? Post your questions and find answers here.
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 »

ebs wrote:
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:
Thanks for the code patch ebs. Whenever I get the time, I'll have to look more into those keyboard shortcuts.
IdeasVacuum wrote:
the Wal-Mart character. #WM_CHAR
So that's what it is! :mrgreen:
You know I was just ranting. Maybe it's the Windows® Meta character or some such.

Now that I see it in Linux, once again Michael, thanks for the great code.
Especially your RandomLine() function implementation, which I like maybe a bit more than my proposed GarbageText() function.
Perhaps one of us could merge the two ideas and post it into the "appropriate place". :wink: :lol:
Keep it BASIC.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: Page Turn Effect?

Post by falsam »

@Michael Vogel : NIce code. thanks for sharing.

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
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 »

Still coding very rude (Windows only, no constants nor enumeration etc.) - I've just done to test some effects now, so real coding can be done by someone else :wink:

So this iteration just show a more realistic page turning on the right side of the booklet only (to be able to compare both effect types):

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 Create99(n,x)

	Protected i,f
	If x
		CopyImage(n,99)
		ResizeImage(99,x,#Y)
		For i=0 To x
			GrabImage(99,100+i,i,0,1,#Y)
		Next i

		StartDrawing(ImageOutput(99))
		For i=0 To x
			f=MulDiv_(i,(#x-x),#X)
			DrawImage(ImageID(100+i),i,-f,1,#Y+f+f)
		Next i
		StopDrawing()
	EndIf

EndProcedure
Procedure Page(p)

	Protected i,j
	Protected x

	#Z=10

	For i=1 To #Z
		x=MulDiv_(#X,i,#Z)
		Create99(p+1,#X-x)
		StartDrawing(CanvasOutput(0))
		DrawImage(ImageID(p+3),#X,0)
		If i<#Z
			DrawImage(ImageID(99),#X,0)
			DrawingMode(#PB_2DDrawing_AlphaBlend)
			For j=0 To MulDiv_(#X-x,63,#X)
				LineXY(#X+#X-x+j,0,#X+#X-x+j,#Y,(63-j)<<24)
			Next j
			DrawingMode(#PB_2DDrawing_Default)
		EndIf
		StopDrawing()
		Delay(5)
	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)
	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)
	AddKeyboardShortcut(0,#PB_Shortcut_Space,1)

	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 #PB_Event_Menu
			Page(p)
			If p<17
				p+2
			Else
				p=1
			EndIf
		Case #PB_Event_CloseWindow
			End
		EndSelect
	ForEver
EndProcedure

Main()
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Page Turn Effect?

Post by Kwai chang caine »

Really splendid !!! :shock:
Never i believe, it's possible to do a so nice effect, with a so little line number of code
Thanks a lot for sharing 8)
ImageThe happiness is a road...
Not a destination
User avatar
BasicallyPure
Enthusiast
Enthusiast
Posts: 539
Joined: Thu Mar 24, 2011 12:40 am
Location: Iowa, USA

Re: Page Turn Effect?

Post by BasicallyPure »

Michael Vogel,
Here it is using your first method.
I have added the ability to page forward and backward, just use the
left and right arrow keys.
I would have used your second method but it was too difficult for me. :)

Just for fun I added an old random word procedure that I had.

Made it cross platform too.
Tested with Windows and Linux.

Code: Select all

EnableExplicit

#X = 400
#Y = 600
#Z = 15 ; speed

Declare.s MakeWord(Mode = 0, WordLength = 0)
Declare.s RandomLine()
Declare.i Init()
Declare.i PageForward(p)
Declare.i PageBackward(p)
Declare.i Main()

If Init()
   Main()
EndIf

End

Procedure Main()
   Protected p = 1

   Repeat
      Select WaitWindowEvent()
         Case #PB_Event_Menu
            Select EventMenu()
               Case 1 ; go forward
                  If p < 19 : p + 2 : PageForward(p)  : EndIf
               Case 2 ; go backward
                  If p > 01 : p - 2 : PageBackward(p) : EndIf
            EndSelect
            
         Case #PB_Event_CloseWindow
            End
      EndSelect
   ForEver
EndProcedure

Procedure PageForward(p)
   Protected i,j,x

   For i = 1 To #Z ; do right page
      x = (#X*i) / #Z
      StartDrawing(CanvasOutput(0))
         DrawImage(ImageID(p+1),#X,0) ; right complete
         DrawImage(ImageID(p-1),#X,0,#X-x,#Y) ; right turning
      StopDrawing()
      Delay(25)
   Next i
   
   For i = 1 To #Z ; do left page
      x = (#X*i) / #Z
      StartDrawing(CanvasOutput(0))
         ;DrawImage(ImageID(p-2),0,0) ; left complete
         DrawImage(ImageID(p),#X-x,0,x,#Y) ; left turning
      StopDrawing()
      Delay(25)
   Next i
   
EndProcedure

Procedure PageBackward(p)
   Protected i,j,x

   For i = 1 To #Z ; do left page
      x = #X*i / #Z
      StartDrawing(CanvasOutput(0))
         DrawImage(ImageID(p),0,0) ; left complete
         DrawImage(ImageID(p+2),x,0,#X-x,#Y) ; left turning
      StopDrawing()
      Delay(25)
   Next i
   
   For i = 1 To #Z ; do right page
      x = (#X*i) / #Z
      StartDrawing(CanvasOutput(0))
         ;DrawImage(ImageID(p+3),#X,0) ; right complete
         DrawImage(ImageID(p+1),#X,0,x,#Y) ; right turning
      StopDrawing()
      Delay(25)
   Next i

EndProcedure

Procedure Init()
   
   Protected i,j,x,m,n,c,result
   Protected s.s
   
   result = OpenWindow(0,0,0,#X+#X,#Y,"Page flip effect")
   
   If result
      CanvasGadget(0,0,0,#X+#X,#Y)
      
      AddKeyboardShortcut(0,#PB_Shortcut_Right,1)
      AddKeyboardShortcut(0,#PB_Shortcut_Left,2)
      
      LoadFont(0,"Courier New", 10)
      
      For i=1 To 20
         CreateImage(i,#X,#Y)
         StartDrawing(ImageOutput(i))
            DrawingFont(FontID(0))
            Box(0,0,#X,#Y,$FFFFFF)
            
            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(),0,$FFFFFF)
            Next j
            
            s=Str(i)
            If i&1
               x=10
            Else
               x=#X-10-TextWidth(s)
            EndIf
            DrawText(x,#Y-20,Str(i),$0000FF,$FFFFFF)
         StopDrawing()
      Next i
      
      StartDrawing(CanvasOutput(0))
         DrawImage(ImageID(1),0,0)
         DrawImage(ImageID(2),#X,0)
      StopDrawing()
   EndIf
   
   ProcedureReturn result
EndProcedure

Procedure.s RandomLine()
   Static wc
   Protected result.s = MakeWord(Bool(wc = 0)) : wc + 1
   
   While Len(result) < 35
      If wc > 3 And Random(4) = 0
         If Random(1) And wc < 8 : result + "," : wc = 3
         Else : result + ". " : wc = 0
         EndIf
      Else
         result + " " + MakeWord(Bool(wc = 0)) : wc + 1
      EndIf
   Wend
   
   ProcedureReturn result
EndProcedure

Procedure.s MakeWord(Mode = 0, WordLength = 0)
   ; procedure returns a randomly constructed word
   ; mode = 0 --- all lower case (default)
   ; mode = 1 --- first letter is upper case
   ; mode = 2 --- all upper case
   ; if WordLength = 0 (default) then word length is random 3 to 10
   
   Protected vcFlag.i, LL$, NL$, word$
   Static cc    ; the number of available consonants
   Static sc    ; the number of special consonants
   Static vc    ; the number of available vowels
   Static sv    ; the number of special vowels
   Static sb    ; the number of special beginnings
   Static con$  ; stores all of the available consonants
   Static vow$  ; stores all of the available vowels
   Static beg$  ; stores all special beginnings consonants
   Static init = #True
   
   Macro GetData(dataBlock, counterVariable, storageString)
      Restore dataBlock
      Read.s LL$
      While LL$
         counterVariable + 1
         storageString + LL$
         Read.s LL$
      Wend
   EndMacro
   
   If init ; do this only once
      ; count and store all the consonants and vowels
      GetData(consonants, cc, con$)
      GetData(specialConsonants, sc, con$)
      cc + sc - 1
      GetData(vowels, vc, vow$)
      GetData(specialVowels, sv, vow$)
      vc + sv - 1
      GetData(specialBeginnings, sb, beg$)
      sb - 1
      init = #False
   EndIf
   
   If WordLength < 1
      WordLength = 3 + Random(3) + Random(2) + Random(2)
   EndIf
   
   If Random(10) > 2 ; make first letter a consonant
      If Not Random(10) ; use a special beginning
         word$ = RTrim(Mid(beg$, 1 + Random(sb) << 1, 2))
      Else
         word$ = RTrim(Mid(con$, 1 + Random(cc - sc) << 1, 2))
      EndIf
      vcFlag = #False
   Else ; make first letter a vowel
      word$ = RTrim(Mid(vow$, 1 + Random(vc - sv) << 1, 2))
      vcFlag = #True 
   EndIf
   
   LL$ = Right(word$,1)
   
   While Len(word$) < WordLength ; choose the remaining letters
      Repeat
         Repeat
            If vcFlag ; last was vowel so add a consonant
               NL$ = RTrim(Mid(con$, 1 + Random(cc) << 1, 2))
            Else ; last was consonant so add a vowel
               NL$ = RTrim(Mid(vow$, 1 + Random(vc) << 1, 2))
            EndIf
         Until NL$ <> LL$
      Until Len(word$) + Len(NL$) <= WordLength
      word$ + NL$ : LL$ = Right(NL$,1) : vcFlag ! 1
   Wend
   
   Select mode
      Case 0 ; default all lower case
         ; do nothing
      Case 1 ; make first letter upercase
         word$ = UCase(Left(word$,1)) + Right(word$,Len(word$)-1)
      Case 2 ; make all letters uppercase
         word$ = UCase(word$)
   EndSelect

   ProcedureReturn word$
   
   DataSection
      specialBeginnings: ; only used at word beginnings
      Data.s "bl","br","cl","cr","dr","fl","fr","gr","kl","kr","pl","pr","qu","sl","sm"
      Data.s "sn","sp","sw"
      Data.s ""
      
      consonants:
      Data.s "b ","b ","c ","c ","c ","c ","d ","d ","d ","d ","d ","d ","f ","f ","f "
      Data.s "g ","g ","g ","h ","h ","h ","h ","h ","h ","h ","h ","j ","j ","k ","l "
      Data.s "l ","l ","l ","l ","m ","m ","m ","n ","n ","n ","n ","n ","n ","n ","n "
      Data.s "n ","p ","p ","p ","r ","r ","r ","r ","r ","r ","r ","r ","s ","s ","s "
      Data.s "s ","s ","s ","s ","s ","s ","t ","t ","t ","t ","t ","t ","t ","t ","t "
      Data.s "t ","t ","t ","v ","w ","w ","w ","x ","x ","y ","y ","y ","z ","ch","th"
      Data.s "sh","st","sk","sp","tr","ph"
      Data.s ""
      
      specialConsonants: ; never used at begining of words
      Data.s "ng","nt","rk","nd","ck","ds","ks","rt","nk","bb","gg","ll","nn","ss"
      Data.s ""
      
      vowels:
      Data.s "a ","a ","a ","e ","e ","e ","e ","e ","i ","i ","i "
      Data.s "o ","o ","o ","u ","a ","a ","a ","e ","e ","e ","e "
      Data.s "e ","i ","i ","i ","o ","o ","o ","u "
      Data.s ""
      
      specialVowels: ; never used at beginning of words
      Data.s "oa","ea","ie","ia","ya","yo","oo","ee","y "
      Data.s ""
   EndDataSection

EndProcedure
Last edited by BasicallyPure on Sun Feb 15, 2015 6:42 pm, edited 3 times in total.
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: Page Turn Effect?

Post by jack »

with so many applauds I tried BasicallyPure version, I am disappointed, I thought it would be something like this http://www.turnjs.com
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 »

I don't know what the hell you are doing with the text BasicallyPure...

but I like it. :wink:

I was just reading it out loud. A variant of Simlish perhaps? Or maybe a bit closer to Furbish?
Keep it BASIC.
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: Page Turn Effect?

Post by jack »

heartbone, I am talking about the example by BasicallyPure, code just above, don't know neither do I care to know what Simlish or Furbish is.
User avatar
BasicallyPure
Enthusiast
Enthusiast
Posts: 539
Joined: Thu Mar 24, 2011 12:40 am
Location: Iowa, USA

Re: Page Turn Effect?

Post by BasicallyPure »

heartbone wrote:I don't know what the hell you are doing with the text BasicallyPure...but I like it.
Then you man enjoy this also. :P
It's a procedure that I pulled from this larger program.
Name The Baby

Follow the audio links there to see what it sounds like when it is input to a text to speech program.
It's a real hoot!
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.
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 »

You are right, I really liked that Jibber Jabber.
It seemed so smooth and natural.
I can relate to that speech much more than anything coming out of our government representatives in Washington DC.
Hopefully I'll find some reason to use some of that audio sometime in the future, unless that's a problem.
jack wrote:with so many applauds I tried BasicallyPure version, I am disappointed, I thought it would be something like this http://www.turnjs.com
jack wrote:heartbone, I am talking about the example by BasicallyPure, code just above, don't know neither do I care to know what Simlish or Furbish is.
Hi jack. Did you see Michael Vogel's updated version above? He made substantial changes.

That is one impressive page that you linked to, with Steve Jobs face on it and all.
turn.js
Make a flip book with HTML5
Works on most browsers and devices
Simple and clean API
Lightweight, 10K
That 10K part really caught my eye!
I was deceived into clicking the download button.
WTF a 20.4 MB??? :?: !!! :!: :evil: download.
I did not bother looking inside the zip before putting it where it belonged.

BasicallyPure's code compiles to a 69K executable, before zipping, and 33.3KB after WinZip's default compression is applied.
If you have the balls to post that you are "disappointed", I'm surely hoping that you will show us some better code, right?

The more that I think about this, the more it seems to be a natural for a Pure/SpiderBasic community project.
Come up with a easy way to transfer the contents of most types of books into a standard data format.
The contents can then be presented in a book fashion using a (PureBasic for the .exe and SpiderBasic for the browser) user customizable display utility which will support whatever you can agree to add to the PB community standard book data format.
If the standard and display could handle the page layout of 90% of the typical books, it would be good.
I'd consider initially encoding for a variety of targets such as a Kindergarten book, a few novels. a comic book, a simple tech manual, a coffee table book, single page pamphlet, a middle school text book, a repair manual, a simple brochure, and a religious book.

After the base release, upgrades should be continually under consideration and the best ideas should make it into the base build.

So far I see a need to have some database and scanning (+OCR) software in addition to the compilers.
What else?
Keep it BASIC.
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 »

Graphically, I'm thinking to allow PNG, JPEG and the practically unused APNG (and/or the related MNG) formats only.
I'm all for a severe size/time time restriction on the animated files to stop any attempts to include any version of video.
Not trying to replicate a wikipædia document either, audio is verboten.
Most books will end up rather small.
I'd probably do my high school senior yearbook, an edition so old it's before any crazy crap about IP rights.

However, entities should be able to feel comfortable issuing for profit (read DRM) books in the format with no problem.

If the PBX book player could handle other common formats like ODT and PDF it would be a positive.

I almost forgot that there'd need to be some sort of SVG format support in the PBX files.
The content creation aspects of the book player can not be overlooked, and some book makers would expect no less than scalable vector graphics.
Keep it BASIC.
User avatar
JHPJHP
Addict
Addict
Posts: 2257
Joined: Sat Oct 09, 2010 3:47 am

Re: Page Turn Effect?

Post by JHPJHP »

I've expanded on my original example, trying put the idea of shrinking and expanding pages to good use (thank you Michael Vogel).
- Comic Book / Magnifying Glass

NB*: The download is over 40 MB due to the included database of comic images.

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
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 »

I was able to run your Comic Book code on Linux after replacing the color constants.
I also share interest in this functionality.
It sure looks like you are taking the lead.
Are you planning to continue expand your implementation?
And if so, would you be interested in reviewing a possible design suggestion?
I'm hoping that there be something in it that you might like.
I wanted to check out the Magnifying Glass implementation, but that will have to wait until I log in to Windows®.
Keep it BASIC.
User avatar
JHPJHP
Addict
Addict
Posts: 2257
Joined: Sat Oct 09, 2010 3:47 am

Re: Page Turn Effect?

Post by JHPJHP »

Hi heartbone,

I won't be expanding this implementation any further. It has been pointed out some of the inherent problems I'd face pursuing this method, which I found to have merit. It was also suggested that Sprites would prove more reliable, the direction I'd take if I were to continue.

Take a look at my post Embed JS Framework into PureBasic.
- TurnJS_Create.pb, TurnJS_Double.pb

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

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Post Reply