From 5b01f557ebbd3343b30fd3c6423f3072623d8f41 Mon Sep 17 00:00:00 2001 From: leomcelroy Date: Thu, 19 Oct 2023 19:56:13 -0400 Subject: [PATCH] updates --- art/hilbert_golf-henry/index.js | 2 +- guides/cubic_disarray.md | 5 ++++- guides/joydivision.md | 14 +++++++------- guides/mesh.md | 8 ++++---- guides/roots.md | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/art/hilbert_golf-henry/index.js b/art/hilbert_golf-henry/index.js index 5724ea228..cbcbfa274 100644 --- a/art/hilbert_golf-henry/index.js +++ b/art/hilbert_golf-henry/index.js @@ -6,6 +6,6 @@ for (let i of eval( eval(i == 'F' ? `t.forward(-0.1)` : `t.left(${i}87)`) } catch {} -t.scale(125/t.width); +t.scale(110/t.width); t.translate([125/2, 125/2], t.cc); drawTurtles([t]) diff --git a/guides/cubic_disarray.md b/guides/cubic_disarray.md index 7cdf2924f..dcb1bd2ef 100644 --- a/guides/cubic_disarray.md +++ b/guides/cubic_disarray.md @@ -14,10 +14,13 @@ We can get started by setting up a turtle, and define some constants: ```js const t = createTurtle() -drawTurtles([ t ]) const size = 10 const squareSize = 1 + +// ... other code goes here ... + +drawTurtles([ t ]) ``` Obviously we'll need a way to draw these rotated squares, so let's define a function for that: diff --git a/guides/joydivision.md b/guides/joydivision.md index 54e50b182..b5617f70f 100644 --- a/guides/joydivision.md +++ b/guides/joydivision.md @@ -12,14 +12,14 @@ First, let's start by noticing what we see in the image. It seems to be composed Let's give this a shot! First, simply declare a turtle, and draw it's path to the screen: -``` +```js const t = new Turtle(); drawTurtles([ t ]); ``` To actually get it to draw something, we can iterate through a grid, drawing horizontal lines: -``` +```js const height = 13; const lineWidth = 10; const lineSpacing = 0.2; @@ -43,7 +43,7 @@ You should now be seeing a bunch of straight horizontal lines. Let's add some ra A first attempt may look something like this: -``` +```js let height = Math.random(); ``` @@ -53,7 +53,7 @@ We can call this in the Haxidraw editor with `noise([x, y], {octaves:n, falloff: We don't want pure smooth noise, and we'll instead want to modify how we sample it a bit. Set `height` equal to `line + sampleNoise(x, line)`, and define that function: -``` +```js const baseNoiseHorizontalScale = 1.5; const baseNoiseVerticalScale = 10; const baseNoiseAmp = 0.1; @@ -81,7 +81,7 @@ We define a few constants to dictate how vertically and horizontally stretched b Notice that when defining the base noise, we use a function `distFromCenter`. We'll have to define this as such: -``` +```js function distFromCenter(x) { return lineWidth/2 - Math.abs(x) } @@ -97,13 +97,13 @@ This looks close to the final product, but there's still one big thing that it's Create the array, and fill it with zeroes: -``` +```js let maxHeights = new Array(lineWidth / dx); ``` Above the line `if (x == -lineWidth/2) t.up();` in our main loop, add the following logic doing what we outlined earlier: -``` +```js let maxHeightsIndex = Math.floor((x + lineWidth/2) / dx) if (height > maxHeights[maxHeightsIndex]) { t.down() diff --git a/guides/mesh.md b/guides/mesh.md index 9867ea85b..55abcf2ec 100644 --- a/guides/mesh.md +++ b/guides/mesh.md @@ -26,7 +26,7 @@ Next, let's define a scale for the whole image: Then, we can create a grid. This is identical to a typical rectangular grid, except we offset every other line by a bit, making it triangular. -``` +```js var line, dot, odd = false, lines = [], @@ -41,7 +41,7 @@ for(var y = gap / 2; y <= size; y+= gap) { Then, use the built-in haxidraw noise function to offset the points again, this time randomly. Also, add an offset on the x axis if we're drawing an odd-numbered line. -``` +```js let n = noise([x * 0.1, y * 0.1]) line.push({ x: x + (n*4.1 - .4) * gap + (odd ? gap/2 : 0), @@ -54,7 +54,7 @@ Then, use the built-in haxidraw noise function to offset the points again, this Now, we need a way to draw this. We can define a simple function to render a triange, where we simply go through every point of the triangle with the turtle `goTo` function. -``` +```js function drawTriangle(pointA, pointB, pointC) { t.goTo([pointA.x, pointA.y]); t.down() @@ -67,7 +67,7 @@ function drawTriangle(pointA, pointB, pointC) { Now, to draw the whole mesh, we can iterate through the points, drawing triangles at every 3 points next to each other in 2D. -``` +```js var dotLine; odd = true; diff --git a/guides/roots.md b/guides/roots.md index 8a8227108..0dba2bca1 100644 --- a/guides/roots.md +++ b/guides/roots.md @@ -22,7 +22,7 @@ We can first start by drawing a simple random walk, where during each step we (r const WIDTH = 10 const HEIGHT = 20 -const t = new Turtle([WIDTH / 2, 0]) +const t = createTurtle([WIDTH / 2, 0]) t.right(90) const turtles = [t]