Hey Bob, yes for sure, if you're not using a module bundler to import and export files, you can inline the Dot.js
code into your main .js file.
All you'd do is change Dot.js
here:
export default class Dot {
constructor(x, y, r, g, b, imageX, imageY) {
this.x = x
this.y = y
this.r = r
this.g = g
this.b = b
this.imageX = imageX
this.imageY = imageY
}
draw(c) {
c.beginPath()
c.arc(this.x, this.y, 2, 0, 2 * Math.PI, false)
c.fillStyle = 'rgb(' + this.r + ', ' + this.g + ', ' + this.b + ')'
c.fill()
}
}
To be inline-able like:
class Dot {
constructor(x, y, r, g, b, imageX, imageY) {
this.x = x
this.y = y
this.r = r
this.g = g
this.b = b
this.imageX = imageX
this.imageY = imageY
}
draw(c) {
c.beginPath()
c.arc(this.x, this.y, 2, 0, 2 * Math.PI, false)
c.fillStyle = 'rgb(' + this.r + ', ' + this.g + ', ' + this.b + ')'
c.fill()
}
}
So basically, get rid of the export default
, place the class in whatever file you'd like to use it, and now you can use it just like in the video.
Let me know if that helps!
Want to participate?
Create a free Chris Courses account to begin