File: bsp.wl

package info (click to toggle)
wadc 3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 7,352 kB
  • sloc: java: 3,808; ansic: 1,950; xml: 135; makefile: 67; sh: 34
file content (87 lines) | stat: -rw-r--r-- 1,639 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * bsp.wl: binary space partitioning experiment
 * part of WadC
 *
 * Copyright © 2019 Jonathan Dowland <jon@dow.land>
 *
 * Distributed under the terms of the GNU GPL Version 2
 * See file LICENSE.txt
 */

#"standard.h"

minseg  { 512 }
minroom  { 128 }

size { knob("size", 0, 2048, 8192) }

main
{
    seed(rand(0,1337))
    bsp(size, size, 0)
    pushpop( movestep(32,32) thing)
}

-- always split vertically (rotate in recursion)
bsp(x, y, depth)
{
    bsp_(x, y, depth, rand(minseg,sub(y,minseg)))
}
bsp_(x, y, depth, _split)
{
    drawseg(x, y) -- DEBUG
    movestep(0,_split)
    rotleft

    ifelse(lessthaneq(_split, minseg),
       room(_split, x, depth),
       bsp(_split, x, add(depth,1))
    )

    rotright
    movestep(x,0) 
    rotright

    ifelse(lessthaneq(_split, minseg),
        room(sub(y,_split), x, depth),
        bsp(sub(y,_split), x, add(depth,1))
    )

    rotright
    movestep(x,_split)
    turnaround
}

-- just a box, but smaller than the space given.
room(w, h, depth)
{
    print(cat(w,cat(",",h)))    
      _room(ifelse(lessthaneq(w,minroom), w, rand(minroom, w)),
            ifelse(lessthaneq(h,minroom), h, rand(minroom, h)),
            depth)
}
_room(_w, _h, depth)
{
    print(cat("    ",cat(_w,cat(",",_h))))    
    box(sub(0, mul(depth,8)), 128, 160, _w,_h)
}

drawseg(x, y)
{
  straight(x)
  right(y)
  right(x)
  right(y)
  rotright
}

/* bad seeds:

    -1246253629
    -1231509699

	need a separate minquad number for controlling recursion, from a minsize argument
 	for room size generation (done)

	rooms can still be adjacent, so perhaps always sub an additional 8 from sizes
*/