diff --git a/public/scripts/input-output.js b/public/scripts/input-output.js deleted file mode 100644 index 044fc81..0000000 --- a/public/scripts/input-output.js +++ /dev/null @@ -1,32 +0,0 @@ -function setup() { - let canvas = createCanvas(710, 400, WEBGL); - canvas.parent('input-output'); - angleMode(DEGREES); - strokeWeight(5); - noFill(); - stroke(32, 8, 64); -} - -function draw() { - background(250, 180, 200); - - // Call every frame to adjust camera based on mouse/touch - orbitControl(); - - // Rotate rings in a half circle to create a sphere of cubes - for (let zAngle = 0; zAngle < 180; zAngle += 30) { - // Rotate cubes in a full circle to create a ring of cubes - for (let xAngle = 0; xAngle < 360; xAngle += 30) { - push(); - - // Rotate from center of sphere - rotateZ(zAngle); - rotateX(xAngle); - - // Then translate down 400 units - translate(0, 400, 0); - box(); - pop(); - } - } -} \ No newline at end of file diff --git a/public/scripts/multi-sketch.js b/public/scripts/multi-sketch.js new file mode 100644 index 0000000..6a92b2f --- /dev/null +++ b/public/scripts/multi-sketch.js @@ -0,0 +1,55 @@ +let canvas1 = function ( p ) { + p.setup = function() { + p.createCanvas(710, 400, p.WEBGL); + p.angleMode(p.DEGREES); + p.strokeWeight(5); + p.noFill(); + p.stroke(32, 8, 64); + } + + p.draw = function() { + p.background(250, 180, 200); + + // Call every frame to adjust camera based on mouse/touch + p.orbitControl(); + + // Rotate rings in a half circle to create a sphere of cubes + for (let zAngle = 0; zAngle < 180; zAngle += 30) { + // Rotate cubes in a full circle to create a ring of cubes + for (let xAngle = 0; xAngle < 360; xAngle += 30) { + p.push(); + + // Rotate from center of sphere + p.rotateZ(zAngle); + p.rotateX(xAngle); + + // Then translate down 400 units + p.translate(0, 400, 0); + p.box(); + p.pop(); + } + } + } +}; + +let canvas2 = function ( p ) { + + + p.setup = function() { + p.createCanvas(710, 400); + p.background(250, 180, 200); + } + + p.draw = function() { + // draw a circle at the mouse position + p.fill(255, 0, 0); + p.stroke(0); + p.strokeWeight(0); + p.ellipse(p.mouseX, p.mouseY, 80, 80); + + } +} + + +var mycanvas1 = new p5(canvas1, 'canvas1'); +var myp5 = new p5(canvas2, 'canvas2'); diff --git a/src/components/P5Sketch.astro b/src/components/P5Sketch.astro index 46a1ff2..77bc46b 100644 --- a/src/components/P5Sketch.astro +++ b/src/components/P5Sketch.astro @@ -1,15 +1,9 @@ --- -const { sketch_path, sketch_name, figure_id, sketch_description } = Astro.props; -// https://github.com/osbm/osbm.dev/blob/main/ + sketch_path(first 3 characters removed) -const sketch_url = 'https://github.com/osbm/osbm.dev/blob/main/' + sketch_path.slice(3); - +const { sketch_path, canvas_id, figure_id, sketch_description } = Astro.props; +const sketch_url = 'https://github.com/osbm/osbm.dev/blob/main/' + sketch_path; --- - - - -
- +

Figure {figure_id}: {sketch_description} Sketch source diff --git a/src/content/blog/blog-with-multi-p5js.mdx b/src/content/blog/blog-with-multi-p5js.mdx new file mode 100644 index 0000000..164d049 --- /dev/null +++ b/src/content/blog/blog-with-multi-p5js.mdx @@ -0,0 +1,23 @@ +--- +title: 'Third post' +description: 'First post of this website that tests many things' +pubDate: '2024-10-29' +includes_p5js: True +p5_script_path: '../../scripts/multi-sketch.js' +--- + +import P5Sketch from '../../components/P5Sketch.astro'; + +Before first Canvas + + + +After first canvas + + +Before second Canvas + + + +After second canvas +``` diff --git a/src/content/blog/blog-with-p5js.mdx b/src/content/blog/blog-with-p5js.mdx index d5f3fc7..292df6a 100644 --- a/src/content/blog/blog-with-p5js.mdx +++ b/src/content/blog/blog-with-p5js.mdx @@ -2,19 +2,14 @@ title: 'Second post' description: 'First post of this website that tests many things' pubDate: '2024-10-26' - - +includes_p5js: True +p5_script_path: '../../scripts/hello-world.js' --- -import P5Sketch from '../../components/P5Sketch.astro'; +import P5Sketch from '../../components/P5Sketch.astro'; Before Canvas - + After canvas - - - - -why these things happen \ No newline at end of file diff --git a/src/content/config.ts b/src/content/config.ts index 0905202..07124a4 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -11,6 +11,8 @@ const blog = defineCollection({ updatedDate: z.coerce.date().optional(), filename: z.string().optional(), heroImage: z.string().optional(), + includes_p5js: z.boolean().optional(), + p5_script_path: z.string().optional(), }), }); diff --git a/src/layouts/BlogPost.astro b/src/layouts/BlogPost.astro index 3ba5a0a..e8044ee 100644 --- a/src/layouts/BlogPost.astro +++ b/src/layouts/BlogPost.astro @@ -10,7 +10,7 @@ import type { CollectionEntry } from "astro:content"; type Props = CollectionEntry<"blog">["data"]; -const { title, description, pubDate, updatedDate, filename, heroImage } = Astro.props; +const { title, description, pubDate, updatedDate, filename, heroImage, includes_p5js, p5_script_path } = Astro.props; const commitHistoryUrl = "https://github.com/osbm/osbm.dev/commits/main/src/content/blog/" + filename; @@ -21,6 +21,13 @@ const commitHistoryUrl = "https://github.com/osbm/osbm.dev/commits/main/src/cont {title} + + { + includes_p5js && ( + + + ) + }