Add new images

master
Sameer 6 years ago committed by Sameer Puri
parent 439f4859b8
commit dbf46ef01b

@ -1,6 +1,6 @@
# L-systems in Rust
Renderings of various L-systems using Rust and Cairo.
Renderings of various L-systems using Rust and Cairo. Special thanks goes to [Paul Bourke](http://paulbourke.net/fractals/lsys/) and the [L-systems Wikipedia page](https://en.wikipedia.org/wiki/L-system) for the systems below
## Sierpinski Triangle
![sierpinski](out/sierpinski.svg)
@ -13,3 +13,27 @@ Renderings of various L-systems using Rust and Cairo.
## Dragon Curve
![dragon](out/dragon.svg)
## Fractal Plant (Wikipedia)
![plant](out/plant.svg)
## Moore Curve
![moore](out/moore.svg)
## Hilbert Curve
![hilbert](out/hilbert.svg)
## Sierpinski Carpet
![sierpinski_capret](out/sierpinski_carpet.svg)
## Koch Snowflake
![snowflake](out/snowflake.svg)
## Hexagonal Gosper
![gosper](out/gosper.svg)
## Kolam
![kolam](out/kolam.svg)
## Crystal
![crystal](out/crystal.svg)

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 14 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 36 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 79 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 40 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 63 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1024pt" height="1024pt" viewBox="0 0 1024 1024" version="1.1">
<g id="surface51">
<path style="fill:none;stroke-width:0.001;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 0.5 0.5 L 0.496464 0.496464 L 0.482319 0.510609 L 0.478783 0.507072 L 0.492928 0.492928 L 0.489391 0.489391 L 0.475246 0.503536 L 0.464638 0.492928 L 0.478783 0.478783 L 0.475246 0.475246 L 0.461102 0.489391 L 0.457565 0.485855 L 0.47171 0.47171 L 0.468174 0.468174 L 0.464638 0.47171 L 0.478783 0.485855 L 0.475246 0.489391 L 0.461102 0.475246 L 0.457565 0.478783 L 0.47171 0.492928 L 0.461102 0.503536 L 0.446957 0.489391 L 0.44342 0.492928 L 0.457565 0.507072 L 0.454029 0.510609 L 0.439884 0.496464 L 0.429276 0.507072 L 0.44342 0.521217 L 0.439884 0.524754 L 0.425739 0.510609 L 0.422203 0.514145 L 0.436348 0.52829 L 0.425739 0.538898 L 0.411594 0.524754 L 0.408058 0.52829 L 0.422203 0.542435 L 0.418667 0.545971 L 0.404522 0.531826 L 0.400986 0.535362 L 0.404522 0.538898 L 0.418667 0.524754 L 0.422203 0.52829 L 0.408058 0.542435 L 0.411594 0.545971 L 0.425739 0.531826 L 0.436348 0.542435 L 0.422203 0.55658 L 0.425739 0.560116 L 0.439884 0.545971 L 0.44342 0.549507 L 0.429276 0.563652 L 0.432812 0.567188 L 0.436348 0.563652 L 0.422203 0.549507 L 0.425739 0.545971 L 0.439884 0.560116 L 0.44342 0.55658 L 0.429276 0.542435 L 0.439884 0.531826 L 0.454029 0.545971 L 0.457565 0.542435 L 0.44342 0.52829 L 0.446957 0.524754 L 0.461102 0.538898 L 0.464638 0.535362 L 0.461102 0.531826 L 0.446957 0.545971 L 0.44342 0.542435 L 0.457565 0.52829 L 0.454029 0.524754 L 0.439884 0.538898 L 0.429276 0.52829 L 0.44342 0.514145 L 0.439884 0.510609 L 0.425739 0.524754 L 0.422203 0.521217 L 0.436348 0.507072 L 0.425739 0.496464 L 0.411594 0.510609 L 0.408058 0.507072 L 0.422203 0.492928 L 0.418667 0.489391 L 0.404522 0.503536 L 0.393913 0.492928 L 0.408058 0.478783 L 0.404522 0.475246 L 0.390377 0.489391 L 0.386841 0.485855 L 0.400986 0.47171 L 0.397449 0.468174 L 0.393913 0.47171 L 0.408058 0.485855 L 0.404522 0.489391 L 0.390377 0.475246 L 0.386841 0.478783 L 0.400986 0.492928 L 0.390377 0.503536 L 0.376232 0.489391 L 0.372696 0.492928 L 0.386841 0.507072 L 0.383305 0.510609 L 0.36916 0.496464 L 0.365623 0.5 L 0.36916 0.503536 L 0.383305 0.489391 L 0.386841 0.492928 L 0.372696 0.507072 L 0.376232 0.510609 L 0.390377 0.496464 L 0.400986 0.507072 L 0.386841 0.521217 L 0.390377 0.524754 L 0.404522 0.510609 L 0.408058 0.514145 L 0.393913 0.52829 L 0.397449 0.531826 L 0.400986 0.52829 L 0.386841 0.514145 L 0.390377 0.510609 L 0.404522 0.524754 L 0.408058 0.521217 L 0.393913 0.507072 L 0.404522 0.496464 L 0.418667 0.510609 L 0.422203 0.507072 L 0.408058 0.492928 L 0.411594 0.489391 L 0.425739 0.503536 L 0.436348 0.492928 L 0.422203 0.478783 L 0.425739 0.475246 L 0.439884 0.489391 L 0.44342 0.485855 L 0.429276 0.47171 L 0.439884 0.461102 L 0.454029 0.475246 L 0.457565 0.47171 L 0.44342 0.457565 L 0.446957 0.454029 L 0.461102 0.468174 L 0.464638 0.464638 L 0.461102 0.461102 L 0.446957 0.475246 L 0.44342 0.47171 L 0.457565 0.457565 L 0.454029 0.454029 L 0.439884 0.468174 L 0.429276 0.457565 L 0.44342 0.44342 L 0.439884 0.439884 L 0.425739 0.454029 L 0.422203 0.450493 L 0.436348 0.436348 L 0.432812 0.432812 L 0.429276 0.436348 L 0.44342 0.450493 L 0.439884 0.454029 L 0.425739 0.439884 L 0.422203 0.44342 L 0.436348 0.457565 L 0.425739 0.468174 L 0.411594 0.454029 L 0.408058 0.457565 L 0.422203 0.47171 L 0.418667 0.475246 L 0.404522 0.461102 L 0.400986 0.464638 L 0.404522 0.468174 L 0.418667 0.454029 L 0.422203 0.457565 L 0.408058 0.47171 L 0.411594 0.475246 L 0.425739 0.461102 L 0.436348 0.47171 L 0.422203 0.485855 L 0.425739 0.489391 L 0.439884 0.475246 L 0.44342 0.478783 L 0.429276 0.492928 L 0.439884 0.503536 L 0.454029 0.489391 L 0.457565 0.492928 L 0.44342 0.507072 L 0.446957 0.510609 L 0.461102 0.496464 L 0.47171 0.507072 L 0.457565 0.521217 L 0.461102 0.524754 L 0.475246 0.510609 L 0.478783 0.514145 L 0.464638 0.52829 L 0.468174 0.531826 L 0.47171 0.52829 L 0.457565 0.514145 L 0.461102 0.510609 L 0.475246 0.524754 L 0.478783 0.521217 L 0.464638 0.507072 L 0.475246 0.496464 L 0.489391 0.510609 L 0.492928 0.507072 L 0.478783 0.492928 L 0.482319 0.489391 L 0.496464 0.503536 L 0.5 0.5 " transform="matrix(1024,0,0,1024,0,0)"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.3 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 63 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 28 KiB

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1024pt" height="1024pt" viewBox="0 0 1024 1024" version="1.1">
<g id="surface6">
<path style="fill:none;stroke-width:0.001;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M -0.433013 -0.25 L -0.438012 -0.241341 L -0.443011 -0.250002 L -0.44801 -0.241343 L -0.43801 -0.241345 L -0.443009 -0.232686 L -0.453007 -0.250007 L -0.458006 -0.241348 L -0.463004 -0.250009 L -0.468004 -0.24135 L -0.458004 -0.241352 L -0.463003 -0.232693 L -0.443003 -0.232696 L -0.448003 -0.224037 L -0.453001 -0.232698 L -0.458 -0.224039 L -0.448001 -0.22404 L -0.453 -0.215381 L -0.472995 -0.250024 L -0.477994 -0.241365 L -0.482992 -0.250026 L -0.487992 -0.241367 L -0.477992 -0.241369 L -0.482991 -0.23271 L -0.492988 -0.250031 L -0.497988 -0.241373 L -0.502986 -0.250033 L -0.507985 -0.241375 L -0.497986 -0.241376 L -0.502985 -0.232717 L -0.482985 -0.23272 L -0.487984 -0.224061 L -0.492983 -0.232722 L -0.497982 -0.224063 L -0.487983 -0.224064 L -0.492982 -0.215406 L -0.452983 -0.215411 L -0.457982 -0.206752 L -0.46298 -0.215413 L -0.46798 -0.206754 L -0.45798 -0.206756 L -0.462979 -0.198097 L -0.472976 -0.215418 L -0.477976 -0.206759 L -0.482974 -0.21542 L -0.487973 -0.206761 L -0.477974 -0.206763 L -0.482973 -0.198104 L -0.462973 -0.198107 L -0.467972 -0.189448 L -0.472971 -0.198109 L -0.47797 -0.18945 L -0.467971 -0.189451 L -0.47297 -0.180792 L -0.512959 -0.250078 L -0.517958 -0.241419 L -0.522957 -0.25008 L -0.527956 -0.241421 L -0.517957 -0.241423 L -0.522956 -0.232764 L -0.532953 -0.250085 L -0.537952 -0.241427 L -0.542951 -0.250087 L -0.54795 -0.241429 L -0.53795 -0.24143 L -0.54295 -0.232771 L -0.52295 -0.232774 L -0.527949 -0.224115 L -0.532948 -0.232776 L -0.537947 -0.224117 L -0.527947 -0.224118 L -0.532946 -0.21546 L -0.552941 -0.250102 L -0.55794 -0.241444 L -0.562939 -0.250104 L -0.567938 -0.241446 L -0.557938 -0.241447 L -0.562938 -0.232788 L -0.572935 -0.25011 L -0.577934 -0.241451 L -0.582933 -0.250112 L -0.587932 -0.241453 L -0.577932 -0.241454 L -0.582931 -0.232795 L -0.562932 -0.232798 L -0.567931 -0.224139 L -0.57293 -0.2328 L -0.577929 -0.224141 L -0.567929 -0.224143 L -0.572928 -0.215484 L -0.532929 -0.215489 L -0.537928 -0.20683 L -0.542927 -0.215491 L -0.547926 -0.206832 L -0.537926 -0.206834 L -0.542926 -0.198175 L -0.552923 -0.215496 L -0.557922 -0.206838 L -0.562921 -0.215498 L -0.56792 -0.20684 L -0.55792 -0.206841 L -0.562919 -0.198182 L -0.54292 -0.198185 L -0.547919 -0.189526 L -0.552918 -0.198187 L -0.557917 -0.189528 L -0.547917 -0.189529 L -0.552916 -0.180871 L -0.472918 -0.180882 L -0.477917 -0.172223 L -0.482916 -0.180883 L -0.487915 -0.172225 L -0.477916 -0.172226 L -0.482915 -0.163567 L -0.492912 -0.180889 L -0.497911 -0.17223 L -0.50291 -0.180891 L -0.507909 -0.172232 L -0.497909 -0.172233 L -0.502908 -0.163574 L -0.482909 -0.163577 L -0.487908 -0.154918 L -0.492907 -0.163579 L -0.497906 -0.15492 L -0.487906 -0.154922 L -0.492905 -0.146263 L -0.5129 -0.180906 L -0.517899 -0.172247 L -0.522898 -0.180908 L -0.527897 -0.172249 L -0.517897 -0.17225 L -0.522897 -0.163592 L -0.532894 -0.180913 L -0.537893 -0.172254 L -0.542892 -0.180915 L -0.547891 -0.172256 L -0.537891 -0.172257 L -0.54289 -0.163599 L -0.522891 -0.163601 L -0.52789 -0.154943 L -0.532889 -0.163603 L -0.537888 -0.154945 L -0.527888 -0.154946 L -0.532887 -0.146287 L -0.492888 -0.146293 L -0.497887 -0.137634 L -0.502886 -0.146295 L -0.507885 -0.137636 L -0.497885 -0.137637 L -0.502885 -0.128978 L -0.512882 -0.1463 L -0.517881 -0.137641 L -0.52288 -0.146302 L -0.527879 -0.137643 L -0.517879 -0.137644 L -0.522878 -0.128985 L -0.502879 -0.128988 L -0.507878 -0.120329 L -0.512877 -0.12899 L -0.517876 -0.120331 L -0.507876 -0.120333 L -0.512875 -0.111674 L -0.592854 -0.250246 L -0.432858 -0.250268 " transform="matrix(-512,-886.810013,886.810013,-512,0,0)"/>
<path style="fill:none;stroke-width:0.001;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 0.5 0.5 L 0.5 0.494999 L 0.49567 0.497498 L 0.49567 0.492496 L 0.5 0.494995 L 0.5 0.489994 L 0.491341 0.494991 L 0.491341 0.48999 L 0.487011 0.492489 L 0.487011 0.487488 L 0.491341 0.489986 L 0.491341 0.484985 L 0.5 0.489983 L 0.5 0.484982 L 0.49567 0.48748 L 0.49567 0.482479 L 0.5 0.484978 L 0.5 0.479977 L 0.482681 0.489971 L 0.482681 0.48497 L 0.478352 0.487469 L 0.478352 0.482468 L 0.482681 0.484966 L 0.482681 0.479965 L 0.474022 0.484962 L 0.474022 0.479961 L 0.469692 0.48246 L 0.469692 0.477459 L 0.474022 0.479958 L 0.474022 0.474957 L 0.482681 0.479954 L 0.482681 0.474953 L 0.478352 0.477451 L 0.478352 0.47245 L 0.482681 0.474949 L 0.482681 0.469948 L 0.5 0.479942 L 0.5 0.474941 L 0.49567 0.47744 L 0.49567 0.472439 L 0.5 0.474937 L 0.5 0.469936 L 0.491341 0.474934 L 0.491341 0.469933 L 0.487011 0.472431 L 0.487011 0.46743 L 0.491341 0.469929 L 0.491341 0.464928 L 0.5 0.469925 L 0.5 0.464924 L 0.49567 0.467422 L 0.49567 0.462421 L 0.5 0.46492 L 0.5 0.459919 L 0.465363 0.479908 L 0.465363 0.474907 L 0.461033 0.477406 L 0.461033 0.472404 L 0.465363 0.474903 L 0.465363 0.469902 L 0.456703 0.474899 L 0.456703 0.469898 L 0.452374 0.472397 L 0.452374 0.467396 L 0.456703 0.469894 L 0.456703 0.464893 L 0.465363 0.469891 L 0.465363 0.46489 L 0.461033 0.467388 L 0.461033 0.462387 L 0.465363 0.464886 L 0.465363 0.459885 L 0.448044 0.469879 L 0.448044 0.464878 L 0.443714 0.467377 L 0.443714 0.462376 L 0.448044 0.464874 L 0.448044 0.459873 L 0.439384 0.46487 L 0.439384 0.459869 L 0.435055 0.462368 L 0.435055 0.457367 L 0.439384 0.459866 L 0.439384 0.454865 L 0.448044 0.459862 L 0.448044 0.454861 L 0.443714 0.457359 L 0.443714 0.452358 L 0.448044 0.454857 L 0.448044 0.449856 L 0.465363 0.45985 L 0.465363 0.454849 L 0.461033 0.457348 L 0.461033 0.452347 L 0.465363 0.454845 L 0.465363 0.449844 L 0.456703 0.454842 L 0.456703 0.449841 L 0.452374 0.452339 L 0.452374 0.447338 L 0.456703 0.449837 L 0.456703 0.444836 L 0.465363 0.449833 L 0.465363 0.444832 L 0.461033 0.44733 L 0.461033 0.442329 L 0.465363 0.444828 L 0.465363 0.439827 L 0.5 0.459816 L 0.5 0.454815 L 0.49567 0.457314 L 0.49567 0.452312 L 0.5 0.454811 L 0.5 0.44981 L 0.491341 0.454807 L 0.491341 0.449806 L 0.487011 0.452305 L 0.487011 0.447304 L 0.491341 0.449802 L 0.491341 0.444801 L 0.5 0.449799 L 0.5 0.444798 L 0.49567 0.447296 L 0.49567 0.442295 L 0.5 0.444794 L 0.5 0.439793 L 0.482681 0.449787 L 0.482681 0.444786 L 0.478352 0.447285 L 0.478352 0.442284 L 0.482681 0.444782 L 0.482681 0.439781 L 0.474022 0.444778 L 0.474022 0.439777 L 0.469692 0.442276 L 0.469692 0.437275 L 0.474022 0.439774 L 0.474022 0.434772 L 0.482681 0.43977 L 0.482681 0.434769 L 0.478352 0.437267 L 0.478352 0.432266 L 0.482681 0.434765 L 0.482681 0.429764 L 0.5 0.439758 L 0.5 0.434757 L 0.49567 0.437256 L 0.49567 0.432255 L 0.5 0.434753 L 0.5 0.429752 L 0.491341 0.43475 L 0.491341 0.429749 L 0.487011 0.432247 L 0.487011 0.427246 L 0.491341 0.429745 L 0.491341 0.424744 L 0.5 0.429741 L 0.5 0.42474 L 0.49567 0.427238 L 0.49567 0.422237 L 0.5 0.424736 L 0.5 0.419735 L 0.430725 0.459713 L 0.5 0.499691 " transform="matrix(1024,0,0,1024,0,0)"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 123 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 15 KiB

@ -9,10 +9,18 @@ fn main() {
sierpinski();
arrowhead();
dragon();
plant();
moore();
hilbert();
sierpinski_carpet();
snowflake();
gosper();
kolam();
crystal();
}
fn koch() {
let mut out = File::create("koch.svg").unwrap();
let mut out = File::create("out/koch.svg").unwrap();
run(
"F",
&['F'],
@ -27,7 +35,7 @@ fn koch() {
}
fn sierpinski() {
let mut out = File::create("sierpinski.svg").unwrap();
let mut out = File::create("out/sierpinski.svg").unwrap();
run(
"F-G-G",
&['F', 'G'],
@ -43,7 +51,7 @@ fn sierpinski() {
}
fn arrowhead() {
let mut out = File::create("arrowhead.svg").unwrap();
let mut out = File::create("out/arrowhead.svg").unwrap();
run(
"A",
&['A', 'B'],
@ -53,13 +61,13 @@ fn arrowhead() {
other => vec![other],
},
std::f64::consts::PI * 1. / 3.,
4,
6,
&mut out,
);
}
fn dragon() {
let mut out = File::create("dragon.svg").unwrap();
let mut out = File::create("out/dragon.svg").unwrap();
run(
"FX",
&['F'],
@ -69,13 +77,146 @@ fn dragon() {
other => vec![other],
},
std::f64::consts::PI / 2.,
10,
12,
&mut out,
);
}
fn plant() {
let mut out = File::create("out/plant.svg").unwrap();
run(
"X",
&['F'],
|c: char| match c {
'X' => "F-[[X]+X]+F[+FX]-X".chars().collect(),
'F' => "FF".chars().collect(),
other => vec![other],
},
std::f64::consts::PI * 25.0 / 180.0,
5,
&mut out,
);
}
fn moore() {
let mut out = File::create("out/moore.svg").unwrap();
run(
"LFL+F+LFL",
&['F'],
|c: char| match c {
'L' => "-RF+LFL+FR-".chars().collect(),
'R' => "+LF-RFR-FL+".chars().collect(),
other => vec![other],
},
std::f64::consts::PI * 90.0 / 180.0,
5,
&mut out,
);
}
fn run<F, W>(axiom: &str, variables: &[char], rules: F, angle: f64, iterations: usize, writer: W)
where
fn hilbert() {
let mut out = File::create("out/hilbert.svg").unwrap();
run(
"A",
&['F'],
|c: char| match c {
'A' => "-BF+AFA+FB-".chars().collect(),
'B' => "+AF-BFB-FA+".chars().collect(),
other => vec![other],
},
std::f64::consts::PI / 2.0,
6,
&mut out,
);
}
fn sierpinski_carpet() {
let mut out = File::create("out/sierpinski_carpet.svg").unwrap();
run(
"F+F+F+F",
&['F'],
|c: char| match c {
'F' => "FF+F+F+F+FF".chars().collect(),
other => vec![other],
},
std::f64::consts::PI / 2.,
4,
&mut out,
);
}
fn snowflake() {
let mut out = File::create("out/snowflake.svg").unwrap();
run(
"F++F++F",
&['F'],
|c: char| match c {
'F' => "F-F++F-F".chars().collect(),
other => vec![other],
},
std::f64::consts::PI / 3.,
4,
&mut out,
);
}
fn gosper() {
let mut out = File::create("out/gosper.svg").unwrap();
run(
"XF",
&['F'],
|c: char| match c {
'X' => "X+YF++YF-FX--FXFX-YF+".chars().collect(),
'Y' => "-FX+YFYF++YF+FX--FX-Y".chars().collect(),
other => vec![other],
},
std::f64::consts::PI / 3.,
4,
&mut out,
);
}
fn kolam() {
let mut out = File::create("out/kolam.svg").unwrap();
run(
"-D--D",
&['F'],
|c: char| match c {
'A' => "F++FFFF--F--FFFF++F++FFFF--F".chars().collect(),
'B' => "F--FFFF++F++FFFF--F--FFFF++F".chars().collect(),
'C' => "BFA--BFA".chars().collect(),
'D' => "CFC--CFC".chars().collect(),
other => vec![other],
},
std::f64::consts::PI / 4.0,
6,
&mut out,
);
}
fn crystal() {
let mut out = File::create("out/crystal.svg").unwrap();
run(
"F+F+F+F",
&['F'],
|c: char| match c {
'F' => "FF+F++F+F".chars().collect(),
other => vec![other],
},
std::f64::consts::PI / 2.,
4,
&mut out,
);
}
fn run<F, W>(
axiom: &str,
variables_to_draw: &[char],
rules: F,
angle: f64,
iterations: usize,
writer: W,
) where
F: Fn(char) -> Vec<char> + Copy,
W: Write,
{
@ -94,26 +235,36 @@ where
// let segment_count = state.chars().filter(|c| variables.contains(&c)).count();
ctx.move_to(0.0, 0.5);
ctx.move_to(0.5, 0.5);
let mut stack: Vec<((f64, f64), f64)> = vec![];
let mut curangle = -std::f64::consts::PI / 2.0;
for c in state.chars() {
match c {
'+' => {
ctx.rotate(-angle);
// ctx.rotate(angle);
curangle += angle;
}
'-' => {
ctx.rotate(angle);
// ctx.rotate(-angle);
curangle -= angle;
}
'|' => {
curangle = -curangle;
}
'[' => {
stack.push((ctx.get_current_point(), curangle));
}
']' => {
let state = stack.pop().unwrap();
ctx.move_to((state.0).0, (state.0).1);
curangle = state.1;
}
other => {
if variables.contains(&other) {
ctx.rel_line_to(0.01, 0.0);
if variables_to_draw.contains(&other) {
ctx.rel_line_to(0.005 * f64::cos(curangle), 0.005 * f64::sin(curangle));
}
}
}
}
ctx.stroke();
// let mut fout = File::create("out.png").unwrap();
// surf.write_all(&mut fout).unwrap();
// println!("{}", axiom);
}

Loading…
Cancel
Save