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()
}









share|improve this question


















  • 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

















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()
}









share|improve this question


















  • 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















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()
}









share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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














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.






share|improve this answer





















  • Thanks so much :)
    – Giorgio Martini
    Nov 11 at 12:33










  • You're welcome ;-)
    – trincot
    Nov 11 at 12:34











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























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.






share|improve this answer





















  • Thanks so much :)
    – Giorgio Martini
    Nov 11 at 12:33










  • You're welcome ;-)
    – trincot
    Nov 11 at 12:34















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.






share|improve this answer





















  • Thanks so much :)
    – Giorgio Martini
    Nov 11 at 12:33










  • You're welcome ;-)
    – trincot
    Nov 11 at 12:34













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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Full-time equivalent

さくらももこ

13 indicted, 8 arrested in Calif. drug cartel investigation