<commit_before>USING: accessors arrays byte-arrays combinators
combinators.short-circuit fry hints images kernel locals math
math.affine-transforms math.functions math.order
math.polynomials math.private math.vectors random
random.mersenne-twister sequences sequences.private
sequences.product ;
IN: noise

: <perlin-noise-table> ( -- table )
    256 iota >byte-array randomize dup append ; inline

: with-seed ( seed quot -- )
    [ <mersenne-twister> ] dip with-random ; inline

<PRIVATE

: (fade) ( x y z -- x' y' z' )
    [ { 0.0 0.0 0.0 10.0 -15.0 6.0 } polyval* ] tri@ ;

HINTS: (fade) { float float float } ;

: fade ( point -- point' )
    first3 (fade) 3array ; inline

:: grad ( hash x y z -- gradient )
    hash 8  bitand zero? [ x ] [ y ] if
        :> u
    hash 12 bitand zero?
    [ y ] [ hash 13 bitand 12 = [ x ] [ z ] if ] if
        :> v

    hash 1 bitand zero? [ u ] [ u neg ] if
    hash 2 bitand zero? [ v ] [ v neg ] if + ;

HINTS: grad { fixnum float float float } ;

: unit-cube ( point -- cube )
    [ floor >fixnum 256 rem ] map ;

:: hashes ( table x y z -- aaa baa aba bba aab bab abb bbb )
    x               table nth-unsafe y fixnum+fast :> a
    x 1 fixnum+fast table nth-unsafe y fixnum+fast :> b

    a               table nth-unsafe z fixnum+fast :> aa
    b               table nth-unsafe z fixnum+fast :> ba
    a 1 fixnum+fast table nth-unsafe z fixnum+fast :> ab
    b 1 fixnum+fast table nth-unsafe z fixnum+fast :> bb

    aa               table nth-unsafe 
    ba               table nth-unsafe 
    ab               table nth-unsafe 
    bb               table nth-unsafe 
    aa 1 fixnum+fast table nth-unsafe 
    ba 1 fixnum+fast table nth-unsafe 
    ab 1 fixnum+fast table nth-unsafe 
    bb 1 fixnum+fast table nth-unsafe ; inline

HINTS: hashes { byte-array fixnum fixnum fixnum } ;

: >byte-map ( floats -- bytes )
    [ 255.0 * >fixnum ] B{ } map-as ;

: >image ( bytes dim -- image )
    image new
        swap >>dim
        swap >>bitmap<commit_msg>noise: don't use math.private words<commit_after>USING: accessors arrays byte-arrays combinators
combinators.short-circuit fry hints images kernel locals math
math.affine-transforms math.functions math.order math.polynomials
math.vectors random random.mersenne-twister sequences
sequences.private sequences.product ;
IN: noise

: <perlin-noise-table> ( -- table )
    256 iota >byte-array randomize dup append ; inline

: with-seed ( seed quot -- )
    [ <mersenne-twister> ] dip with-random ; inline

<PRIVATE

: (fade) ( x y z -- x' y' z' )
    [ { 0.0 0.0 0.0 10.0 -15.0 6.0 } polyval* ] tri@ ;

HINTS: (fade) { float float float } ;

: fade ( point -- point' )
    first3 (fade) 3array ; inline

:: grad ( hash x y z -- gradient )
    hash 8  bitand zero? [ x ] [ y ] if
        :> u
    hash 12 bitand zero?
    [ y ] [ hash 13 bitand 12 = [ x ] [ z ] if ] if
        :> v

    hash 1 bitand zero? [ u ] [ u neg ] if
    hash 2 bitand zero? [ v ] [ v neg ] if + ;

HINTS: grad { fixnum float float float } ;

: unit-cube ( point -- cube )
    [ floor 256 rem ] map ;

:: hashes ( table x y z -- aaa baa aba bba aab bab abb bbb )
    x      table nth-unsafe y + :> a
    x  1 + table nth-unsafe y + :> b

    a      table nth-unsafe z + :> aa
    b      table nth-unsafe z + :> ba
    a  1 + table nth-unsafe z + :> ab
    b  1 + table nth-unsafe z + :> bb

    aa     table nth-unsafe
    ba     table nth-unsafe
    ab     table nth-unsafe
    bb     table nth-unsafe
    aa 1 + table nth-unsafe
    ba 1 + table nth-unsafe
    ab 1 + table nth-unsafe
    bb 1 + table nth-unsafe ; inline

HINTS: hashes { byte-array fixnum fixnum fixnum } ;

: >byte-map ( floats -- bytes )
    [ 255.0 * >fixnum ] B{ } map-as ;

: >image ( bytes dim -- image )
    image new
        swap >>dim
        swap >>bitmap
{'fraction_non_alphanumeric': 0.11201469045120671, 'fraction_numerical': 0.022035676810073453, 'mean_word_length': 2.070048309178744, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3360954', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1317, 'n_words': 464}