mirror of
https://github.com/Xevion/processing-projects.git
synced 2025-12-06 01:15:57 -06:00
Dynamic Lines sketch
This commit is contained in:
71
other/DynamicLines/DynamicLines.pyde
Normal file
71
other/DynamicLines/DynamicLines.pyde
Normal 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)
|
||||||
@@ -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.
|
- **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.
|
- **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.
|
||||||
Reference in New Issue
Block a user