@genocode/core 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ast.d.ts +17 -1
- package/dist/ast.d.ts.map +1 -1
- package/dist/ast.js.map +1 -1
- package/dist/builtins.d.ts +1 -1
- package/dist/builtins.d.ts.map +1 -1
- package/dist/builtins.js +5 -2
- package/dist/builtins.js.map +1 -1
- package/dist/checker.d.ts +10 -1
- package/dist/checker.d.ts.map +1 -1
- package/dist/checker.js +102 -2
- package/dist/checker.js.map +1 -1
- package/dist/colour.d.ts +1 -1
- package/dist/colour.d.ts.map +1 -1
- package/dist/colour.js +8 -4
- package/dist/colour.js.map +1 -1
- package/dist/format.d.ts.map +1 -1
- package/dist/format.js +37 -3
- package/dist/format.js.map +1 -1
- package/dist/genetics.d.ts.map +1 -1
- package/dist/genetics.js +3 -1
- package/dist/genetics.js.map +1 -1
- package/dist/help.d.ts.map +1 -1
- package/dist/help.js +30 -3
- package/dist/help.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interpreter.js +3 -1
- package/dist/interpreter.js.map +1 -1
- package/dist/lexer.d.ts.map +1 -1
- package/dist/lexer.js +1 -0
- package/dist/lexer.js.map +1 -1
- package/dist/parser.js +48 -2
- package/dist/parser.js.map +1 -1
- package/dist/values.d.ts +2 -0
- package/dist/values.d.ts.map +1 -1
- package/dist/values.js +1 -1
- package/dist/values.js.map +1 -1
- package/package.json +1 -1
- package/reference/LANGUAGE.md +61 -8
- package/reference/creatures/Alien.genie +653 -0
- package/reference/creatures/Breeze.genie +386 -0
- package/reference/creatures/Cobra.genie +386 -0
- package/reference/creatures/Flowerball.genie +302 -39
- package/reference/creatures/FlyingFish.genie +786 -0
- package/reference/creatures/Genes.genie +470 -0
- package/reference/creatures/Genie.genie +548 -0
- package/reference/creatures/Greenbay.genie +786 -0
- package/reference/creatures/Jellyfish.genie +472 -0
- package/reference/creatures/Monster.genie +594 -0
- package/reference/creatures/Neuron.genie +649 -0
- package/reference/creatures/Octoplant.genie +334 -0
- package/reference/creatures/Parasite.genie +393 -0
- package/reference/creatures/Pesky.genie +473 -0
- package/reference/creatures/Phoenix.genie +294 -0
- package/reference/creatures/Picstix.genie +1788 -0
- package/reference/creatures/Psybat.genie +602 -0
- package/reference/creatures/Star.genie +339 -0
- package/reference/creatures/Starfish.genie +458 -0
- package/reference/creatures/Transformer.genie +297 -0
- package/reference/creatures/TwoByTwo.genie +547 -0
- package/reference/creatures/Flower.genie +0 -41
- package/reference/creatures/Flyer.genie +0 -142
- package/reference/creatures/StarBurstShell.genie +0 -102
- package/reference/creatures/StarBurstShell9.genie +0 -102
package/reference/LANGUAGE.md
CHANGED
|
@@ -167,7 +167,7 @@ allowed as arguments to `print`.
|
|
|
167
167
|
creature gene part function return let if else repeat as for from to by while
|
|
168
168
|
branch lay reshape symmetric shape colour color shine sharpness texture background
|
|
169
169
|
fill dance forward back move pitch yaw roll rotate around grow mirror in step log
|
|
170
|
-
at and or not true false print turtle time beat music
|
|
170
|
+
at and or not true false print turtle time beat music variant
|
|
171
171
|
```
|
|
172
172
|
|
|
173
173
|
Some words are only special in one place, and are ordinary names elsewhere:
|
|
@@ -176,7 +176,8 @@ Some words are only special in one place, and are ordinary names elsewhere:
|
|
|
176
176
|
- the effect names `morph`, `zoom`, `spin`, `turn`, `reverse` and `flat` inside a `dance` block.
|
|
177
177
|
|
|
178
178
|
**Built-in names**, such as the library functions, constants, colour names, shape names and pattern
|
|
179
|
-
kinds, can't be used as names of genes, variables, parameters,
|
|
179
|
+
kinds, and the words `gradient` and `spectrum`, can't be used as names of genes, variables, parameters,
|
|
180
|
+
parts or functions.
|
|
180
181
|
|
|
181
182
|
`colour` and `color` mean the same thing everywhere, including in `turtle.colour` / `turtle.color`.
|
|
182
183
|
|
|
@@ -303,6 +304,46 @@ part wing(reach, side) { … }
|
|
|
303
304
|
- A part gene can only be called. It can't be stored in a variable, passed as an argument or
|
|
304
305
|
compared.
|
|
305
306
|
|
|
307
|
+
### 6.6 Variants
|
|
308
|
+
|
|
309
|
+
A creature can keep other sets of gene values alongside its own: its **variants**. Together with
|
|
310
|
+
the creature itself, they form a family of related creatures that share one program, such as the
|
|
311
|
+
members of an evolved population.
|
|
312
|
+
|
|
313
|
+
```
|
|
314
|
+
creature Cobra
|
|
315
|
+
|
|
316
|
+
gene hood = 1.2 in 0.5..2 // how wide the hood spreads
|
|
317
|
+
gene coils = 3 in 1..6 step 1
|
|
318
|
+
gene skin = hsv(120, 0.7, 0.8) in hsv(60, 0.3, 0.5)..hsv(180, 1, 1)
|
|
319
|
+
|
|
320
|
+
grow hood
|
|
321
|
+
repeat coils {
|
|
322
|
+
colour skin
|
|
323
|
+
forward 1
|
|
324
|
+
lay
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
variant Coiled { coils = 6; hood = 0.8 }
|
|
328
|
+
|
|
329
|
+
variant Striker {
|
|
330
|
+
hood = 2
|
|
331
|
+
skin = hsv(70, 0.9, 1) // bright, to warn others off
|
|
332
|
+
}
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
- `variant Name { … }` sets genes by their **full names** ([6.3](#63-full-names)), one per line
|
|
336
|
+
(or separated by `;`): `petals = 9`, `whorl.petals = 9`, `background.hue = 200`, `seed = 42`.
|
|
337
|
+
Genes it doesn't mention keep the values written in their declarations.
|
|
338
|
+
- Variants can only be at the top level of a creature file. Their names must be different from one
|
|
339
|
+
another; they don't clash with any other names.
|
|
340
|
+
- Each value is a constant expression ([6.1](#61-declaring-genes)) that would be allowed as the
|
|
341
|
+
gene's own value: of the gene's kind, within its range, one of its options, or one of its parts.
|
|
342
|
+
A gene can be set at most once in a variant.
|
|
343
|
+
- Variants don't change what the program does. They are used by the app wherever it wants a
|
|
344
|
+
group of related creatures ([section 19](#19-genetics)), for example as the loop a creature
|
|
345
|
+
morphs through.
|
|
346
|
+
|
|
306
347
|
## 7. Variables
|
|
307
348
|
|
|
308
349
|
```
|
|
@@ -564,7 +605,7 @@ opacity: 1 is solid and 0 is invisible.
|
|
|
564
605
|
|
|
565
606
|
**Blending two colours** (in `mix`, `smoothmix`, gradients and morphing) blends saturation, value
|
|
566
607
|
and alpha in a straight line, and hue the short way round the circle. Hues exactly 180 degrees
|
|
567
|
-
apart blend in the increasing direction.
|
|
608
|
+
apart blend in the increasing direction. Spectrums ([13.3](#133-gradients)) are the one exception.
|
|
568
609
|
|
|
569
610
|
The named colours are:
|
|
570
611
|
|
|
@@ -610,6 +651,15 @@ repeat 20 as i {
|
|
|
610
651
|
last stop it's the last stop's, and between two stops it's those two colours blended
|
|
611
652
|
([13.1](#131-colours)).
|
|
612
653
|
|
|
654
|
+
**Spectrums.** `spectrum(…)` is written and sampled like `gradient(…)`, with one difference: between
|
|
655
|
+
two stops, hue moves in a straight line from one number to the other, never across 0°. So
|
|
656
|
+
`spectrum(blue, red)` passes through cyan, green and yellow (240° down to 0°), where
|
|
657
|
+
`gradient(blue, red)` goes the short way, through magenta.
|
|
658
|
+
|
|
659
|
+
```
|
|
660
|
+
let flame = spectrum(hsv(60, 1, 1), hsv(0, 1, 1), hsv(280, 1, 0.5)) // yellow, red, then back through every hue to violet
|
|
661
|
+
```
|
|
662
|
+
|
|
613
663
|
## 14. Textures
|
|
614
664
|
|
|
615
665
|
Textures are generated from a recipe of a few values, so they can be genes and evolve with the
|
|
@@ -801,7 +851,7 @@ All angles are in degrees.
|
|
|
801
851
|
|
|
802
852
|
### 18.3 Colours
|
|
803
853
|
|
|
804
|
-
`hsv(…)`, `rgb(…)`, `mix(a, b, t)`, `smoothmix(a, b, t)` and `
|
|
854
|
+
`hsv(…)`, `rgb(…)`, `mix(a, b, t)`, `smoothmix(a, b, t)`, `gradient(…)` and `spectrum(…)`, plus the colour names in
|
|
805
855
|
[13.1](#131-colours) and the parts `.hue`, `.sat`, `.val` and `.alpha`.
|
|
806
856
|
|
|
807
857
|
### 18.4 Reading the turtle
|
|
@@ -910,14 +960,15 @@ Values aren't limited to either creature's range while morphing.
|
|
|
910
960
|
|
|
911
961
|
A morph through several creatures (a loop) is a chain of these morphs between neighbours. When A
|
|
912
962
|
and B share a program, a morph is smooth all the way; when their programs differ, the creature
|
|
913
|
-
changes shape at the halfway point.
|
|
963
|
+
changes shape at the halfway point. A creature with variants ([6.6](#66-variants)) has a loop of its
|
|
964
|
+
own: the creature itself, then each variant in the order they're written.
|
|
914
965
|
|
|
915
966
|
### 19.4 Saving
|
|
916
967
|
|
|
917
968
|
A creature that has been mutated, bred or morphed is saved as an ordinary creature file: its
|
|
918
969
|
program, with each gene's new value written into the gene's line. Nothing else in the program
|
|
919
970
|
changes, except that the file is laid out by the formatter, and a gene whose value hasn't changed
|
|
920
|
-
keeps the text it was written with. The new values are written readably: stepped numbers exactly,
|
|
971
|
+
keeps the text it was written with. Variants are kept as they are. The new values are written readably: stepped numbers exactly,
|
|
921
972
|
other numbers to four significant figures, colours as `hsv(…)`, and choices by name, always within
|
|
922
973
|
the gene's range. The automatic `seed` gene has no line of its own, so it isn't saved yet: a saved
|
|
923
974
|
creature that uses `random` starts again from seed 0.
|
|
@@ -992,7 +1043,9 @@ dance_file = "dance" NAME NL dance_body ;
|
|
|
992
1043
|
|
|
993
1044
|
item = gene | part | function | statement
|
|
994
1045
|
| "background" "{" bg_body "}"
|
|
995
|
-
| "dance" "{" dance_body "}"
|
|
1046
|
+
| "dance" "{" dance_body "}"
|
|
1047
|
+
| "variant" NAME "{" { gene_ref "=" expr NL } "}" ;
|
|
1048
|
+
gene_ref = ( NAME | "background" | "dance" ) { "." NAME } ;
|
|
996
1049
|
|
|
997
1050
|
gene = "gene" NAME "=" expr [ gene_range ] NL ;
|
|
998
1051
|
gene_range = "in" expr ".." expr [ "step" expr | "log" ]
|
|
@@ -1054,7 +1107,7 @@ primary = NUMBER | HEX_COLOUR | STRING | "true" | "false"
|
|
|
1054
1107
|
| "turtle" "." NAME | "time" | "beat" | "music" "." NAME
|
|
1055
1108
|
| "(" expr ")"
|
|
1056
1109
|
| "(" expr "," expr "," expr ")"
|
|
1057
|
-
| "gradient" "(" stop "," stop { "," stop } ")" ;
|
|
1110
|
+
| ( "gradient" | "spectrum" ) "(" stop "," stop { "," stop } ")" ;
|
|
1058
1111
|
stop = expr [ "at" expr ] ;
|
|
1059
1112
|
args = expr { "," expr } ;
|
|
1060
1113
|
```
|