Text Size
Text Size
Exit Full Screen
Python Mini
Show
Source Code
View Source Code in Full Screen
Open in New Tab
from processing import * import firebase import time db = firebase.loadFirebase('AIzaSyCZ3tPJmKLqaDLwcN7Z44fPVeYkYAOasKc', 'fir-test-efbf9', 'fir-test-efbf9') players = {} orders = [] dots = [] xlen = 25 ylen = 25 tilew = 20 tileh = 20 def setup(): size(510, 510) background(0, 0, 0) def draw(): global orders, players, dots background(0, 0, 0) fill(255, 255, 255) for i in range(xlen): for j in range(ylen): rect(i * tilew, j * tileh, tilew, tileh) for order in orders: pid = order["pid"] if pid not in players: continue player= players[pid] command = order["command"].split() if command[0] == "goto": if len(command) == 3: player["x"] = int(command[1]) player["y"] = int(command[2]) elif command[0] == "draw": if len(command) == 4: dots.append({ "x": player["x"], "y": player["y"], "r": command[1], "g": command[2], "b": command[3] }) orders = [] # draw dots for dot in dots: fill(dot["r"], dot["g"], dot["b"]) rect(dot["x"] * tilew, dot["y"] * tileh, tilew, tileh) # draw players for pid in players.keys(): player = players[pid] r, g, b = player["color"] fill(r, g, b) ellipse(player["x"] * tilew + tilew/2.0, player["y"] * tileh + tileh/2.0, tilew, tileh) text(player["name"], (player["x"] + 1) * tilew, player["y"] * tileh) def enter_game(url, data): global players val = data["value"] # ignore players who joined game 10 mins ago if val["joints"] < time.time() - 6000: return pid = val["pid"] # val is dict, keys: pid, name, x, y, color, joints players[pid] = val def receive_order(url, data): global orders if not data: return orders.append(data["value"]) db.child_added("pixelart/player/", enter_game) db.child_added("pixelart/order/", receive_order) run()
pixelart-server.py
( around 74 lines python code )
Published By:
Bo Tinker
Published on
2016-08-18T19:34:10Z
Python Mini
- an
OYOclass
application,
own your own class today
.
Run
Result
×
Error message shows here