Why is the function Fill not found? but the rest of the functions on the library yes?
up vote
2
down vote
favorite
Im workingon a P5.js sketch...
Instead of creating objects with a constructor function, and then using the new keyword.
I want to use a factory function.
It seems to work fine, and renders correclty when using for example this code:
stroke(255,0,0)
ellipse(speed, 10, 10, 10)
But at the moment i try to use fill(255)
, i get an error saying fill is not a function?
How is it possible that only this function from p5 is not being recognized but others yes?
Here is a codepen: https://codepen.io/giorgiomartini/pen/VVKMKg?editors=0011
Code:
function setup () {
createCanvas(300,500)
background(3)
bola = createCircle(circleOpts)
}
const circleOpts = {
fill: 255,
x: 0,
y: 0,
maxRadius: 10,
}
const createCircle = ({fill = 255, x = 10, y = 10, maxRadius = 20}) => {
let speed = 0
return {
display() {
noStroke()
background(2)
stroke(255,0,0)
// if you remove this next line it works!
fill(255)
ellipse(speed, 10, 30, 30)
}
}
}
let bola
function draw () {
bola.display()
}
javascript processing p5.js
add a comment |
up vote
2
down vote
favorite
Im workingon a P5.js sketch...
Instead of creating objects with a constructor function, and then using the new keyword.
I want to use a factory function.
It seems to work fine, and renders correclty when using for example this code:
stroke(255,0,0)
ellipse(speed, 10, 10, 10)
But at the moment i try to use fill(255)
, i get an error saying fill is not a function?
How is it possible that only this function from p5 is not being recognized but others yes?
Here is a codepen: https://codepen.io/giorgiomartini/pen/VVKMKg?editors=0011
Code:
function setup () {
createCanvas(300,500)
background(3)
bola = createCircle(circleOpts)
}
const circleOpts = {
fill: 255,
x: 0,
y: 0,
maxRadius: 10,
}
const createCircle = ({fill = 255, x = 10, y = 10, maxRadius = 20}) => {
let speed = 0
return {
display() {
noStroke()
background(2)
stroke(255,0,0)
// if you remove this next line it works!
fill(255)
ellipse(speed, 10, 30, 30)
}
}
}
let bola
function draw () {
bola.display()
}
javascript processing p5.js
1
fill = 255
in the parameter list defines it as a number, not a function. It probably shadows the function with the same name. So just use a different name for either of the two.
– trincot
Nov 11 at 12:21
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Im workingon a P5.js sketch...
Instead of creating objects with a constructor function, and then using the new keyword.
I want to use a factory function.
It seems to work fine, and renders correclty when using for example this code:
stroke(255,0,0)
ellipse(speed, 10, 10, 10)
But at the moment i try to use fill(255)
, i get an error saying fill is not a function?
How is it possible that only this function from p5 is not being recognized but others yes?
Here is a codepen: https://codepen.io/giorgiomartini/pen/VVKMKg?editors=0011
Code:
function setup () {
createCanvas(300,500)
background(3)
bola = createCircle(circleOpts)
}
const circleOpts = {
fill: 255,
x: 0,
y: 0,
maxRadius: 10,
}
const createCircle = ({fill = 255, x = 10, y = 10, maxRadius = 20}) => {
let speed = 0
return {
display() {
noStroke()
background(2)
stroke(255,0,0)
// if you remove this next line it works!
fill(255)
ellipse(speed, 10, 30, 30)
}
}
}
let bola
function draw () {
bola.display()
}
javascript processing p5.js
Im workingon a P5.js sketch...
Instead of creating objects with a constructor function, and then using the new keyword.
I want to use a factory function.
It seems to work fine, and renders correclty when using for example this code:
stroke(255,0,0)
ellipse(speed, 10, 10, 10)
But at the moment i try to use fill(255)
, i get an error saying fill is not a function?
How is it possible that only this function from p5 is not being recognized but others yes?
Here is a codepen: https://codepen.io/giorgiomartini/pen/VVKMKg?editors=0011
Code:
function setup () {
createCanvas(300,500)
background(3)
bola = createCircle(circleOpts)
}
const circleOpts = {
fill: 255,
x: 0,
y: 0,
maxRadius: 10,
}
const createCircle = ({fill = 255, x = 10, y = 10, maxRadius = 20}) => {
let speed = 0
return {
display() {
noStroke()
background(2)
stroke(255,0,0)
// if you remove this next line it works!
fill(255)
ellipse(speed, 10, 30, 30)
}
}
}
let bola
function draw () {
bola.display()
}
javascript processing p5.js
javascript processing p5.js
asked Nov 11 at 12:18
Giorgio Martini
16018
16018
1
fill = 255
in the parameter list defines it as a number, not a function. It probably shadows the function with the same name. So just use a different name for either of the two.
– trincot
Nov 11 at 12:21
add a comment |
1
fill = 255
in the parameter list defines it as a number, not a function. It probably shadows the function with the same name. So just use a different name for either of the two.
– trincot
Nov 11 at 12:21
1
1
fill = 255
in the parameter list defines it as a number, not a function. It probably shadows the function with the same name. So just use a different name for either of the two.– trincot
Nov 11 at 12:21
fill = 255
in the parameter list defines it as a number, not a function. It probably shadows the function with the same name. So just use a different name for either of the two.– trincot
Nov 11 at 12:21
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
There is a variable name conflict: fill
is a local variable that is created in the function parameter list of createCircle
. This local variable shadows the function name you probably defined in the global scope. And this local variable is indeed not a function (but a number).
You can resolve this with a name change: either change the name of the function fill
or the name of the local variable fill
. If you go for the latter option, it could look like this:
const circleOpts = {
fillColor: 255, // <-------- changed name
x: 0,
y: 0,
maxRadius: 10,
}
const createCircle = ({fillColor = 255, x = 10, y = 10, maxRadius = 20}) => {
// ^^^^^^^^^
... etc.
Thanks so much :)
– Giorgio Martini
Nov 11 at 12:33
You're welcome ;-)
– trincot
Nov 11 at 12:34
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
There is a variable name conflict: fill
is a local variable that is created in the function parameter list of createCircle
. This local variable shadows the function name you probably defined in the global scope. And this local variable is indeed not a function (but a number).
You can resolve this with a name change: either change the name of the function fill
or the name of the local variable fill
. If you go for the latter option, it could look like this:
const circleOpts = {
fillColor: 255, // <-------- changed name
x: 0,
y: 0,
maxRadius: 10,
}
const createCircle = ({fillColor = 255, x = 10, y = 10, maxRadius = 20}) => {
// ^^^^^^^^^
... etc.
Thanks so much :)
– Giorgio Martini
Nov 11 at 12:33
You're welcome ;-)
– trincot
Nov 11 at 12:34
add a comment |
up vote
1
down vote
accepted
There is a variable name conflict: fill
is a local variable that is created in the function parameter list of createCircle
. This local variable shadows the function name you probably defined in the global scope. And this local variable is indeed not a function (but a number).
You can resolve this with a name change: either change the name of the function fill
or the name of the local variable fill
. If you go for the latter option, it could look like this:
const circleOpts = {
fillColor: 255, // <-------- changed name
x: 0,
y: 0,
maxRadius: 10,
}
const createCircle = ({fillColor = 255, x = 10, y = 10, maxRadius = 20}) => {
// ^^^^^^^^^
... etc.
Thanks so much :)
– Giorgio Martini
Nov 11 at 12:33
You're welcome ;-)
– trincot
Nov 11 at 12:34
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
There is a variable name conflict: fill
is a local variable that is created in the function parameter list of createCircle
. This local variable shadows the function name you probably defined in the global scope. And this local variable is indeed not a function (but a number).
You can resolve this with a name change: either change the name of the function fill
or the name of the local variable fill
. If you go for the latter option, it could look like this:
const circleOpts = {
fillColor: 255, // <-------- changed name
x: 0,
y: 0,
maxRadius: 10,
}
const createCircle = ({fillColor = 255, x = 10, y = 10, maxRadius = 20}) => {
// ^^^^^^^^^
... etc.
There is a variable name conflict: fill
is a local variable that is created in the function parameter list of createCircle
. This local variable shadows the function name you probably defined in the global scope. And this local variable is indeed not a function (but a number).
You can resolve this with a name change: either change the name of the function fill
or the name of the local variable fill
. If you go for the latter option, it could look like this:
const circleOpts = {
fillColor: 255, // <-------- changed name
x: 0,
y: 0,
maxRadius: 10,
}
const createCircle = ({fillColor = 255, x = 10, y = 10, maxRadius = 20}) => {
// ^^^^^^^^^
... etc.
answered Nov 11 at 12:26
trincot
114k1477109
114k1477109
Thanks so much :)
– Giorgio Martini
Nov 11 at 12:33
You're welcome ;-)
– trincot
Nov 11 at 12:34
add a comment |
Thanks so much :)
– Giorgio Martini
Nov 11 at 12:33
You're welcome ;-)
– trincot
Nov 11 at 12:34
Thanks so much :)
– Giorgio Martini
Nov 11 at 12:33
Thanks so much :)
– Giorgio Martini
Nov 11 at 12:33
You're welcome ;-)
– trincot
Nov 11 at 12:34
You're welcome ;-)
– trincot
Nov 11 at 12:34
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248683%2fwhy-is-the-function-fill-not-found-but-the-rest-of-the-functions-on-the-library%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
fill = 255
in the parameter list defines it as a number, not a function. It probably shadows the function with the same name. So just use a different name for either of the two.– trincot
Nov 11 at 12:21