Skip to content

Commit

Permalink
change drawTurtles to take list
Browse files Browse the repository at this point in the history
  • Loading branch information
leomcelroy committed Oct 17, 2023
1 parent df4deb9 commit 9aff745
Show file tree
Hide file tree
Showing 23 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion art/eca-henry/eca.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ for (let gen = 0; gen < w * 2; gen++) {
drawGen(allGens[gen + 1], -gen)
}

drawTurtles(t)
drawTurtles([t])
2 changes: 1 addition & 1 deletion art/hilbert_golf-henry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ for (let i of eval(
try {
eval(i == 'F' ? `t.forward(-0.1)` : `t.left(${i}87)`)
} catch {}
drawTurtles(t)
drawTurtles([t])
2 changes: 1 addition & 1 deletion art/landscape-henry/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const t = new Turtle()
drawTurtles(t)
drawTurtles([t])
const time = 106

const resX = 5.16
Expand Down
2 changes: 1 addition & 1 deletion art/leaf-leo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ t.iteratePath(pt => {
t.translate([125 / 2, 125 / 2], t.cc)
t.scale(17.2)

drawTurtles(t)
drawTurtles([t])
2 changes: 1 addition & 1 deletion art/raymarching-henry/raymarch.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,4 @@ world.objects = [
new Plane(new Vec3(0, -3, 0))
]
renderFrame(cam)
drawTurtles(t)
drawTurtles([t])
2 changes: 1 addition & 1 deletion art/roots-kai/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,4 @@ function makeBranch(turtle, length, startingT) {
makeBranch(t, 0.1, 0)

// Draw turtles array
drawTurtles(...turtles)
drawTurtles([turtles])
2 changes: 1 addition & 1 deletion art/square-disarray-leo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ for (let i = 0; i < nWidth; i++) {

shapes.scale([0.9, -0.9])

drawTurtles(shapes)
drawTurtles([shapes])
2 changes: 1 addition & 1 deletion art/tree-leo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ for (let i = 0; i < 100000; i++) {

randomWalk.rotate(randInRange(-5, 5)).translate([-0.1, -0.6])

drawTurtles(trunk, randomWalk)
drawTurtles([trunk, randomWalk])
2 changes: 1 addition & 1 deletion astro/src/components/landing/ThreeDModel.astro
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ t.iteratePath(pt => {
t.translate([125 / 2, 125 / 2], t.cc)
t.scale(70)

drawTurtles(t)`)
drawTurtles([t])`)

if (testTurtles.length > 1) {
const [first, ...rest] = testTurtles
Expand Down
4 changes: 2 additions & 2 deletions astro/src/lib/defaultProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ testTurtle.translate(
testTurtle.cc
);
drawTurtles(
drawTurtles([
testTurtle
);
]);
`.trim()
10 changes: 8 additions & 2 deletions astro/src/lib/runTextReturnTurtles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ const customGlobal = {
lerp(start: number, end: number, t: number) {
return (1 - t) * start + t * end
},
drawTurtles: (...turtlesToDraw: Turtle[]) => {
turtlesToDraw.forEach(t => _returnTurtles.push(t))
drawTurtles: (turtlesToDraw: Turtle[], style = {}) => {
turtlesToDraw.forEach(t => {
const temp = t.copy();
if (style.fill === undefined) style.fill = "none";
if (style.stroke === undefined) style.stroke = "black";
temp.style = style;
turtles.push(temp);
});
},
setDocDimensions(w: number, h: number) {}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/TOOLKIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ t.interpolate(tValue)
To render a turtle use `drawTurtles` it is variadic (can take multiple turtles as arguments).

```js
drawTurtles(...turtles)
drawTurtles([ turtles ])
```

You can drag in SVG's, and the interface will generate a turtle for it. Keep in mind that SVG's are often imported far too large, and will need to be scaled and translated.
Expand Down
2 changes: 1 addition & 1 deletion guides/10PRINT.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Each time we're at a new row, start moving horizontally by increasing `x`. At ev

And, lastly, let's draw this to the screen! This is done simply by calling the function `drawTurtles` with the turtle we defined at the start.

`drawTurtles(t);`
`drawTurtles([ t ]);`

And, you're done! If all went well, you should be seeing something like the below art:

Expand Down
2 changes: 1 addition & 1 deletion guides/10PRINT2.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Let's start by defining a constant `t`: this will represent our turtle. The turt
const t = createTurtle()
```

Directly below that, write `drawTurtles(t);`. This function makes it so that we can see the turtle's path in the preview window as we add to it.
Directly below that, write `drawTurtles([ t ]);`. This function makes it so that we can see the turtle's path in the preview window as we add to it.

Since the original artwork is made up of many diagonal lines, we'll need a function that can draw these.

Expand Down
2 changes: 1 addition & 1 deletion guides/cubic_disarray.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ We can get started by setting up a turtle, and define some constants:

```js
const t = createTurtle()
drawTurtles(t)
drawTurtles([ t ])

const size = 10
const squareSize = 1
Expand Down
2 changes: 1 addition & 1 deletion guides/eca.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ for (let gen = 0; gen < w; gen++) {
drawGen(allGens[gen + 1], gen)
}
drawTurtles(t)
drawTurtles([ t ])
```

Great job! There are plenty of variations on ECAs that you can explore. Here's a few more drawings done with the code, by setting only the center pixel as a one:
Expand Down
2 changes: 1 addition & 1 deletion guides/joydivision.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Let's give this a shot! First, simply declare a turtle, and draw it's path to th

```
const t = new Turtle();
drawTurtles(t);
drawTurtles([ t ]);
```

To actually get it to draw something, we can iterate through a grid, drawing horizontal lines:
Expand Down
2 changes: 1 addition & 1 deletion guides/landscape.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,5 @@ for (let y = 0; y < 15; y += dy) {
}
}

drawTurtles(t)
drawTurtles([ t ])
```
4 changes: 2 additions & 2 deletions guides/leaf.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const edge = createTurtle().forward(leafLength)
// render the final leaf like such
const leaf = createTurtle().join(edge)

drawTurtles(leaf)
drawTurtles([ leaf ])
```

<img
Expand Down Expand Up @@ -70,7 +70,7 @@ const bottom = edge.copy().scale([1, -1], [0, 0])

const leaf = createTurtle().join(edge).join(bottom)

drawTurtles(leaf)
drawTurtles([ leaf ])
```

<img
Expand Down
2 changes: 1 addition & 1 deletion guides/mesh.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ for(var y = 0; y < lines.length - 1; y++) {
}
}
drawTurtles(t)
drawTurtles([ t ])
```

And, that's it! If all went well, you should have an image resembling the one at the start of the guide.
4 changes: 2 additions & 2 deletions guides/roots.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function makeBranch(turtle) {

makeBranch(t)

drawTurtles(...turtles)
drawTurtles([ turtles ])
```

You should get something like the screenshot below:
Expand Down Expand Up @@ -105,7 +105,7 @@ function thicken(turtle) {

makeBranch(t, 0.1, 0)

drawTurtles(t)
drawTurtles([ t ])

// Smoothstep
function clamp(x, minVal, maxVal) {
Expand Down
2 changes: 1 addition & 1 deletion guides/square-disarray.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const shapes = createTurtle() // this will be our container turtle

shapes.translate([width / 2, height / 2], shapes.cc) // this moves the center of our turtle to the center of our doc

drawTurtles(shapes)
drawTurtles([ shapes ])
```

# Draw a Square
Expand Down
4 changes: 2 additions & 2 deletions guides/tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ for (let i = 0; i < 1000; i++) {
const [endX, endY] = randomWalk.end;
}

drawTurtles(randomWalk);
drawTurtles([ randomWalk ]);
```

<img src="https://github.com/hackclub/haxidraw/assets/27078897/f98e2f48-3785-4449-b936-dc5e637bdff5" height="512"/>
Expand Down Expand Up @@ -276,7 +276,7 @@ let startPt = trunk.ct;

randomWalk.rotate(randInRange(-5, 5)).translate([-0.1, -0.6]);

drawTurtles(randomWalk, trunk);
drawTurtles([ randomWalk, trunk ]);
```

<img src="https://github.com/hackclub/haxidraw/assets/27078897/114d17dc-b5a3-43ab-baf6-0e1dfee2d959" height="512"/>
Expand Down

1 comment on commit 9aff745

@vercel
Copy link

@vercel vercel bot commented on 9aff745 Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blot – ./astro

blot.hackclub.dev
blot-git-main.hackclub.dev

Please sign in to comment.