From 72f65452d2ae78f8e9feb624894026d43564c1f5 Mon Sep 17 00:00:00 2001 From: LeNPaul Date: Sun, 31 Jul 2016 09:48:18 -0400 Subject: [PATCH] Add code highlighting --- 404.html | 15 ++ _posts/2016-07-17-code-test.md | 304 +-------------------------------- css/1syntax.css | 60 ------- css/main.css | 34 ++++ css/syntax.css | 4 - index.html | 4 +- 6 files changed, 55 insertions(+), 366 deletions(-) create mode 100644 404.html delete mode 100644 css/1syntax.css diff --git a/404.html b/404.html new file mode 100644 index 0000000000..34682d5802 --- /dev/null +++ b/404.html @@ -0,0 +1,15 @@ +--- +layout: default +title: "404: Page not found" +permalink: 404.html +--- + +
+

404: Page not found

+ + + +

Ahhhhh!

+ +

Sorry, we've misplaced that URL or it's pointing to something that doesn't exist. Head back home to try finding it again, or search for if on the archives page.

+
diff --git a/_posts/2016-07-17-code-test.md b/_posts/2016-07-17-code-test.md index 8bd1ddb587..675c35b1d4 100644 --- a/_posts/2016-07-17-code-test.md +++ b/_posts/2016-07-17-code-test.md @@ -7,7 +7,7 @@ tags: [programming] You can find the full list of supported programming languages here -{% highlight js %} +{% highlight js linenos %} // Example can be run directly in your JavaScript console // Create a function that takes two arguments and returns the sum of those arguments @@ -18,7 +18,9 @@ adder(2, 6); // > 8 {% endhighlight %} -{% highlight py %} + + +{% highlight py linenos %} import pygame import simulator @@ -105,302 +107,4 @@ def resetSimulation(): pygame.display.update() clock.tick(15) -#Pause function - -def pause(count): - paused = True - - pygame.display.update() - - while paused: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - pygame.quit() - quit() - if event.type == pygame.KEYDOWN: - if event.key == pygame.K_SPACE: - paused = False - if event.key == pygame.K_r: - resetSimulation() - count = 0 - if event.key == pygame.K_q: - pygame.quit() - quit() - if event.key in functionKeys: - functionKeys[event.key](simulationScreen) - - simulationDisplay.fill(constant.black) - daysPassed(count) - - messageFunction("Press space bar to continue simulation",parameter.displayWidth/2,parameter.displayHeight/2) - - for particle in simulator.particleList: - x = int(simulationScreen.mx + (simulationScreen.dx + particle.px) * simulationScreen.magnification) - y = int(simulationScreen.my + (simulationScreen.dy + particle.py) * simulationScreen.magnification) - - size = int(simulationScreen.magnification) - - if size < 2: - pygame.draw.circle(simulationDisplay,constant.white,(x,y),1,1) - else: - pygame.draw.circle(simulationDisplay,constant.white,(x,y),size,0) - - pygame.display.update() - clock.tick(5) - -#Message to screen function - -def textObjects(text, font): - textSurface = font.render(text, True, constant.white) - return textSurface, textSurface.get_rect() - -def messageFunction(text,x,y): - largeText = pygame.font.Font('freesansbold.ttf',30) - textSurf, textRect = textObjects(text, largeText) - textRect.center = ((x), (y)) - simulationDisplay.blit(textSurf, textRect) - #pygame.display.update() - -#Button function - -def button(text,x,y,buttonWidth,buttonHeight,inactiveColor,activeColor,action=None): - - mouse = pygame.mouse.get_pos() - click = pygame.mouse.get_pressed() - - if x + buttonWidth/2 > mouse[0] > x - buttonWidth/2 and y + buttonHeight/2 > mouse[1] > y - buttonHeight/2: - pygame.draw.rect(simulationDisplay, activeColor,(x-(buttonWidth/2),y-(buttonHeight/2),buttonWidth,buttonHeight)) - if click[0] == 1 and action != None: - action() - else: - pygame.draw.rect(simulationDisplay, inactiveColor,(x-(buttonWidth/2),y-(buttonHeight/2),buttonWidth,buttonHeight)) - - smallText = pygame.font.Font("freesansbold.ttf",20) - textSurf, textRect = textObjects(text, smallText) - textRect.center = ( (x), (y)) - simulationDisplay.blit(textSurf, textRect) - -#Simulation start screen - -def simulationIntro(): - - intro = True - - while intro: - - for event in pygame.event.get(): - if event.type == pygame.QUIT: - pygame.quit() - quit() - if event.type == pygame.KEYDOWN: - if event.key == pygame.K_SPACE: - intro = False - if event.key == pygame.K_r: - resetSimulation() - if event.key == pygame.K_q: - pygame.quit() - quit() - if event.key in functionKeys: - functionKeys[event.key](simulationScreen) - - simulationDisplay.fill(constant.black) - - #Draw initial particles - for particle in simulator.particleList: - - x = int(simulationScreen.mx + (simulationScreen.dx + particle.px) * simulationScreen.magnification) - y = int(simulationScreen.my + (simulationScreen.dy + particle.py) * simulationScreen.magnification) - - size = int(simulationScreen.magnification) - - if size < 2: - pygame.draw.circle(simulationDisplay,constant.white,(x,y),1,1) - else: - pygame.draw.circle(simulationDisplay,constant.white,(x,y),size,0) - - #Start menu - - messageFunction("ApplePy",parameter.displayWidth/2,parameter.displayHeight/8) - - messageFunction("n-body simulator",parameter.displayWidth/2,parameter.displayHeight/8 + 50) - - button("Start!", parameter.displayWidth/2,parameter.displayHeight/2 - 150,100,50, constant.green,constant.darkGreen,simulationLoop) - - button("Help", parameter.displayWidth/2,parameter.displayHeight/2 - 75,100,50, constant.green,constant.darkGreen,helpScreen) - - button("About", parameter.displayWidth/2,parameter.displayHeight/2,100,50, constant.green,constant.darkGreen,aboutScreen) - - pygame.display.update() - clock.tick(30) - -#Simulation loop - -#Initial conditions -simulator.generateParticles(parameter.particleNumber,"moon") - -def simulationLoop(): - - count = 0 - - simulationExit = False - - while not simulationExit: - for event in pygame.event.get(): - - #Handling quit events - - if event.type == pygame.QUIT: - simulationExit = True - - if event.type == pygame.KEYDOWN: - if event.key == pygame.K_r: - resetSimulation() - count = 0 - elif event.key == pygame.K_SPACE: - pause(count) - elif event.key in functionKeys: - functionKeys[event.key](simulationScreen) - - simulationDisplay.fill(constant.black) - - #Update particle positions - simulator.updatePositions(simulator.particleList,"euler") - - #Draw particles - for particle in simulator.particleList: - - x = int(simulationScreen.mx + (simulationScreen.dx + particle.px) * simulationScreen.magnification) - y = int(simulationScreen.my + (simulationScreen.dy + particle.py) * simulationScreen.magnification) - - size = int(simulationScreen.magnification) - - if size < 2: - pygame.draw.circle(simulationDisplay,constant.white,(x,y),1,1) - else: - pygame.draw.circle(simulationDisplay,constant.white,(x,y),size,0) - - count += 1 - daysPassed(count) - - pygame.display.update() - - clock.tick(30) - - pygame.quit() - quit() - -#Simulation help screen -def helpScreen(): - - intro = True - - while intro: - - for event in pygame.event.get(): - if event.type == pygame.QUIT: - pygame.quit() - quit() - if event.type == pygame.KEYDOWN: - if event.key == pygame.K_SPACE: - intro = False - if event.key == pygame.K_r: - resetSimulation() - if event.key == pygame.K_q: - pygame.quit() - quit() - if event.key in functionKeys: - functionKeys[event.key](simulationScreen) - - simulationDisplay.fill(constant.black) - - #Draw initial particles - for particle in simulator.particleList: - - x = int(simulationScreen.mx + (simulationScreen.dx + particle.px) * simulationScreen.magnification) - y = int(simulationScreen.my + (simulationScreen.dy + particle.py) * simulationScreen.magnification) - - size = int(simulationScreen.magnification) - - if size < 2: - pygame.draw.circle(simulationDisplay,constant.white,(x,y),1,1) - else: - pygame.draw.circle(simulationDisplay,constant.white,(x,y),size,0) - - #Start menu - - messageFunction("ApplePy",parameter.displayWidth/2,parameter.displayHeight/8) - - messageFunction("n-body simulator",parameter.displayWidth/2,parameter.displayHeight/8 + 50) - - messageFunction("Press spacebar to pause",parameter.displayWidth/2,parameter.displayHeight/8 + 150) - - messageFunction("Use arrow keys to move around and +/- to zoom",parameter.displayWidth/2,parameter.displayHeight/8 + 200) - - messageFunction("Press r to reset simulation and q to quit",parameter.displayWidth/2,parameter.displayHeight/8 + 250) - - button("Back", parameter.displayWidth/2,parameter.displayHeight/8 + 350,100,50, constant.green,constant.darkGreen,simulationIntro) - - pygame.display.update() - clock.tick(30) - -#Simulation about screen -def aboutScreen(): - - intro = True - - while intro: - - for event in pygame.event.get(): - if event.type == pygame.QUIT: - pygame.quit() - quit() - if event.type == pygame.KEYDOWN: - if event.key == pygame.K_SPACE: - intro = False - if event.key == pygame.K_r: - resetSimulation() - if event.key == pygame.K_q: - pygame.quit() - quit() - if event.key in functionKeys: - functionKeys[event.key](simulationScreen) - - simulationDisplay.fill(constant.black) - - #Draw initial particles - for particle in simulator.particleList: - - x = int(simulationScreen.mx + (simulationScreen.dx + particle.px) * simulationScreen.magnification) - y = int(simulationScreen.my + (simulationScreen.dy + particle.py) * simulationScreen.magnification) - - size = int(simulationScreen.magnification) - - if size < 2: - pygame.draw.circle(simulationDisplay,constant.white,(x,y),1,1) - else: - pygame.draw.circle(simulationDisplay,constant.white,(x,y),size,0) - - #Start menu - - messageFunction("ApplePy",parameter.displayWidth/2,parameter.displayHeight/8) - - messageFunction("n-body simulator",parameter.displayWidth/2,parameter.displayHeight/8 + 50) - - messageFunction("This physics simulation uses euler integration to solve",parameter.displayWidth/2,parameter.displayHeight/8 + 150) - - messageFunction("for the motion of particles under the influence of gravity.",parameter.displayWidth/2,parameter.displayHeight/8 + 200) - - messageFunction("Built by Paul Le",parameter.displayWidth/2,parameter.displayHeight/8 + 250) - - button("Back", parameter.displayWidth/2,parameter.displayHeight/8 + 350,100,50, constant.green,constant.darkGreen,simulationIntro) - - pygame.display.update() - clock.tick(30) - - -#Calling simulation program functions - -simulationIntro() -simulationLoop() - {% endhighlight %} diff --git a/css/1syntax.css b/css/1syntax.css deleted file mode 100644 index 2774b76492..0000000000 --- a/css/1syntax.css +++ /dev/null @@ -1,60 +0,0 @@ -.highlight { background: #ffffff; } -.highlight .c { color: #999988; font-style: italic } /* Comment */ -.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ -.highlight .k { font-weight: bold } /* Keyword */ -.highlight .o { font-weight: bold } /* Operator */ -.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */ -.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */ -.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */ -.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */ -.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ -.highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */ -.highlight .ge { font-style: italic } /* Generic.Emph */ -.highlight .gr { color: #aa0000 } /* Generic.Error */ -.highlight .gh { color: #999999 } /* Generic.Heading */ -.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ -.highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */ -.highlight .go { color: #888888 } /* Generic.Output */ -.highlight .gp { color: #555555 } /* Generic.Prompt */ -.highlight .gs { font-weight: bold } /* Generic.Strong */ -.highlight .gu { color: #aaaaaa } /* Generic.Subheading */ -.highlight .gt { color: #aa0000 } /* Generic.Traceback */ -.highlight .kc { font-weight: bold } /* Keyword.Constant */ -.highlight .kd { font-weight: bold } /* Keyword.Declaration */ -.highlight .kp { font-weight: bold } /* Keyword.Pseudo */ -.highlight .kr { font-weight: bold } /* Keyword.Reserved */ -.highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */ -.highlight .m { color: #009999 } /* Literal.Number */ -.highlight .s { color: #d14 } /* Literal.String */ -.highlight .na { color: #008080 } /* Name.Attribute */ -.highlight .nb { color: #0086B3 } /* Name.Builtin */ -.highlight .nc { color: #445588; font-weight: bold } /* Name.Class */ -.highlight .no { color: #008080 } /* Name.Constant */ -.highlight .ni { color: #800080 } /* Name.Entity */ -.highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */ -.highlight .nf { color: #990000; font-weight: bold } /* Name.Function */ -.highlight .nn { color: #555555 } /* Name.Namespace */ -.highlight .nt { color: #000080 } /* Name.Tag */ -.highlight .nv { color: #008080 } /* Name.Variable */ -.highlight .ow { font-weight: bold } /* Operator.Word */ -.highlight .w { color: #bbbbbb } /* Text.Whitespace */ -.highlight .mf { color: #009999 } /* Literal.Number.Float */ -.highlight .mh { color: #009999 } /* Literal.Number.Hex */ -.highlight .mi { color: #009999 } /* Literal.Number.Integer */ -.highlight .mo { color: #009999 } /* Literal.Number.Oct */ -.highlight .sb { color: #d14 } /* Literal.String.Backtick */ -.highlight .sc { color: #d14 } /* Literal.String.Char */ -.highlight .sd { color: #d14 } /* Literal.String.Doc */ -.highlight .s2 { color: #d14 } /* Literal.String.Double */ -.highlight .se { color: #d14 } /* Literal.String.Escape */ -.highlight .sh { color: #d14 } /* Literal.String.Heredoc */ -.highlight .si { color: #d14 } /* Literal.String.Interpol */ -.highlight .sx { color: #d14 } /* Literal.String.Other */ -.highlight .sr { color: #009926 } /* Literal.String.Regex */ -.highlight .s1 { color: #d14 } /* Literal.String.Single */ -.highlight .ss { color: #990073 } /* Literal.String.Symbol */ -.highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */ -.highlight .vc { color: #008080 } /* Name.Variable.Class */ -.highlight .vg { color: #008080 } /* Name.Variable.Global */ -.highlight .vi { color: #008080 } /* Name.Variable.Instance */ -.highlight .il { color: #009999 } /* Literal.Number.Integer.Long */ diff --git a/css/main.css b/css/main.css index a7353a1679..7bef66e991 100644 --- a/css/main.css +++ b/css/main.css @@ -235,7 +235,41 @@ blockquote p { Code */ +pre, +code { + font-size: 0.75rem; + border-radius: 3px; + background-color: #f5f5f5; + font-family: "Source Code Pro"; +} + +code { + padding: 1px 5px; +} +pre { + padding: 8px 12px; + overflow-x: auto; + + > code { + border: 0; + padding-right: 0; + padding-left: 0; + } +} + +.highlight .lineno { + color: #aaa; + display:inline-block; + padding: 0 5px; + border-right:1px solid #ccc; +} +.highlight pre code { + display: block; + white-space: pre; + overflow-x: auto; + word-wrap: normal; +} /* Social media icons diff --git a/css/syntax.css b/css/syntax.css index ea93cc1d01..15ad797710 100644 --- a/css/syntax.css +++ b/css/syntax.css @@ -1,7 +1,3 @@ -code { - font-family: 'Source Code Pro'; -} - .highlight .hll { background-color: #ffc; } .highlight .c { color: #999; } /* Comment */ .highlight .err { color: #a00; background-color: #faa } /* Error */ diff --git a/index.html b/index.html index 2e90fbe7b3..bcb95c4054 100644 --- a/index.html +++ b/index.html @@ -21,13 +21,13 @@