diff options
author | Karl Berry <karl@freefriends.org> | 2015-09-20 22:31:39 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2015-09-20 22:31:39 +0000 |
commit | 6dfa7943f147ffdfe5efdcb565b537bc91129e95 (patch) | |
tree | 391ecf22fdab020f51736958951596edca0707d4 /Master/texmf-dist/tex/latex | |
parent | b2ea7dce029df59615ef6bd98e335672bd219171 (diff) |
randomwalk (20sep15)
git-svn-id: svn://tug.org/texlive/trunk@38418 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex')
-rw-r--r-- | Master/texmf-dist/tex/latex/randomwalk/randomwalk.sty | 159 |
1 files changed, 87 insertions, 72 deletions
diff --git a/Master/texmf-dist/tex/latex/randomwalk/randomwalk.sty b/Master/texmf-dist/tex/latex/randomwalk/randomwalk.sty index 10ff54412c7..a960a1f17df 100644 --- a/Master/texmf-dist/tex/latex/randomwalk/randomwalk.sty +++ b/Master/texmf-dist/tex/latex/randomwalk/randomwalk.sty @@ -22,11 +22,11 @@ %% http://www.latex-project.org/lppl.txt %% %% ----------------------------------------------------------------------- -\RequirePackage{expl3}[2012/08/14] +\RequirePackage{expl3}[2015/09/11] \ProvidesExplPackage - {randomwalk.sty} {2015/03/03} {0.3} {Customizable random walks using TikZ} -\RequirePackage{xparse}[2012/08/14] -\RequirePackage{tikz} + {randomwalk.sty} {2015/09/20} {0.4} {Customizable random walks} +\RequirePackage{xparse}[2015/09/11] +\RequirePackage{pgfcore} \int_const:Nn \c__randomwalk_lcg_last_int { \c_max_int - \c_one } \AtBeginDocument { @@ -37,7 +37,7 @@ counter = lcg@rand ] { lcg } - \rand % This \rand avoids some very odd bug. + \rand } \tl_new:N \l__randomwalk_internal_tl \int_new:N \l__randomwalk_internal_int @@ -49,21 +49,32 @@ \cs_new_protected_nopar:Npn \__randomwalk_next_length: { } \fp_new:N \l__randomwalk_angle_fp \fp_new:N \l__randomwalk_length_fp -\fp_new:N \l__randomwalk_old_x_fp -\fp_new:N \l__randomwalk_old_y_fp -\fp_new:N \l__randomwalk_new_x_fp -\fp_new:N \l__randomwalk_new_y_fp +\dim_new:N \l__randomwalk_x_dim +\dim_new:N \l__randomwalk_y_dim \seq_new:N \l__randomwalk_angles_seq \seq_new:N \l__randomwalk_lengths_seq \DeclareDocumentCommand \RandomWalk { m } - { \randomwalk:n { #1 } } + { \randomwalk:n {#1} } \cs_new_protected:Npn \randomwalk:n #1 { - \__randomwalk_set_defaults: - \keys_set:nn { randomwalk } { #1 } + \__randomwalk_setup_defaults: + \keys_set:nn { randomwalk } {#1} \__randomwalk_walk: } -\cs_new:Npn \__randomwalk_set_defaults: +\keys_define:nn { randomwalk } + { + number .value_required:n = true , + length .value_required:n = true , + angles .value_required:n = true , + number .int_set:N = \l__randomwalk_step_number_int , + length .code:n = { \__randomwalk_setup_length:n {#1} } , + angles .code:n = { \__randomwalk_setup_angles:n {#1} } , + degree .bool_set:N = \l__randomwalk_degrees_bool , + degrees .bool_set:N = \l__randomwalk_degrees_bool , + angles-relative .bool_set:N = \l__randomwalk_relative_angles_bool , + revert-random .bool_set:N = \l__randomwalk_revert_random_bool , + } +\cs_new_protected_nopar:Npn \__randomwalk_setup_defaults: { \int_set:Nn \l__randomwalk_step_number_int {10} \cs_gset_protected_nopar:Npn \__randomwalk_next_angle: @@ -72,75 +83,79 @@ { \fp_set:Nn \l__randomwalk_length_fp {10} } \bool_set_false:N \l__randomwalk_revert_random_bool \bool_set_false:N \l__randomwalk_relative_angles_bool + \fp_zero:N \l__randomwalk_angle_fp + \fp_zero:N \l__randomwalk_length_fp + \dim_zero:N \l__randomwalk_x_dim + \dim_zero:N \l__randomwalk_y_dim } -\keys_define:nn { randomwalk } +\cs_new_protected:Npn \__randomwalk_setup_length:n #1 { - number .value_required: , - length .value_required: , - angles .value_required: , - number .int_set:N = \l__randomwalk_step_number_int , - length .code:n = + \seq_set_split:Nnn \l__randomwalk_lengths_seq { , } {#1} + \seq_set_map:NNn \l__randomwalk_lengths_seq + \l__randomwalk_lengths_seq { \dim_to_fp:n {##1} } + \cs_gset_protected_nopar:Npn \__randomwalk_next_length: { - \seq_set_split:Nnn \l__randomwalk_lengths_seq { , } {#1} - \seq_set_map:NNn \l__randomwalk_lengths_seq - \l__randomwalk_lengths_seq { \dim_to_fp:n {##1} } - \cs_gset_protected_nopar:Npn \__randomwalk_next_length: - { - \__randomwalk_get_rand_seq_item:NN - \l__randomwalk_lengths_seq \l__randomwalk_internal_tl - \fp_set:Nn \l__randomwalk_length_fp { \l__randomwalk_internal_tl } - } - } , - angles .code:n = + \__randomwalk_get_rand_seq_item:NN + \l__randomwalk_lengths_seq \l__randomwalk_internal_tl + \fp_set:Nn \l__randomwalk_length_fp { \l__randomwalk_internal_tl } + } + } +\cs_new_protected:Npn \__randomwalk_setup_angles:n #1 + { + \seq_set_split:Nnn \l__randomwalk_angles_seq { , } {#1} + \seq_set_map:NNn \l__randomwalk_angles_seq + \l__randomwalk_angles_seq { \fp_to_tl:n {##1} } + \cs_gset_protected_nopar:Npn \__randomwalk_next_angle: { - \seq_set_split:Nnn \l__randomwalk_angles_seq { , } {#1} - \seq_set_map:NNn \l__randomwalk_angles_seq - \l__randomwalk_angles_seq { \fp_to_tl:n {##1} } - \cs_gset_protected_nopar:Npn \__randomwalk_next_angle: - { - \__randomwalk_get_rand_seq_item:NN - \l__randomwalk_angles_seq \l__randomwalk_internal_tl - \bool_if:NF \l__randomwalk_degrees_bool - { \tl_put_right:Nn \l__randomwalk_internal_tl { rad } } - \bool_if:NTF \l__randomwalk_relative_angles_bool - { \fp_add:Nn } { \fp_set:Nn } - \l__randomwalk_angle_fp { \l__randomwalk_internal_tl } - } - } , - degree .bool_set:N = \l__randomwalk_degrees_bool , - degrees .bool_set:N = \l__randomwalk_degrees_bool , - angles-relative .bool_set:N = \l__randomwalk_relative_angles_bool , - revert-random .bool_set:N = \l__randomwalk_revert_random_bool , + \__randomwalk_get_rand_seq_item:NN + \l__randomwalk_angles_seq \l__randomwalk_internal_tl + \bool_if:NF \l__randomwalk_degrees_bool + { \tl_put_right:Nn \l__randomwalk_internal_tl { rad } } + \bool_if:NTF \l__randomwalk_relative_angles_bool + { \fp_add:Nn } { \fp_set:Nn } + \l__randomwalk_angle_fp { \l__randomwalk_internal_tl } + } + } +\cs_new_protected_nopar:Npn \__randomwalk_walk: + { + \__randomwalk_walk_start: + \prg_replicate:nn { \l__randomwalk_step_number_int } + { \__randomwalk_walk_step: } + \bool_if:NF \l__randomwalk_revert_random_bool + { \int_gset_eq:NN \cr@nd \cr@nd } + \__randomwalk_walk_stop: } -\cs_new:Npn \__randomwalk_walk: +\cs_new_protected_nopar:Npn \__randomwalk_walk_start: { - \begin{tikzpicture} - \fp_zero:N \l__randomwalk_angle_fp - \fp_zero:N \l__randomwalk_length_fp - \fp_zero:N \l__randomwalk_old_x_fp - \fp_zero:N \l__randomwalk_old_y_fp - \fp_zero:N \l__randomwalk_new_x_fp - \fp_zero:N \l__randomwalk_new_y_fp - \prg_replicate:nn { \l__randomwalk_step_number_int } - { \__randomwalk_step_draw: } - \bool_if:NF \l__randomwalk_revert_random_bool - { \int_gset_eq:NN \cr@nd \cr@nd } - \end{tikzpicture} + \begin{pgfpicture} + \pgfpathmoveto + { \pgfpoint { \l__randomwalk_x_dim } { \l__randomwalk_y_dim } } } -\cs_new:Npn \__randomwalk_step_draw: +\cs_new_protected_nopar:Npn \__randomwalk_walk_line: + { + \pgfpathlineto + { \pgfpoint { \l__randomwalk_x_dim } { \l__randomwalk_y_dim } } + } +\cs_new_protected_nopar:Npn \__randomwalk_walk_stop: + { + \pgfusepath { stroke } + \end{pgfpicture} + } +\cs_new_protected_nopar:Npn \__randomwalk_walk_step: { \__randomwalk_next_length: \__randomwalk_next_angle: - \fp_set_eq:NN \l__randomwalk_old_x_fp \l__randomwalk_new_x_fp - \fp_set_eq:NN \l__randomwalk_old_y_fp \l__randomwalk_new_y_fp - \fp_add:Nn \l__randomwalk_new_x_fp - { \l__randomwalk_length_fp * cosd \l__randomwalk_angle_fp } - \fp_add:Nn \l__randomwalk_new_y_fp - { \l__randomwalk_length_fp * sind \l__randomwalk_angle_fp } - \draw ( \fp_to_dim:N \l__randomwalk_old_x_fp , - \fp_to_dim:N \l__randomwalk_old_y_fp ) - -- ( \fp_to_dim:N \l__randomwalk_new_x_fp , - \fp_to_dim:N \l__randomwalk_new_y_fp ); + \dim_add:Nn \l__randomwalk_x_dim + { + \fp_to_dim:n + { \l__randomwalk_length_fp * cosd ( \l__randomwalk_angle_fp ) } + } + \dim_add:Nn \l__randomwalk_y_dim + { + \fp_to_dim:n + { \l__randomwalk_length_fp * sind ( \l__randomwalk_angle_fp ) } + } + \__randomwalk_walk_line: } \cs_new_protected:Npn \__randomwalk_fp_set_rand:Nnn #1#2#3 { |