Skip to content

Instantly share code, notes, and snippets.

@antiboredom
Forked from anonymous/script.js
Created December 9, 2015 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antiboredom/bb3ef44a61bc27c47dfb to your computer and use it in GitHub Desktop.
Save antiboredom/bb3ef44a61bc27c47dfb to your computer and use it in GitHub Desktop.
var canvas;
var handleVal;
var isClicked = false;
//var clock;
// Class Definition
var UiHandle = function (startX, startY, width, height){
this.x = startX;
this.y = startY;
//this.handleVal = ;
this.width = width;
this.height = height;
this.isClicked = false;
this.getClick = getClicked;
this.col = color(175, 175, 175);
fill(this.col);
rect(this.x, this.y, this.width, this.height);
}
function getClicked(){
// Determining if click is inside handle dimensions
if(mouseX > this.x && mouseX < this.x + this.width && mouseY > this.y && mouseY < this.y + this.height && mouseIsPressed){
this.isClicked = true;
this.col = color(255, 25, 25);
console.log("Condition 1: " + this.isClicked);
} else {
this.isClicked = false;
this.col = color(175, 175, 175);
console.log("Condition 2: " + this.isClicked);
}
return this.isClicked;
return this.col;
}
function setup() {
canvas = createCanvas(400, 200);
}
function draw() {
background(255);
ellipse(canvas.width/2, canvas.height/4, 25, 25);
//clock = document.getElementById('clock').setInnerHTML(mouseX);
line(50, 100, 350, 100);
// Instantiating handle object
var handle = new UiHandle(50,87,25,25);
handle.getClick();
//console.log(handle.isClicked);
// If handle is clicked and moved, update handle location and color
if (isClicked === true){
handle.x = mouseX;
handle.col = (255, 25, 25);
//handle.isClicked();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment