Skip to content

Instantly share code, notes, and snippets.

@mimetaur
Created November 5, 2019 17:24
Show Gist options
  • Save mimetaur/dec938e03b1e80a9d5440b8d8ae05812 to your computer and use it in GitHub Desktop.
Save mimetaur/dec938e03b1e80a9d5440b8d8ae05812 to your computer and use it in GitHub Desktop.
Midterm help for Ramsey
// this object literal holds our triangle info
let playerTriangle = {
x: 50,
y: 50,
size: 25
}
function setup() {
createCanvas(800, 700);
}
function draw() {
background(220, 250, 100);
stroke(0)
// ellipse
fill(250, 250, 200)
// so now we move the whole triangle, not just one point
playerTriangle.x = mouseX;
playerTriangle.y = mouseY;
// this code looks complicated
// but you need variables and math to manage triangles
// because there are three different x,y points
// see https://p5js.org/reference/#/p5/triangle
triangle(playerTriangle.x - playerTriangle.size, playerTriangle.y - playerTriangle.size, playerTriangle.x + playerTriangle.size, playerTriangle.y - playerTriangle.size, playerTriangle.x, playerTriangle.y + playerTriangle.size);
// so the problem with your original code is that
// the mouse is only moving one corner of your triangle, but you need to move the whole thing
// triangle(mouseX, mouseY, 58, 20, 86, 75);
rect(5, 520, 40, 10)
rect(5, 720, 40, 10)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment