Created
November 5, 2019 17:24
-
-
Save mimetaur/dec938e03b1e80a9d5440b8d8ae05812 to your computer and use it in GitHub Desktop.
Midterm help for Ramsey
This file contains 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
// 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