summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustyna Att Ilczuk <justyna.ilczuk@gmail.com>2012-11-11 18:06:19 +0100
committerJustyna Att Ilczuk <justyna.ilczuk@gmail.com>2012-11-11 18:06:19 +0100
commit8bd6089f9aa2657939db9f794f43e9f89978cb8e (patch)
treebddafed59be459adb1c77d7712bf89bc74082422
parent3f60dfa460b44493d8e6cdb37265373e9281dc97 (diff)
downloadlaserz_und_stuff-8bd6089f9aa2657939db9f794f43e9f89978cb8e.tar.gz
laserz_und_stuff-8bd6089f9aa2657939db9f794f43e9f89978cb8e.tar.bz2
laserz_und_stuff-8bd6089f9aa2657939db9f794f43e9f89978cb8e.zip
Camera is working!
-rw-r--r--Lasers_und_stuff/main.py38
-rw-r--r--Lasers_und_stuff/main.pycbin9032 -> 9997 bytes
-rw-r--r--Lasers_und_stuff/templates/status.html64
3 files changed, 85 insertions, 17 deletions
diff --git a/Lasers_und_stuff/main.py b/Lasers_und_stuff/main.py
index 55962e4..f652b37 100644
--- a/Lasers_und_stuff/main.py
+++ b/Lasers_und_stuff/main.py
@@ -14,10 +14,15 @@ import json
from pygame.locals import *
from Cannon import HackWAWCannonController
from Cannon import Gunpoint
+import pygame.camera
app = flask.Flask(__name__)
app.debug = True
pygame.init()
+pygame.camera.init()
+
+CAMERA_X = 400
+CAMERA_Y = 30
cannon = None
@@ -41,17 +46,32 @@ def move_down(amount):
cannon.move_down(amount)
return "OK"
+@app.route("/fire/", methods=["POST"])
+def fire():
+ cannon.fire();
+
+@app.route("/stop_fire/", methods=["POST"])
+def stop_fire():
+ cannon.fired = False;
+
@app.route("/status")
def status():
return json.dumps(cannon.get_data())
@app.route("/")
def root():
-
return flask.render_template("status.html", data=cannon.get_data())
+
+
+#Camera stuff
+
+camera = pygame.camera.Camera("/dev/video0", (640, 480))
+camera.start()
+
+
def main():
#create the screen
- window = pygame.display.set_mode((800, 600))
+ window = pygame.display.set_mode((1200, 800))
GRAY = ( 182, 182, 182)
VIOLET = (150, 100, 190)
@@ -71,6 +91,7 @@ def main():
gunpoint = Gunpoint((5, 4), (200, 4), (5, 210))
+
keep_running = True
while keep_running:
screen.draw_surface(cannon)
@@ -115,6 +136,14 @@ def main():
screen.communicates.append("Calibrated")
elif event.type == MOUSEBUTTONUP:
+ mousex, mousey = pygame.mouse.get_pos()
+ print mousex, mousey
+ x = (mousex - CAMERA_X)/640.0
+ y = (CAMERA_Y + 480 - mousey)/480.0
+ print x, y
+ position = gunpoint.aim((x, y))
+ print position
+ cannon.position = position
screen.change_color()
print "Pygame thread exited."
os.kill(os.getpid(), signal.SIGINT)
@@ -202,7 +231,10 @@ class Screen:
if cannon.fired:
self.print_text("Fired!", 20, 150, (150, 20, 40), 40, self.window)
- self.print_text([str(x) for x in cannon.get_data()].__str__(), 20, 300, (0, 0, 0), 30, self.window)
+ self.print_text([str(x) for x in cannon.get_data()].__str__(), 20, 300, (0, 0, 0), 30, self.window)
+ image = camera.get_image()
+ self.window.blit(image, (CAMERA_X, CAMERA_Y))
+
pygame.display.flip()
def print_text(self, text,xx,yy,color,text_size, screen):
diff --git a/Lasers_und_stuff/main.pyc b/Lasers_und_stuff/main.pyc
index 223d4cb..5cec598 100644
--- a/Lasers_und_stuff/main.pyc
+++ b/Lasers_und_stuff/main.pyc
Binary files differ
diff --git a/Lasers_und_stuff/templates/status.html b/Lasers_und_stuff/templates/status.html
index 233476b..0b1b24d 100644
--- a/Lasers_und_stuff/templates/status.html
+++ b/Lasers_und_stuff/templates/status.html
@@ -2,33 +2,69 @@
{% block body %}
<script type=text/javascript src="{{url_for('static', filename='jquery.min.js') }}"> </script>
<script type=text/javascript>
- $(document).ready(function(){
- //
- $('#dupa').text("I like bananas");
- });
- function pop_banana() {
- $('#banana').html('<a href="http://ranchochilamate.com/wp/wp-content/uploads/2010/10/banana.jpg">Click</a>');
+ function update() {
+ update_status();
+ window.setTimeout(update, 100000000);
}
+ $("document").ready(function(data) {
+ update();
+ });
+
+ function move_right() {
$.post("/right/20", function(data) {
- $('#dupa').html(data);
+ update_status();
+ });
+ }
+
+ function move_left() {
+ $.post("/left/20", function(data) {
+ update_status();
});
+ }
+
+ function move_down() {
+ $.post("/down/20", function(data) {
+ update_status();
+ });
+ }
function move_up() {
$.post("{{url_for('move_up', amount="20")}}", function(data) {
- $('#dupa').html(data);
+ update_status();
});
}
+
+ function fire() {
+ $.post("/fire", function(data) {
+
+ });
+ }
+
+ function stop_fire() {
+ $.post("/stop_fire", function(data) {
+
+ });
+ }
+
+ function update_status() {
+ $.get("/status", function(data) {
+ $('#status').html(data);
+ });
+ }
+
</script>
<div style="width: 400px; height: 400px; margin-top: -200px; margin-left: -200px; position: absolute; top: 50%; left: 50%;">
+ <h2>Hello in cannon controller, adjust angles!</h2>
+ <p>Angles can be in range 0:255</p>
<a onclick="move_up()">Up</a>
- <a href="/down/20">Down</a>
- <a href="/left/20">Left</a>
- <a href ="/right/20"" onclick="move_right()">Right</a>
- <p id="dupa" onclick="move_right()"></p>
- <p id="banana"></p>
- <h2>Status</h2> <p>{{data}}</p></div>
+ <a onclick="move_down()">Down</a>
+ <a onclick="move_left()">Left</a>
+ <a onclick="move_right()">Right</a>
+ <p><a onclick="fire()">Fire!</a> <a onclick="stop_fire()">Stop</a></p>
+
+ <h2>Status: </h2> <p id="status">{{data}}</p></div>
</body>
{% endblock %} \ No newline at end of file