-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
53 lines (43 loc) · 1.44 KB
/
Copy pathutils.py
File metadata and controls
53 lines (43 loc) · 1.44 KB
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
import random
import math
import noise
def get_random_position(width, height):
return random.randint(0, width - 1), random.randint(0, height - 1)
def distance(x1, y1, x2, y2):
return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
def is_visible(x1, y1, x2, y2, radius, world):
dx = abs(x2 - x1)
dy = abs(y2 - y1)
# Check if the point is within the elliptical radius
if (dx / 2) ** 2 + dy ** 2 > radius ** 2:
return False
# Perform ray-casting
steps = max(dx, dy)
if steps == 0:
return True
dx = (x2 - x1) / steps
dy = (y2 - y1) / steps
x, y = x1, y1
for _ in range(int(steps)):
check_x, check_y = round(x), round(y)
if 0 <= check_x < world.width and 0 <= check_y < world.height:
if world.is_obstacle(check_x, check_y):
return False
x += dx
y += dy
return True
def generate_perlin_noise(x, y, t, scale=0.1, octaves=6, persistence=0.5, lacunarity=2.0):
return noise.pnoise3(x * scale,
y * scale,
t * scale,
octaves=octaves,
persistence=persistence,
lacunarity=lacunarity,
repeatx=1024,
repeaty=1024,
base=0)
def get_wave_char(value):
if value <= 0:
return '-'
else:
return '='