mirror of https://github.com/Askill/r_place.git
plotting image
This commit is contained in:
parent
5177c4b601
commit
dd4414ff0d
|
|
@ -14,7 +14,7 @@ var upgrader = websocket.Upgrader{
|
||||||
ReadBufferSize: 2048,
|
ReadBufferSize: 2048,
|
||||||
WriteBufferSize: 2048,
|
WriteBufferSize: 2048,
|
||||||
}
|
}
|
||||||
var img = GetImage(1000, 1000)
|
var img = GetImage(100, 100)
|
||||||
|
|
||||||
func get(w http.ResponseWriter, r *http.Request) {
|
func get(w http.ResponseWriter, r *http.Request) {
|
||||||
c, err := upgrader.Upgrade(w, r, nil)
|
c, err := upgrader.Upgrade(w, r, nil)
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,12 @@ import datetime
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
|
import matplotlib
|
||||||
|
from matplotlib import pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
import websockets
|
import websockets
|
||||||
|
import cv2
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class pixel:
|
class pixel:
|
||||||
|
|
@ -23,9 +26,9 @@ async def sender():
|
||||||
async with websockets.connect("ws://localhost:8080/set") as websocket:
|
async with websockets.connect("ws://localhost:8080/set") as websocket:
|
||||||
while True:
|
while True:
|
||||||
message = pixel(
|
message = pixel(
|
||||||
x=random.randint(0, 990),
|
x=random.randint(0, 99),
|
||||||
y=random.randint(0, 990),
|
y=random.randint(0, 99),
|
||||||
color=random.randint(0,15),
|
color=random.randint(0,11),
|
||||||
timestamp=int(time.time()),
|
timestamp=int(time.time()),
|
||||||
userid=1,
|
userid=1,
|
||||||
)
|
)
|
||||||
|
|
@ -34,15 +37,24 @@ async def sender():
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
|
|
||||||
async def client():
|
async def client():
|
||||||
|
image = np.zeros(shape=[100, 100, 3], dtype=np.uint8)
|
||||||
|
colors = []
|
||||||
|
for name, hex in matplotlib.colors.cnames.items():
|
||||||
|
colors.append(matplotlib.colors.to_rgb(hex))
|
||||||
|
|
||||||
async with websockets.connect("ws://localhost:8080/get") as websocket:
|
async with websockets.connect("ws://localhost:8080/get") as websocket:
|
||||||
i= 0
|
i= 0
|
||||||
while True:
|
while True:
|
||||||
i+=1
|
i+=1
|
||||||
x = await websocket.recv()
|
x = pixel(**json.loads(await websocket.recv()))
|
||||||
#print(i, x)
|
image[x.x][x.y] = ([y*255 for y in colors[x.color]])
|
||||||
|
if i% 1000 == 0:
|
||||||
|
cv2.imshow("changes x", image)
|
||||||
|
cv2.waitKey(10) & 0XFF
|
||||||
|
print(i, x)
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
coros = [sender() for _ in range(500)]
|
coros = [sender() for _ in range(100)]
|
||||||
coros.append(client())
|
coros.append(client())
|
||||||
returns = await asyncio.gather(*coros)
|
returns = await asyncio.gather(*coros)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
websockets
|
websockets
|
||||||
numpy
|
numpy
|
||||||
matplotlib
|
matplotlib
|
||||||
|
opencv-python
|
||||||
Loading…
Reference in New Issue