Last active
November 14, 2017 05:38
-
-
Save lizzybrooks/597aca1001af34f716019447130d9ae5 to your computer and use it in GitHub Desktop.
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
//make room for a person, person1, in this sketch. | |
let person1; | |
function setup() { | |
createCanvas(400, 400); | |
person1 = new Person(); //create person1 from the Person class | |
} | |
function draw(){ | |
background(0); | |
fill(200,200,30); | |
stroke(200,200,30); | |
person1.drawPerson(); //draw that person using the technique in the Person class | |
} | |
function mousePressed(){ | |
person1.movePerson(); //change that person's location using the movePerson function | |
} | |
//make a class or template called Person, from which many similar people can be made. | |
class Person { | |
constructor(x,y){ | |
this.x = 100; | |
this.y = 150; | |
} | |
drawPerson(){ | |
ellipse(this.x,this.y,50,50); | |
line(this.x,this.y,this.x,this.y+200); | |
} | |
movePerson(){ | |
this.x = mouseX; | |
this.y = mouseY; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment