Dynamic Lines sketch

This commit is contained in:
Xevion
2019-10-15 13:20:47 -05:00
parent 3a30444ecc
commit 59aff8e609
2 changed files with 74 additions and 1 deletions

View File

@@ -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)

View File

@@ -11,3 +11,5 @@ 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.
- **DynamicLines** - A very simple line drawing application.