Merge branch 'master' of github.com:patriciogonzalezvivo/thebookofshaders
6
.gitignore
vendored
@ -1,3 +1,7 @@
|
||||
.DS_Store
|
||||
.dropbox
|
||||
*Icon*
|
||||
*Icon*
|
||||
tmp.md
|
||||
tmp*.png
|
||||
book.tex
|
||||
book.pdf
|
||||
|
BIN
01/00.jpeg
Before Width: | Height: | Size: 263 KiB After Width: | Height: | Size: 263 KiB |
BIN
01/03.jpeg
Before Width: | Height: | Size: 269 KiB After Width: | Height: | Size: 269 KiB |
BIN
01/04.jpeg
Before Width: | Height: | Size: 340 KiB After Width: | Height: | Size: 301 KiB |
BIN
05/mr_miyagi.jpg
Before Width: | Height: | Size: 149 KiB After Width: | Height: | Size: 132 KiB |
BIN
06/mix-vec.jpg
Before Width: | Height: | Size: 217 KiB After Width: | Height: | Size: 217 KiB |
BIN
07/circle.jpg
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 112 KiB |
BIN
07/compass.jpg
Before Width: | Height: | Size: 271 KiB After Width: | Height: | Size: 270 KiB |
Before Width: | Height: | Size: 270 KiB After Width: | Height: | Size: 270 KiB |
Before Width: | Height: | Size: 370 KiB After Width: | Height: | Size: 367 KiB |
BIN
08/rotate.jpg
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 60 KiB |
BIN
08/translate.jpg
Before Width: | Height: | Size: 171 KiB After Width: | Height: | Size: 170 KiB |
BIN
09/brick.jpg
Before Width: | Height: | Size: 217 KiB After Width: | Height: | Size: 215 KiB |
BIN
14/muybridge.jpg
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
BIN
15/03.jpg
Before Width: | Height: | Size: 177 KiB After Width: | Height: | Size: 177 KiB |
@ -9,8 +9,8 @@ latexEngine = "xelatex"
|
||||
outputPath = "."
|
||||
|
||||
if not os.path.exists(outputPath): os.makedirs(outputPath)
|
||||
pdfBookPath = os.path.join(outputPath, "book.pdf")
|
||||
texBookPath = os.path.join(outputPath, "book.tex")
|
||||
pdfBookPath = os.path.join(outputPath, "book.pdf")
|
||||
texBookPath = os.path.join(outputPath, "book.tex")
|
||||
|
||||
chapters = []
|
||||
|
||||
@ -19,17 +19,26 @@ def injectShaderBlocks( _folder, _text ):
|
||||
lines = _text.split('\n');
|
||||
for line in lines:
|
||||
if line.find('<div class=\"codeAndCanvas\"') >= 0:
|
||||
shaderFile = re.sub(r'<div class=\"codeAndCanvas\" data=\"(.*)\"></div>', r'\1', line.rstrip())
|
||||
shaderTextureResults = re.findall(r'<div class=\"codeAndCanvas\" data=\".*\" data-imgs=\"(.*)\"></div>', line.rstrip())
|
||||
shaderFile = re.sub(r'<div class=\"codeAndCanvas\" data=\"(.*?)\"(>| .+>)</div>', r'\1', line.rstrip())
|
||||
|
||||
shaderName,shaderExt = os.path.splitext(shaderFile)
|
||||
|
||||
shaderPath = folder+"/"+shaderFile;
|
||||
if shaderTextureResults:
|
||||
shaderTexturePaths = map (lambda f: folder+"/"+f, shaderTextureResults[0].split(","))
|
||||
else:
|
||||
shaderTexturePaths = []
|
||||
|
||||
shaderString = open(shaderPath, 'r').read()
|
||||
rta += '```glsl\n'+shaderString.rstrip('\n')+'\n```\n'
|
||||
shaderImage = folder+"/tmp-"+shaderName+".png"
|
||||
shaderCommand = "glslViewer " + shaderPath + " -s 0.5 -o " + shaderImage
|
||||
shaderCommand = "glslViewer " + shaderPath + " " + \
|
||||
" ".join(shaderTexturePaths) + \
|
||||
" -s 0.5 -o " + shaderImage
|
||||
print shaderCommand
|
||||
returnCode = subprocess.call(shaderCommand, shell=True)
|
||||
rta += "!["+shaderPath+"]("+shaderImage+")\n"
|
||||
rta += "![]("+shaderImage+")\n"
|
||||
else:
|
||||
rta += line+'\n'
|
||||
return rta
|
||||
@ -43,19 +52,19 @@ for folder in folders:
|
||||
fileString = originalChapter.read()
|
||||
|
||||
# Correct path for images
|
||||
imgPattern = r'(\!\[(.*)\]\()'
|
||||
subPattern = r'\1{0}/'.format(folder)
|
||||
imgPattern = r'(\!\[.*?\]\()(.*)'
|
||||
subPattern = r'\1' + folder + r'/\2'
|
||||
modifiedChapterString = re.sub(imgPattern, subPattern, fileString)
|
||||
modifiedChapterString = injectShaderBlocks(folder,modifiedChapterString)
|
||||
modifiedChapterPath = folder+'/tmp.md'
|
||||
with open(modifiedChapterPath, "w") as modifiedChapter:
|
||||
modifiedChapter.write(modifiedChapterString)
|
||||
modifiedChapter.write(modifiedChapterString)
|
||||
chapters.append(modifiedChapterPath)
|
||||
|
||||
|
||||
# # Set up the appropriate options for the pandoc command
|
||||
inputOptions = chapters
|
||||
generalOptions = ["-N", "--smart", "--no-tex-ligatures", "--toc", "--standalone", "--preserve-tabs", "-V documentclass=scrbook", "-V papersize=a4", "-V links-as-note", "-S"] #
|
||||
generalOptions = ["-N", "--smart", "--no-tex-ligatures", "--toc", "--standalone", "--preserve-tabs", "-V documentclass=scrbook", "-V papersize=a4", "-V links-as-note", "-S"] #
|
||||
latexOptions = ["--latex-engine="+latexEngine]
|
||||
outputOptions = ["--output={0}".format(pdfBookPath)]
|
||||
pandocCommand = ["pandoc"] + outputOptions + inputOptions + generalOptions + latexOptions
|
||||
@ -74,14 +83,14 @@ for flag in generalOptions+latexOptions:
|
||||
texOutputOptions = ["--output={0}".format(texBookPath)]
|
||||
texPandocCommand = ["pandoc"] + texOutputOptions + inputOptions + generalOptions + latexOptions
|
||||
returnCode = subprocess.call(texPandocCommand)
|
||||
if returnCode == 0:
|
||||
if returnCode == 0:
|
||||
print "Successful building of {0}".format(texBookPath)
|
||||
else:
|
||||
print "Error in building of {0}".format(texBookPath)
|
||||
|
||||
# Call pandoc
|
||||
returnCode = subprocess.call(pandocCommand)
|
||||
if returnCode == 0:
|
||||
if returnCode == 0:
|
||||
print "Successful building of {0}".format(pdfBookPath)
|
||||
else:
|
||||
print "Error in building of {0}".format(pdfBookPath)
|
||||
print "Error in building of {0}".format(pdfBookPath)
|
||||
|