initial commit

This commit is contained in:
Nicole 2024-02-07 01:40:09 +01:00
commit 65bb7c3b45
2 changed files with 61 additions and 0 deletions

29
radio.py Normal file
View file

@ -0,0 +1,29 @@
import math
RADIO_IDLE = 0
RADIO_RX = 1
RADIO_TX = 2
RADIO_BUSY = 3
def distance(r1, r2):
a = abs(r1.x - r2.x)
b = abs(r1.y - r2.y)
return int(math.sqrt(a*a + b*b))
def neighbors(me, world, radius):
ney = []
for target in world:
if distance(me, target) <= radius:
ney.append(target)
return ney
class radio:
def __init__(self,x,y):
self.state = RADIO_IDLE
self.tick = 0
self.x = x
self.y = y
def tickle(self):
self.tick+=1

32
test.py Normal file
View file

@ -0,0 +1,32 @@
import random
import math
import radio
WORLD_X = 10000
WORLD_Y = 10000
radios = []
def print_map(rs):
for r in rs:
x = int(80 / WORLD_X * r.x)
y = int(25 / WORLD_Y * r.y)
print("\033[{0};{1}H{2}".format(y, x, "X"))
# print(x,y)
for i in range(10):
r = radio.radio(random.randint(0, WORLD_X), random.randint(0, WORLD_Y))
radios.append(r)
#for i in range(10):
# print(radios[i].x, radios[i].y)
print("\033[2J")
#for i in range(10):
# print(len(radio.neighbors(radios[i], radios, 2000)))
print_map(radios)
print("\033[{0};{1}H{2}".format(26, 0, ""))