From 5c1755f1a0f831c449ec1d6a52c0a7b021ff40b6 Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Sat, 30 Mar 2013 10:41:40 +0000 Subject: [PATCH] Added buttons --- DisplayMachine.pde | 62 +++++++++++++++++++-------------- Panel.pde | 3 ++ controlsActions.pde | 18 ++++++++++ controlsSetup.pde | 46 ++++++++++++++++++++++++ polargraphcontroller_webcam.pde | 30 ++++++++++++++++ tabSetup.pde | 4 +-- 6 files changed, 135 insertions(+), 28 deletions(-) diff --git a/DisplayMachine.pde b/DisplayMachine.pde index 669e819..c058d09 100644 --- a/DisplayMachine.pde +++ b/DisplayMachine.pde @@ -352,40 +352,17 @@ class DisplayMachine extends Machine noStroke(); // draw machine outline -// fill(80); -// rect(getOutline().getLeft()+DROP_SHADOW_DISTANCE, getOutline().getTop()+DROP_SHADOW_DISTANCE, getOutline().getWidth(), getOutline().getHeight()); - fill(getMachineColour()); rect(getOutline().getLeft(), getOutline().getTop(), getOutline().getWidth(), getOutline().getHeight()); - - -// if (displayingGuides) -// { -// // draw some guides -// stroke(getGuideColour()); -// strokeWeight(1); -// // centre line -// line(getOutline().getLeft()+(getOutline().getWidth()/2), getOutline().getTop(), -// getOutline().getLeft()+(getOutline().getWidth()/2), getOutline().getBottom()); -// -// // page top line -// line(getOutline().getLeft(), getOutline().getTop()+sc(getHomePoint().y), -// getOutline().getRight(), getOutline().getTop()+sc(getHomePoint().y)); -// } - // draw page fill(getPageColour()); rect(getOutline().getLeft()+sc(getPage().getLeft()), getOutline().getTop()+sc(getPage().getTop()), sc(getPage().getWidth()), sc(getPage().getHeight())); - text("page " + getDimensionsAsText(getPage()), getOutline().getLeft()+sc(getPage().getLeft()), - getOutline().getTop()+sc(getPage().getTop())-3); noFill(); - - stroke(getBackgroundColour(),150); strokeWeight(3); noFill(); @@ -406,12 +383,11 @@ class DisplayMachine extends Machine if (drawingLiveVideo) { - drawLiveVideo(); + displayLiveVideo(); } if (displayingVector && getVectorShape() != null) { - stroke(100); displayVectorImage(color(200)); } @@ -427,7 +403,41 @@ class DisplayMachine extends Machine { cursor(ARROW); } - } + } + + public void displayLiveVideo() + { + buildLiveImage(); + // draw actual image + if (liveImage != null) + { + float ox = getOutline().getLeft()+sc(getImageFrame().getLeft()); + float oy = getOutline().getTop()+sc(getImageFrame().getTop()); + float w = sc(getImageFrame().getWidth()); + float h = sc(getImageFrame().getHeight()); + tint(255, getImageTransparency()); + translate(ox, oy); + rotate(radians(270)); + image(liveImage, 0, 0, w, h); + rotate(radians(-270)); + translate(-ox,-oy); + noTint(); + noFill(); + } + } + + public void buildLiveImage() + { + liveCamera.update(); + liveImage = createImage(640,480, RGB); + liveImage.loadPixels(); + // rotate it + liveImage.pixels = liveCamera.image(); + liveImage.filter(BLUR, blurValue); + liveImage.filter(GRAY); + liveImage.filter(POSTERIZE, posterizeValue); + liveImage.updatePixels(); + } public void displayVectorImage() { diff --git a/Panel.pde b/Panel.pde index e562d3e..03d5f8d 100644 --- a/Panel.pde +++ b/Panel.pde @@ -131,10 +131,13 @@ class Panel { for (Controller c : this.getControls()) { + println("Control: " + c.name()); PVector pos = getControlPositions().get(c.name()); float x = pos.x+getOutline().getLeft(); float y = pos.y+getOutline().getTop(); c.setPosition(x, y); + + println("controlsizes: " + getControlSizes()); PVector cSize = getControlSizes().get(c.name()); c.setSize((int)cSize.x, (int)cSize.y); diff --git a/controlsActions.pde b/controlsActions.pde index e51e1ca..3d35d57 100644 --- a/controlsActions.pde +++ b/controlsActions.pde @@ -108,6 +108,24 @@ void button_mode_sendPenliftRange() addToCommandQueue(CMD_SETPENLIFTRANGE+penLiftDownPosition+","+penLiftUpPosition+",END"); } +void numberbox_mode_liveBlurValue(int value) +{ + blurValue = value; +} +void numberbox_mode_liveSimplificationValue(int value) +{ + liveSimplification = value; +} +void numberbox_mode_livePosteriseValue(int value) +{ + posterizeValue = value; +} +void button_mode_liveCaptureFromLive() +{ + addToCommandQueue(CMD_SETPENLIFTRANGE+penLiftDownPosition+","+penLiftUpPosition+",END"); +} + + void toggle_mode_inputBoxTopLeft(boolean flag) { if (flag) diff --git a/controlsSetup.pde b/controlsSetup.pde index 6b9c0d4..c8c256e 100644 --- a/controlsSetup.pde +++ b/controlsSetup.pde @@ -469,6 +469,30 @@ Map initialiseNumberboxValues(Map map) n.setMax(360); n.setMultiplier(0.1); } + else if (MODE_LIVE_BLUR_VALUE.equals(key)) + { + n.setDecimalPrecision(1); + n.setValue(blurValue); + n.setMin(1); + n.setMax(100); + n.setMultiplier(0.1); + } + else if (MODE_LIVE_SIMPLIFICATION_VALUE.equals(key)) + { + n.setDecimalPrecision(1); + n.setValue(liveSimplification); + n.setMin(0); + n.setMax(360); + n.setMultiplier(0.1); + } + else if (MODE_LIVE_POSTERISE_VALUE.equals(key)) + { + n.setDecimalPrecision(1); + n.setValue(posterizeValue); + n.setMin(2); + n.setMax(32); + n.setMultiplier(0.1); + } } } return map; @@ -586,6 +610,7 @@ Map> buildControlsForPanels() map.put(PANEL_NAME_DETAILS, getControllersForControllerNames(getControlNamesForDetailPanel())); map.put(PANEL_NAME_QUEUE, getControllersForControllerNames(getControlNamesForQueuePanel())); map.put(PANEL_NAME_GENERAL, getControllersForControllerNames(getControlNamesForGeneralPanel())); + map.put(PANEL_NAME_WEBCAM, getControllersForControllerNames(getControlNamesForWebcamPanel())); return map; } @@ -669,6 +694,16 @@ List getControlNamesForRovingPanel() return controlNames; } +List getControlNamesForWebcamPanel() +{ + List controlNames = new ArrayList(); + controlNames.add(MODE_LIVE_BLUR_VALUE); + controlNames.add(MODE_LIVE_SIMPLIFICATION_VALUE); + controlNames.add(MODE_LIVE_POSTERISE_VALUE); + controlNames.add(MODE_LIVE_CAPTURE_FROM_LIVE); + return controlNames; +} + List getControlNamesForDetailPanel() { List controlNames = new ArrayList(); @@ -862,6 +897,12 @@ Map buildControlLabels() result.put(MODE_START_RANDOM_SPRITES, "Random sprites"); result.put(MODE_STOP_RANDOM_SPRITES, "Stop sprites"); result.put(MODE_DRAW_NORWEGIAN_DIALOG, "Draw norwegian..."); + + result.put(MODE_LIVE_BLUR_VALUE, "Blur"); + result.put(MODE_LIVE_SIMPLIFICATION_VALUE, "Simplify"); + result.put(MODE_LIVE_POSTERISE_VALUE, "Posterise"); + result.put(MODE_LIVE_CAPTURE_FROM_LIVE, "Capture"); + return result; } @@ -987,6 +1028,11 @@ Set buildControlNames() result.add(MODE_STOP_RANDOM_SPRITES); result.add(MODE_DRAW_NORWEGIAN_DIALOG); + result.add(MODE_LIVE_BLUR_VALUE); + result.add(MODE_LIVE_SIMPLIFICATION_VALUE); + result.add(MODE_LIVE_POSTERISE_VALUE); + result.add(MODE_LIVE_CAPTURE_FROM_LIVE); + return result; } diff --git a/polargraphcontroller_webcam.pde b/polargraphcontroller_webcam.pde index 5cb4a5c..117f949 100644 --- a/polargraphcontroller_webcam.pde +++ b/polargraphcontroller_webcam.pde @@ -306,6 +306,12 @@ static final String MODE_START_RANDOM_SPRITES = "button_mode_startRandomSprite"; static final String MODE_STOP_RANDOM_SPRITES = "button_mode_stopRandomSprites"; static final String MODE_DRAW_NORWEGIAN_DIALOG = "button_mode_drawNorwegianDialog"; +static final String MODE_LIVE_BLUR_VALUE = "numberbox_mode_liveBlurValue"; +static final String MODE_LIVE_SIMPLIFICATION_VALUE = "numberbox_mode_liveSimplificationValue"; +static final String MODE_LIVE_POSTERISE_VALUE = "numberbox_mode_livePosteriseValue"; +static final String MODE_LIVE_CAPTURE_FROM_LIVE = "button_mode_liveCaptureFromLive"; + + PVector statusTextPosition = new PVector(240.0, 12.0); static String currentMode = MODE_BEGIN; @@ -442,6 +448,18 @@ boolean overwriteExistingStoreFile = true; public static Console console; public boolean useWindowedConsole = false; +static boolean drawingLiveVideo = true; + +static PImage liveImage = null; +JMyron liveCamera; +BlobDetector blob_detector; +int liveSimplification = 0; +int blurValue = 1; +int posterizeValue = 6; +Set colours = null; +List colourList = null; + + void setup() { println("Running polargraph controller"); @@ -510,6 +528,17 @@ void setup() changeTab(TAB_NAME_INPUT, TAB_NAME_INPUT); addEventListeners(); + + liveCamera = new JMyron(); + liveCamera.start(640,480); + + blob_detector = new BlobDetector( 640, 480); + blob_detector.setResolution(1); + blob_detector.computeContours(true); + blob_detector.computeBlobPixels(true); + blob_detector.setMinMaxPixels(10*10, 640*480); + + blob_detector.setBLOBable(new BLOBable_blueBlobs(liveImage)); } void addEventListeners() @@ -766,6 +795,7 @@ void drawWebcamPage() for (Panel panel : getPanelsForTab(TAB_NAME_WEBCAM)) { + println("Panel:" + panel); panel.draw(); } text(propertiesFilename, getPanel(PANEL_NAME_GENERAL).getOutline().getLeft(), getPanel(PANEL_NAME_GENERAL).getOutline().getTop()-7); diff --git a/tabSetup.pde b/tabSetup.pde index 82866c1..56194ae 100644 --- a/tabSetup.pde +++ b/tabSetup.pde @@ -72,7 +72,7 @@ Map> buildPanelsForTabs() List buildTabNames() { - List list = new ArrayList(4); + List list = new ArrayList(5); list.add(TAB_NAME_INPUT); list.add(TAB_NAME_ROVING); list.add(TAB_NAME_WEBCAM); @@ -106,7 +106,7 @@ void initTabs() public Set buildPanelNames() { - Set set = new HashSet(5); + Set set = new HashSet(6); set.add(PANEL_NAME_INPUT); set.add(PANEL_NAME_ROVING); set.add(PANEL_NAME_WEBCAM);