Last active
July 6, 2019 15:59
-
-
Save KrabCode/75f6b6687cef591107304e0ce7527e54 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PGraphics canvas; | |
| void setup() { | |
| fullScreen(P2D); | |
| canvas = createGraphics(width*2, height*2, P2D); | |
| canvas.beginDraw(); | |
| canvas.colorMode(HSB, 1, 1, 1, 1); | |
| canvas.background(0); | |
| canvas.endDraw(); | |
| } | |
| void draw() { | |
| float timeSpeed = .05; | |
| float canvasAngle = frameCount*timeSpeed; | |
| canvas.beginDraw(); | |
| canvas.rectMode(CORNER); | |
| canvas.blendMode(SUBTRACT); | |
| canvas.noStroke(); | |
| canvas.fill(1, 0.004); | |
| canvas.rect(0, 0, canvas.width, canvas.height); | |
| canvas.blendMode(REPLACE); | |
| canvas.stroke(1); | |
| canvas.strokeWeight(5); | |
| if (mousePressed) { | |
| canvas.translate(canvas.width/2, canvas.height/2); | |
| canvas.rotate(canvasAngle); | |
| canvas.translate(-width/2, -height/2); | |
| //I'd like to say line(mouseX, mouseY, pmouseX, pmouseY) here but pmouseX and pmouseY won't suffice here | |
| //because the canvas has already rotated so we have to find their positions on the canvas one frame ago | |
| float d = dist(pmouseX, pmouseY, width/2, height/2); | |
| float a = atan2(pmouseY-height/2, pmouseX-width/2); | |
| PVector prev = new PVector(width/2+d*cos(a-timeSpeed), height/2+d*sin(a-timeSpeed)); | |
| canvas.line(mouseX, mouseY, prev.x, prev.y); | |
| } | |
| canvas.endDraw(); | |
| background(0); | |
| imageMode(CENTER); | |
| translate(width/2, height/2); | |
| rotate(-canvasAngle); | |
| image(canvas, 0, 0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment