Edit: This is the next iteration, i have made enough changes that I will cal the new iteration 3 see code below… the code after this code is version 2, its not labeled that though
-- Vertical Reader reads long strings and can scroll up and down
--[[ To use, type in
YourPageName = [[ yourstringhere ]]
--Iteration 3
--By Thomas Z.
ChapterTest = [[ This is a test page!
Testing third line!
Testing Fifth line!
End test!
]]
CurrentDoc = ChapterFour
function setup()
print("Hello World!")
font("AmericanTypewriter")
fontSize(20)
textWrapWidth(WIDTH/2)
textAlign(CENTER)
textMode(CORNER)
width, docHeight = textSize(CurrentDoc)
print( "ScreenHeight="..HEIGHT,
"DocHeight="..docHeight,
"PageCorner="..WIDTH/4,HEIGHT-docHeight)
CurrentPage = 1
numberOfPages = 1
pages = {}
if docHeight >1000 then
StandardPageHeight = 1000
CurrentPageHeight = StandardPageHeight
local numofpages = docHeight/CurrentPageHeight
numberOfPages = numofpages - numofpages%1
print("numberofpages="..numberOfPages)
--[[
WARNING: THIS PROGRAM IS UNABLE TO AUTOMATICALLY CALCULATE THE RESULTING HEIGHT OF A SUBSTRING
IF YOU CHANGE THE FONT, FONTSIZE, TEXTWRAPWIDTH, TEXTALIGN OR TEXTMODE
YOU MAY NEED TO CHANGE THE LENGTH OF THE SUBSTRING RENDERED (see j in string.sub(s,i,j)
ALSO NOTE: text() cannot render if the string height is over 1024 pixels...
i and j in string.sub(s, i, j) controls length of the substring.
use a range that under your preferred font does not exceed 1024 when
measured with textSize()
--]]
for i = 1, numberOfPages,1 do
table.insert(pages, string.sub(CurrentDoc, -500 + 500*i, 500*i))
end
else
table.insert(pages, CurrentDoc)
CurrentPageHeight = docHeight
end
print(pages[CurrentPage])
end
function draw()
background(40, 40, 50)
strokeWidth(2)
fill(162, 162, 162, 255)
stroke(127, 127, 127, 255)
for i = 1, numberOfPages do
text(pages[i], WIDTH/4, HEIGHT-CurrentPageHeight-(StandardPageHeight*(i-1)))
line(WIDTH/4, HEIGHT-CurrentPageHeight-(StandardPageHeight*(i-1))-16, WIDTH*.75,
HEIGHT-CurrentPageHeight-(StandardPageHeight*(i-1))-16)
line(WIDTH/4, HEIGHT-CurrentPageHeight-(StandardPageHeight*(i-1))-24, WIDTH*.75,
HEIGHT-CurrentPageHeight-(StandardPageHeight*(i-1))-24)
end
end
function touched(t)
if t.state == MOVING then
CurrentPageHeight = CurrentPageHeight - t.deltaY
print(CurrentPageHeight)
if CurrentPageHeight < -32 then
if CurrentPage >= 2 then
CurrentPage = CurrentPage - 1
CurrentPageHeight = 1000
end
elseif CurrentPageHeight > 1032 then
if CurrentPageHeight <= numberOfPages then
CurrentPage = CurrentPage + 1
CurrentPageHeight = 1000
end
end
end
end
PREVIOUS VERSION: V 0.2
Ok Dave, i made some changes. The code is a lot less simple than before, and still not fully functional, i think i did something wring. At the best my code is ugly. Do you have suggestions, Ideas or comments?
-- Vertical Reader reads long strings and can scroll up and down
--[[ To use, type in
YourPageName = [[ yourstringhere ]]
ChapterTest = [[ This is a test page!
Testing third line!
Testing Fifth line!
End test!
]]
CurrentDoc = ChapterFour
function setup()
print("Hello World!")
font("AmericanTypewriter")
fontSize(20)
textWrapWidth(WIDTH/2)
textAlign(CENTER)
textMode(CORNER)
width, docHeight = textSize(CurrentDoc)
print( "ScreenHeight="..HEIGHT,
"DocHeight="..docHeight,
"PageCorner="..WIDTH/4,HEIGHT-docHeight)
CurrentPage = 1
numberOfPages = 1
pages = {}
function CalculateSubStringLength(f,fSize,tWrapW,tAlign,tMode)
--this function calculates how long to make the substring so that it can be rendered on the iPad through Codea
end
if docHeight >1000 then
CurrentPageHeight = 1000
local numofpages = docHeight/CurrentPageHeight
numberOfPages = numofpages - numofpages%1
print("numberofpages="..numberOfPages)
for i = 1, numberOfPages,1 do
table.insert(pages, string.sub(CurrentDoc, -500 + 500*i, 500*i))
--table.insert(pages, string.sub(CurrentDoc, 1, 500))
end
else
table.insert(pages, CurrentDoc)
CurrentPageHeight = docHeight
end
print(pages[CurrentPage])
end
function draw()
background(40, 40, 50)
strokeWidth(5)
fill(162, 162, 162, 255)
text(pages[CurrentPage], WIDTH/4, HEIGHT-CurrentPageHeight)
end
function touched(t)
if t.state == MOVING then
CurrentPageHeight = CurrentPageHeight - t.deltaY
print(CurrentPageHeight)
if CurrentPageHeight < -360 then
if CurrentPage >= 2 then
CurrentPage = CurrentPage - 1
CurrentPageHeight = 1000
end
elseif CurrentPageHeight > 1360 then
if CurrentPageHeight <= numberOfPages then
CurrentPage = CurrentPage + 1
CurrentPageHeight = 1000
end
end
end
end