let pointsOgLocation = [];
let prevHandlesOgLocation = [];
let nextHandlesOgLocation = [];
let singleSelectedPoint = false;
let selectionKey = false;
let selectionFull = false;
let selectionSquareOrigin;
let functionType = PROCESSING;
let canvasLoaded = false;
centerPointPos = createVector(0, 0);
selectionSquareOrigin = createVector(0, 0);
squareTopCorner = createVector(0, 0);
for(let i = 0; i <= width; i += gridSize){
for(let i = 0; i <= height; i += gridSize){
for (let i = 0; i < points.length; i++) {
if (grabedPointId == i) {
if (mouseX == points[i].x) {
line(points[i].x, 0, points[i].x, height);
if (mouseY == points[i].y) {
line(0, points[i].y, width, points[i].y);
vertex(points[0].x, points[0].y);
vertex(points[0].x, points[0].y);
for (let i = 0; i < points.length - 1; i++) {
nextHandles[i].x, nextHandles[i].y,
prevHandles[i + 1].x, prevHandles[i + 1].y,
points[i + 1].x, points[i + 1].y
if (mode == CREATE && !handlePos && !plusKey) {
bezier(points[points.length - 1].x, points[points.length - 1].y, nextHandles[nextHandles.length - 1].x, nextHandles[nextHandles.length - 1].y, mouseX, mouseY, mouseX, mouseY);
if (mode == GRAB && selectionKey && mouseButton == RIGHT && showSquare) {
rect(selectionSquareOrigin.x, selectionSquareOrigin.y, mouseX, mouseY);
squareWidth = dist(mouseX, 0, selectionSquareOrigin.x, 0);
squareHeight = dist(0, mouseY, 0, selectionSquareOrigin.y);
if (selectionSquareOrigin.x <= mouseX) {
squareTopCorner.x = selectionSquareOrigin.x;
squareTopCorner.x = mouseX;
} if (selectionSquareOrigin.y <= mouseY) {
squareTopCorner.y = selectionSquareOrigin.y;
squareTopCorner.y = mouseY;
if (selectionKey && mode == GRAB) {
for (let i = 0; i < selectedPoints.length; i++) {
ellipse(points[selectedPoints[i]].x, points[selectedPoints[i]].y, 25, 25);
line(points[lastAdded].x, points[lastAdded].y, prevHandles[lastAdded].x, prevHandles[lastAdded].y);
line(points[lastAdded].x, points[lastAdded].y, nextHandles[lastAdded].x, nextHandles[lastAdded].y);
for (let i = 0; i < points.length; i++) {
circle(points[i].x, points[i].y, 10);
if (singlePoint[0] != undefined) {
singlePoint[0].x = mouseX;
singlePoint[0].y = mouseY;
line(points[i].x, points[i].y, prevHandles[i].x, prevHandles[i].y);
line(points[i].x, points[i].y, nextHandles[i].x, nextHandles[i].y);
if (mousePress && mouseButton == LEFT) {
if (mouseX >= points[i].x - 5 && mouseX <= points[i].x + 5 && mouseY >= points[i].y - 5 && mouseY <= points[i].y + 5) {
singlePoint[0] = points[i];
} else if (mouseX >= prevHandles[i].x - 5 && mouseX <= prevHandles[i].x + 5 && mouseY >= prevHandles[i].y - 5 && mouseY <= prevHandles[i].y + 5) {
singlePoint[0] = prevHandles[i];
} else if (mouseX >= nextHandles[i].x - 5 && mouseX <= nextHandles[i].x + 5 && mouseY >= nextHandles[i].y - 5 && mouseY <= nextHandles[i].y + 5) {
singlePoint[0] = nextHandles[i];
grabedPointId = undefined;
if (singlePoint[0] == points[i]) {
prevHandles[i].x = points[i].x + (prevHandlesOgLocation[i].x - pointsOgLocation[i].x);
prevHandles[i].y = points[i].y + (prevHandlesOgLocation[i].y - pointsOgLocation[i].y);
nextHandles[i].x = points[i].x + (nextHandlesOgLocation[i].x - pointsOgLocation[i].x);
nextHandles[i].y = points[i].y + (nextHandlesOgLocation[i].y - pointsOgLocation[i].y);
if (singlePoint[0] == prevHandles[i]) {
nextHandles[i].x = points[i].x - (mouseX - points[i].x);
nextHandles[i].y = points[i].y - (mouseY - points[i].y);
if (singlePoint[0] == nextHandles[i]) {
prevHandles[i].x = points[i].x - (mouseX - points[i].x);
prevHandles[i].y = points[i].y - (mouseY - points[i].y);
if (selectionKey && mode == GRAB && mousePress) {
for (let i = 0; i < selectedPoints.length; i++) {
points[selectedPoints[i]].x = pointsOgLocation[selectedPoints[i]].x + offsetX;
points[selectedPoints[i]].y = pointsOgLocation[selectedPoints[i]].y + offsetY;
prevHandles[selectedPoints[i]].x = points[selectedPoints[i]].x + (prevHandlesOgLocation[selectedPoints[i]].x - pointsOgLocation[selectedPoints[i]].x);
prevHandles[selectedPoints[i]].y = points[selectedPoints[i]].y + (prevHandlesOgLocation[selectedPoints[i]].y - pointsOgLocation[selectedPoints[i]].y);
nextHandles[selectedPoints[i]].x = points[selectedPoints[i]].x + (nextHandlesOgLocation[selectedPoints[i]].x - pointsOgLocation[selectedPoints[i]].x);
nextHandles[selectedPoints[i]].y = points[selectedPoints[i]].y + (nextHandlesOgLocation[selectedPoints[i]].y - pointsOgLocation[selectedPoints[i]].y);
ellipse(centerPointPos.x, centerPointPos.y, 20, 20);
if (mousePress && mouseX >= centerPointPos.x - 10 && mouseX <= centerPointPos.x + 10 && mouseY >= centerPointPos.y - 10 && mouseY <= centerPointPos.y + 10) {
singlePoint[0] = centerPointPos;
toggleTracker[0] = toggleTracker[1];
toggleTracker[1] = document.querySelector('input:checked');
if (document.querySelector('input:checked') !== null) {
functionType = PROCESSING;
if (document.querySelector('.type').innerText != 'PROCESSING')
document.querySelector('.type').innerText = 'PROCESSING';
document.querySelector('.type').classList.add("processing");
document.querySelector('.type').classList.remove("p5js");
document.querySelector('button').classList.add("processing");
document.querySelector('button').classList.remove("p5js");
if (document.querySelector('.type').innerText != 'P5.JS')
document.querySelector('.type').innerText = 'P5.JS';
document.querySelector('.type').classList.add("p5js");
document.querySelector('.type').classList.remove("processing");
document.querySelector('button').classList.add("p5js");
document.querySelector('button').classList.remove("processing");
if (toggleTracker[0] != toggleTracker[1]) {
if (DOMLoaded && canvasLoaded) {
document.querySelector("main").addEventListener('contextmenu', (e) => {
if (key == 'a' || key == 'A') {
} else if (key == 's' || key == 'S') {
} else if (key == 'd' || key == 'D') {
if (key == '=' || key == '+') {
if(key == 'g' || key == 'G'){
if (key == '=' || key == '+') {
function mousePressed() {
if (mouseButton == RIGHT && selectionKey) {
selectionSquareOrigin.x = mouseX;
selectionSquareOrigin.y = mouseY;
lastAdded = points.length;
if (!plusKey && mouseX <= width && mouseY <= height) {
if (mouseButton === LEFT) {
points.push(createVector(mouseX, mouseY));
prevHandles.push(createVector(mouseX - 50, mouseY));
nextHandles.push(createVector(mouseX + 50, mouseY));
pointsOgLocation.push(createVector(mouseX, mouseY));
prevHandlesOgLocation.push(createVector(mouseX - 50, mouseY));
nextHandlesOgLocation.push(createVector(mouseX + 50, mouseY));
for (let i = 0; i < points.length; i++) {
pointsOgLocation[i].x = points[i].x;
pointsOgLocation[i].y = points[i].y;
prevHandlesOgLocation[i].x = prevHandles[i].x;
prevHandlesOgLocation[i].y = prevHandles[i].y;
nextHandlesOgLocation[i].x = nextHandles[i].x;
nextHandlesOgLocation[i].y = nextHandles[i].y;
if (mouseButton === RIGHT) {
for (let i = points.length - 1; i >= 0; i--) {
if (mouseX >= points[i].x - 5 && mouseX <= points[i].x + 5 && mouseY >= points[i].y - 5 && mouseY <= points[i].y + 5) {
prevHandles.splice(i, 1);
nextHandles.splice(i, 1);
function mouseDragged() {
if (mouseButton == LEFT) {
if (dist(mouseX, 0, points[lastAdded].x, 0) <= dist(0, mouseY, 0, points[lastAdded].y)) {
nextHandles[lastAdded].x = points[lastAdded].x;
nextHandles[lastAdded].y = mouseY;
prevHandles[lastAdded].x = points[lastAdded].x;
prevHandles[lastAdded].y = points[lastAdded].y - (mouseY - points[lastAdded].y);
nextHandles[lastAdded].x = mouseX;
nextHandles[lastAdded].y = points[lastAdded].y;
prevHandles[lastAdded].x = points[lastAdded].x - (mouseX - points[lastAdded].x);
prevHandles[lastAdded].y = points[lastAdded].y;
nextHandles[lastAdded].x = mouseX;
nextHandles[lastAdded].y = mouseY;
prevHandles[lastAdded].x = points[lastAdded].x - (mouseX - points[lastAdded].x);
prevHandles[lastAdded].y = points[lastAdded].y - (mouseY - points[lastAdded].y);
offsetX = mouseX - offsetOriginX;
offsetY = mouseY - offsetOriginY;
function mouseReleased() {
if (selectionKey && mode == GRAB) {
for (let i = 0; i < points.length; i++) {
if (mouseX >= points[i].x - 5 && mouseX <= points[i].x + 5 && mouseY >= points[i].y - 5 && mouseY <= points[i].y + 5) {
if (selectedPoints.includes(i)) {
selectedPoints.splice(selectedPoints.indexOf(i), 1);
if (squareTopCorner.x + squareWidth >= points[i].x - 5 && squareTopCorner.x <= points[i].x + 5 && squareTopCorner.y + squareHeight >= points[i].y - 5 && squareTopCorner.y <= points[i].y + 5) {
if (!selectedPoints.includes(i)) {
selectionSquareOrigin.x = 0;
selectionSquareOrigin.y = 0;
function checkDimentions() {
for (let i = 0; i < points.length - 1; i++) {
for (let t = 0; t < 1; t += 0.01) {
let x = bezierPoint(points[i].x, nextHandles[i].x, prevHandles[i + 1].x, points[i + 1].x, t);
let y = bezierPoint(points[i].y, nextHandles[i].y, prevHandles[i + 1].y, points[i + 1].y, t);
coordinates.push(createVector(x, y));
for (let i = 0; i < coordinates.length; i++) {
let value = coordinates[i];
topPoint = min(value.y, topPoint);
bottomPoint = max(value.y, bottomPoint);
leftPoint = min(value.x, leftPoint);
rightPoint = max(value.x, rightPoint);
for (let i = 0; i < coordinates.length; i++) {
if (mouseX >= coordinates[i].x - 5 && mouseX <= coordinates[i].x + 5 && mouseY >= coordinates[i].y - 5 && mouseY <= coordinates[i].y + 5) {
let previous = (i - (i % 100)) / 100;
if (mouseButton === LEFT) {
points.splice(next, 0, createVector(mouseX, mouseY));
prevHandles.splice(next, 0, createVector(mouseX - 50, mouseY));
nextHandles.splice(next, 0, createVector(mouseX + 50, mouseY));
pointsOgLocation.splice(next, 0, createVector(mouseX, mouseY));
prevHandlesOgLocation.splice(next, 0, createVector(mouseX - 50, mouseY));
nextHandlesOgLocation.splice(next, 0, createVector(mouseX + 50, mouseY));
if (functionType == PROCESSING) {
document.querySelector(".codeText").classList.add("processing");
document.querySelector(".codeText").classList.remove("p5js");
printCode += "<span class='noWrap'><span class='darkBlue'>void</span> <span class='yellow'>myShape</span>(<span class='orange'>float</span> <span class='lightBlue'>shapePosX</span>, <span class='orange'>float</span> <span class='lightBlue'>shapePosY</span>, <span class='orange'>float</span> <span class='lightBlue'>shapeWidth</span>, <span class='orange'>float</span> <span class='lightBlue'>shapeHeight</span>) { </span><br>";
document.querySelector(".codeText").classList.add("p5js");
document.querySelector(".codeText").classList.remove("processing");
printCode += "<span class='noWrap'><span class='darkBlue'>function</span> <span class='yellow'>myShape</span>(<span class='lightBlue'>shapePosX</span>, <span class='lightBlue'>shapePosY</span>, <span class='lightBlue'>shapeWidth</span>, <span class='lightBlue'>shapeHeight</span>) { </span><br>";
printCode += "<span class='offset'>"
printCode += "<span class='yellow'>push</span>();<br>";
printCode += "<span class='yellow'>translate</span>(<span class='lightBlue'>shapePosX</span>, <span class='lightBlue'>shapePosY</span>);<br>";
printCode += "<span class='yellow'>scale</span>(<span class='lightBlue'>shapeWidth</span>/<span class='green'>" + (rightPoint - leftPoint) + "</span>, <span class='lightBlue'>shapeHeight</span>/<span class='green'>" + (bottomPoint - topPoint) + "</span>);<br>";
printCode += "<span class='yellow'>beginShape</span>();<br>";
printCode += "<span class='yellow'>vertex</span>(<span class='green'>" + (points[0].x - centerPointPos.x) + "</span>, <span class='green'>" + (points[0].y - centerPointPos.y) + "</span>);<br>";
for (let i = 0; i < points.length - 1; i++) {
printCode += "<span class='yellow'>bezierVertex</span>(<span class='green'>" + (nextHandles[i].x - centerPointPos.x) + "</span>, <span class='green'>" + (nextHandles[i].y - centerPointPos.y) + "</span>, <span class='green'>" + (prevHandles[i + 1].x - centerPointPos.x) + "</span>, <span class='green'>" + (prevHandles[i + 1].y - centerPointPos.y) + "</span>, <span class='green'>" + (points[i + 1].x - centerPointPos.x) + "</span>, <span class='green'>" + (points[i + 1].y - centerPointPos.y) + "</span>);<br>";
printCode += "<span class='yellow'>endShape</span>();<br>";
printCode += "<span class='yellow'>pop</span>();<br>";
document.querySelector(".codeText").innerHTML = printCode;
function copyToClipBoard() {
var copyText = document.querySelector(".codeText").innerText;
var elem = document.createElement("textarea");
document.body.appendChild(elem);
document.execCommand("copy");
document.body.removeChild(elem);
document.addEventListener("DOMContentLoaded", () => {
document.querySelector("body").addEventListener('keyPressed', (e) => {
e.altKey.preventDefault();