Paste: dragon curve

Author: dondy
Mode: factor
Date: Tue, 12 Feb 2013 22:22:35
Plain Text |
! Copyright (C) 2013 Dondy.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math math.functions locals vectors sequences prettyprint ;
IN: foobar

:: zig ( p1 p2 -- p3 )
    p1 first :> x1 p1 last :> y1
    p2 first :> x2 p2 last :> y2
    V{ }
    x1 x2 + y1 y2 - + 2 / suffix
    x2 x1 - y1 y2 + + 2 / suffix ;

:: zag ( p1 p2 -- p3 )
    p1 first :> x1 p1 last :> y1
    p2 first :> x2 p2 last :> y2
    V{ }
    x1 x2 + y1 y2 + - 2 / suffix
    x1 x2 - y1 y2 + + 2 / suffix ;

:: dragon ( p1 p2 p3 n -- p1 p2 )
    n 0 = [
        V{ p1 p2 }
        append
    ] [
        V{ }
        p1 p1 p2 zig p2 n 1 - dragon suffix
        p2 p2 p3 zag p3 n 1 - dragon suffix
        append
    ] if ;

: foobar ( -- )
    V{ }
    [let
        V{ 100 100 } :> p1
        V{ 356 100 } :> p2
        p1 p1 p2 zig p2 15 dragon ]
        
    . ;

MAIN: foobar
! throws the following error
! The word main cannot be executed because it failed to compile
! 
! Stack effect declaration is wrong
! inferred ( -- x x )
! declared ( -- )
! 
! Type :help for debugging help.
! :errors - show 2 compiler errors

Annotation: pewpew

Author: dondy
Mode: factor
Date: Tue, 12 Feb 2013 22:48:38
Plain Text |
! Copyright (C) 2013 Dondy.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math math.functions locals vectors sequences prettyprint ;
IN: foobar

:: zig ( p1 p2 -- p3 )
    p1 first :> x1 p1 last :> y1
    p2 first :> x2 p2 last :> y2
    V{ } clone
    x1 x2 + y1 y2 - + 2 / suffix
    x2 x1 - y1 y2 + + 2 / suffix ;

:: zag ( p1 p2 -- p3 )
    p1 first :> x1 p1 last :> y1
    p2 first :> x2 p2 last :> y2
    V{ } clone
    x1 x2 + y1 y2 + - 2 / suffix
    x1 x2 - y1 y2 + + 2 / suffix ;

:: dragon ( p1 p2 p3 n -- seq )
    n 0 = [
        V{ p1 p2 }
        push-all
    ] [
        V{ } clone
        p1 p1 p2 zig p2 n 1 - dragon suffix
        p2 p2 p3 zag p3 n 1 - dragon suffix
        push-all
    ] if ;

: foobar ( -- )
    [let
        V{ 100 100 } :> p1
        V{ 356 100 } :> p2
        p1 p1 p2 zig p2 15 dragon ]
    . ;

MAIN: foobar
! The word dragon cannot be executed because it failed to compile
!
! Stack effect declaration is wrong
! inferred ( x x x x x -- x )
! declared ( p1 p2 p3 n -- seq )

! Type :help for debugging help.
! :errors - show 1 compiler errors

Annotation: asdfasdf

Author: dondy
Mode: factor
Date: Tue, 12 Feb 2013 23:03:11
Plain Text |
! Copyright (C) 2013 Dondy.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math math.functions locals vectors sequences prettyprint ;
IN: foobar

:: zig ( p1 p2 -- p3 )
    p1 first2 :> ( x1 y1 )
    p2 first2 :> ( x2 y2 )
    V{ } clone
    x1 x2 + y1 y2 - + 2 / suffix
    x2 x1 - y1 y2 + + 2 / suffix ;

:: zag ( p1 p2 -- p3 )
    p1 first2 :> ( x1 y1 )
    p2 first2 :> ( x2 y2 )
    V{ } clone
    x1 x2 + y1 y2 + - 2 / suffix
    x1 x2 - y1 y2 + + 2 / suffix ;

:: dragon ( p1 p2 p3 n seq -- seq )
    n 0 = [
        V{ } clone
        p1 suffix
        p2 suffix
        push-all
    ] [
        V{ } clone
        p1 p1 p2 zig p2 n 1 - dragon suffix
        p2 p2 p3 zag p3 n 1 - dragon suffix
        push-all
    ] if ;

: foobar ( -- )
    V{ } clone
    [let
        V{ 100 100 } :> p1
        V{ 356 100 } :> p2
        p1 p1 p2 zig p2 15 dragon ]
    . ;

MAIN: foobar

Annotation: asdf

Author: erg
Mode: factor
Date: Tue, 12 Feb 2013 23:18:36
Plain Text |
USING: arrays kernel locals math sequences ;
IN: foobar

:: zig ( p1 p2 -- p3 )
    p1 first2 :> ( x1 y1 )
    p2 first2 :> ( x2 y2 )
    x1 x2 + y1 y2 - + 2 / 
    x2 x1 - y1 y2 + + 2 / 2array ;

:: zag ( p1 p2 -- p3 )
    p1 first2 :> ( x1 y1 )
    p2 first2 :> ( x2 y2 )
    x1 x2 + y1 y2 + - 2 /
    x1 x2 - y1 y2 + + 2 / 2array ;

:: dragon ( p1 p2 p3 n -- seq )
    n 0 = [
        p1 p2 2array 
    ] [
        p1 p1 p2 zig p2 n 1 - dragon
        p2 p2 p3 zag p3 n 1 - dragon 2array
    ] if ;

: foobar ( -- seq )
    [let
        { 100 100 } :> p1
        { 356 100 } :> p2
        p1 p1 p2 zig p2 15 dragon ] ;

New Annotation

Summary:
Author:
Mode:
Body: