thurtle: Add 🌱 example

This commit is contained in:
Remko Tronçon 2024-01-26 19:10:46 +01:00
parent 7135ea2865
commit 3948f4329f

View file

@ -202,6 +202,47 @@ HERE RND !
1 SETPENSIZE 1 SETPENSIZE
SIZE 0 PLANT SIZE 0 PLANT
`,
},
{
name: "🌱",
isExample: true,
program: `
450 CONSTANT <SIZE>
7 CONSTANT <BRANCHES>
160 CONSTANT <SPREAD>
HEX 006A47 DECIMAL CONSTANT 🟩
HEX 825E5C DECIMAL CONSTANT 🟫
VARIABLE RND
134348 RND !
: RANDOM ( -- n )
RND @ 75 * 74 + 65537 MOD
DUP RND !
;
: CHOOSE ( n1 -- n2 )
RANDOM 65537 */MOD SWAP DROP
;
: 🌱 ( size angle -- )
OVER 10 < IF 2DROP EXIT THEN
OVER 50 / 1 MAX SETPENSIZE
OVER 50 > IF 🟫 ELSE 🟩 THEN SETPENCOLOR
DUP
OVER
<BRANCHES> 0 DO
OVER 2/
<SPREAD> CHOOSE <SPREAD> 2/ -
RECURSE
LOOP
PENUP SWAP PENDOWN
;
<SIZE> 0 🌱
HIDETURTLE
`, `,
}, },
].map((e) => ({ ...e, program: e.program.trimStart() })); ].map((e) => ({ ...e, program: e.program.trimStart() }));