Skip to content

Commit

Permalink
add constructor of Shape2D b00tc4mp#200 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
J0s3rra committed Mar 22, 2024
1 parent ed01405 commit 26febea
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
14 changes: 14 additions & 0 deletions staff/joseramon-rodriguez/shapes/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shapes</title>
</head>

<body>
<script src="index.js"></script>
</body>

</html>
49 changes: 49 additions & 0 deletions staff/joseramon-rodriguez/shapes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
function Shape2D(width, height, color) {
this.width = width
this.height = height
this.color = color

this.x = 0
this.y = 0

var container = document.createElement('div')

container.style.position = 'absolute'
container.style.left = this.x + 'px'
container.style.top = this.y + 'px'
container.style.width = this.width + 'px'
container.style.height = this.height + 'px'
container.style.backgroundColor = this.color

this.container = container
}

// location

Shape2D.prototype.setX = function (x) {
this.x = x

this.container.style.left = this.x + 'px'
}

Shape2D.prototype.getX = function () {
return this.x
}

Shape2D.prototype.setY = function (y) {
this.y = y

this.container.style.top = this.y + 'px'
}

Shape2D.prototype.getY = function () {
return this.y
}

Shape2D.prototype.setLocation = function (x, y) {
this.setX(x)
this.setY(y)
}

//dimensions

0 comments on commit 26febea

Please sign in to comment.