diff --git a/other/DynamicLines/DynamicLines.pyde b/other/DynamicLines/DynamicLines.pyde new file mode 100644 index 0000000..b9f7b88 --- /dev/null +++ b/other/DynamicLines/DynamicLines.pyde @@ -0,0 +1,71 @@ +import random, string + +def setup(): + size(1000, 1000) + frameRate(10000) + +curDraw = False +oldLines = [] +curStroke = 1 + +# Get the current line +def getCurLine(): + global startCurX, startCurY, curStroke + pg = createGraphics(width, height) + pg.beginDraw() + pg.fill(255, 0, 0) + pg.strokeWeight(curStroke) + pg.line(startCurX, startCurY, mouseX, mouseY) + pg.endDraw() + return pg + +# Start a new 'current line' and stop drawing the 'old lines' +def mousePressed(): + if mouseButton == LEFT: + global curDraw, startCurX, startCurY + curDraw = True + startCurX, startCurY = mouseX, mouseY + elif mouseButton == RIGHT: + global curStroke + if keyPressed: + if keyCode == SHIFT: + curStroke -= 1 + else: + curStroke += 1 + # if curStroke < 0: + # curStroke = 0 + print(curStroke) + +def keyPressed(): + print("keyPressed({})".format(key)) + if keyCode == BACKSPACE: + global oldLines + oldLines = [] + draw() + print("BACKSPACE pressed") + +def mouseReleased(): + if mouseButton == LEFT: + global curDraw, endCurX, endCurY, startCurX, startCurY, oldLines, curStroke + curDraw = False + endCurX, endCurY = mouseX, mouseY + compile = (startCurX, startCurY, endCurX, endCurY, curStroke) + oldLines.append(compile) + +# Get all old lines into a PGraphics Object +def getOldLines(): + global oldLines + pg = createGraphics(width, height) + pg.beginDraw() + for x1,y1,x2,y2,stroke in oldLines: + pg.strokeWeight(stroke) + pg.line(x1, y1, x2, y2) + pg.endDraw() + return pg + +def draw(): + global curDraw + background(204) + image(getOldLines(), 0, 0) + if curDraw: + image(getCurLine(), 0, 0) diff --git a/other/README.md b/other/README.md index cbd19dd..d8557ed 100644 --- a/other/README.md +++ b/other/README.md @@ -10,4 +10,6 @@ Other sketches without any specific purpose. If enough fit into a specific categ - **Clusters** - A test of a simple clusterization algorithm. -- **DVD Logo** - A fun little sketch displaying the iconic bouncing DVD Logo. May need a little more work to better visualize true-to-heart. \ No newline at end of file +- **DVD Logo** - A fun little sketch displaying the iconic bouncing DVD Logo. May need a little more work to better visualize true-to-heart. + +- **DynamicLines** - A very simple line drawing application. \ No newline at end of file