mirror of https://github.com/Askill/r_place.git
drawing ref image
This commit is contained in:
parent
21e3de27df
commit
d7a1421236
|
|
@ -44,13 +44,11 @@ func get(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
defer c.Close()
|
||||
ticker := time.NewTicker(1 * time.Second)
|
||||
|
||||
var refImage = GetImage(img.width, img.height)
|
||||
var tmpImage = GetImage(img.width, img.height)
|
||||
|
||||
for range ticker.C {
|
||||
copy(refImage.pixels, img.pixels)
|
||||
diff := tmpImage.GetDiff(&refImage)
|
||||
|
||||
diff := tmpImage.GetDiff(&img)
|
||||
for i := 0; i < int(diff.width*diff.height); i++ {
|
||||
pix := diff.pixels[i]
|
||||
if pix.pixel.UserID != 0 {
|
||||
|
|
@ -70,7 +68,7 @@ func get(w http.ResponseWriter, r *http.Request) {
|
|||
if err := c.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
|
||||
return
|
||||
}
|
||||
copy(tmpImage.pixels, refImage.pixels)
|
||||
copy(tmpImage.pixels, img.pixels)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ func (img *image) SetPixel(message Message) int {
|
|||
fmt.Printf("User %d tried accessing out of bounds \n", message.UserID)
|
||||
return 1
|
||||
}
|
||||
if message.Color >= 16 || message.Color < 0 {
|
||||
if message.Color >= 255 || message.Color < 0 {
|
||||
fmt.Printf("User %d tried setting non existent color \n", message.UserID)
|
||||
return 1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import numpy as np
|
|||
|
||||
import websockets
|
||||
import cv2
|
||||
import matplotlib.image as mpimg
|
||||
|
||||
|
||||
@dataclass
|
||||
class pixel:
|
||||
|
|
@ -22,13 +24,15 @@ class pixel:
|
|||
timestamp: int
|
||||
userid: int
|
||||
|
||||
async def sender():
|
||||
async def sender(img):
|
||||
async with websockets.connect("ws://localhost:8080/set") as websocket:
|
||||
while True:
|
||||
rx = random.randint(0, 999)
|
||||
ry = random.randint(0, 999)
|
||||
message = pixel(
|
||||
x=random.randint(0, 999),
|
||||
y=random.randint(0, 999),
|
||||
color=random.randint(0,15),
|
||||
x=rx,
|
||||
y=ry,
|
||||
color=int(img[rx][ry][0]*255),
|
||||
timestamp=int(time.time()),
|
||||
userid=1,
|
||||
)
|
||||
|
|
@ -37,7 +41,7 @@ async def sender():
|
|||
if succ == "1":
|
||||
print(message, "was not set")
|
||||
|
||||
await asyncio.sleep(0.1)
|
||||
await asyncio.sleep(0.01)
|
||||
|
||||
async def client():
|
||||
image = np.zeros(shape=[1000, 1000, 3], dtype=np.uint8)
|
||||
|
|
@ -50,15 +54,18 @@ async def client():
|
|||
while True:
|
||||
i+=1
|
||||
x = pixel(**json.loads(await websocket.recv()))
|
||||
image[x.x][x.y] = ([y*255 for y in colors[x.color]])
|
||||
#if i% 4000 == 0:
|
||||
# cv2.imshow("changes x", image)
|
||||
# cv2.waitKey(10) & 0XFF
|
||||
#image[x.x][x.y] = ([y*255 for y in colors[x.color]])
|
||||
image[x.x][x.y] = ((x.color, x.color, x.color))
|
||||
if i% 1000 == 0:
|
||||
print("showing")
|
||||
cv2.imshow("changes x", image)
|
||||
cv2.waitKey(10) & 0XFF
|
||||
await websocket.send("1")
|
||||
#print(i, x)
|
||||
|
||||
async def main():
|
||||
coros = [sender() for _ in range(500)]
|
||||
img=mpimg.imread('logo.png')
|
||||
coros = [sender(img) for _ in range(10)]
|
||||
coros.append(client())
|
||||
returns = await asyncio.gather(*coros)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue