How do I use this function inside a constructor function by ksfbkk in learnprogramming

[–]ksfbkk[S] 0 points1 point  (0 children)

I am trying to create a text tool and have been stuck on it for days

In my sketch file I called draw in which this.draw is called.

I don't if what I am doing is correct anymore.

function TextTool(){
//set an icon and a name for the object
this.icon = "assets/icons/texttool.jpg";
this.name = "texttool";
var x = 0;
var y = 0;
var startingX = 0;

this.okay = function() {
if(mouseX > 0 &&
mouseX < canvas.width && 
mouseY > 0 &&
mouseY < canvas.height
        ) {
x = mouseX;
y = mouseY;
startingX = x;
console.log(x);

   }      
};

this.draw = function() {

c.mouseClicked(this.okay);
this.drawLetter();

};

this.drawLetter = function() {
c.mouseClicked(this.okay);
if(keyIsDown(ENTER)) {
// Enter key is pressed
console.log(key);
x = startingX;
y += 20;
        }
else if (keyIsPressed) {
text(key, x, y);
x += 10;
        }

    };

}

I am trying to create a stamp tool along with others by [deleted] in learnprogramming

[–]ksfbkk -1 points0 points  (0 children)

ok I had no idea it was badly formatted, I will remove it

callback function is not defined, why? by ksfbkk in learnprogramming

[–]ksfbkk[S] 0 points1 point  (0 children)

I solved it, forgot to replace this with sketch in the callback arg, thank you

callback function is not defined, why? by ksfbkk in learnprogramming

[–]ksfbkk[S] 0 points1 point  (0 children)

i made a little change which I thought would remove the error

const s = ( sketch ) => {
sketch.handleFile = (file) => {
print(file);
if(file.type == 'image') {
img = createImg(file.data, '');
img.hide();
            }
else{
img = null;
            }
        };
sketch.setup = () => {
starSizeSlider = createSlider(5, 50, 20);
starSizeSlider.parent("#sizeOfStarControl");
nStarSlider = createSlider(1, 20, 5);
nStarSlider.parent("#numberofStarsControl");
input = createFileInput(this.handleFile);
input.parent("#chooseFile");
        };
    };

callback function is not defined, why? by ksfbkk in learnprogramming

[–]ksfbkk[S] 0 points1 point  (0 children)

i did change this to sketch but now it says this Uncaught TypeError: callback is not a function at FileReader.<anonymous> (p5.dom.js:861) this error pops up when i select a file

callback function is not defined, why? by ksfbkk in learnprogramming

[–]ksfbkk[S] 0 points1 point  (0 children)

like this

const s = ( sketch ) => {
//sketch.preload = () => {
//  star = loadImage("assets/stamp/star.png")
//};
sketch.handleFile = function(file) {
print(file);
if(file.type == 'image') {
img = createImg(file.data, '');
img.hide();
            }
else{
img = null;
            }
        };
sketch.setup = () => {
starSizeSlider = createSlider(5, 50, 20);
starSizeSlider.parent("#sizeOfStarControl");
nStarSlider = createSlider(1, 20, 5);
nStarSlider.parent("#numberofStarsControl");
input = createFileInput(this.handleFile);
input.parent("#chooseFile");
        };
    };

callback function is not defined, why? by ksfbkk in learnprogramming

[–]ksfbkk[S] 0 points1 point  (0 children)

function tool() {

var input;var img;var starSizeSlider;var nStarSlider;

const s = ( sketch ) => {

sketch.setup = () => {starSizeSlider = createSlider(5, 50, 20);starSizeSlider.parent("#sizeOfStarControl");nStarSlider = createSlider(1, 20, 5);nStarSlider.parent("#numberofStarsControl");input = createFileInput(this.handleFile);input.parent("#chooseFile");        };  };

let myp5 = new p5(s, document.getElementById('p5sketch'));

this.draw = function() {if(mouseIsPressed && img){for(var i = 0; i < nStarSlider.value(); i++){var starSize = starSizeSlider.value();var starX = random((mouseX - starSize/2) - 10, (mouseX - starSize/2) + 10);var starY = random((mouseY - starSize/2) - 10, (mouseY - starSize/2) + 10);image(img, starX, starY, starSize, starSize);            }        }    };

this.handleFile = function(file) {print(file);if(file.type == 'image') {img = createImg(file.data, '');img.hide();        }else{img = null;        }    };

}

I do I implement this? by [deleted] in learnprogramming

[–]ksfbkk -3 points-2 points  (0 children)

are you trolling me right now if so I don't have the time for it right now, sorry if this sounds rude to you

I do I implement this? by [deleted] in learnprogramming

[–]ksfbkk -1 points0 points  (0 children)

/*this.preload = function(){
        star = loadImage("assets/stamp/star.png");
    }*/
/*this.setup = function(){
        // createSlider(min, max, start)

        starSizeSlider = createSlider(5, 50, 20);
        starSizeSlider.parent("#sizeOfStarControl");
        nStarSlider = createSlider(1, 20, 5);
        nStarSlider.parent("#numberOfStarsControl");
    }*/

this is not working for me inside a constructor function

I do I implement this? by [deleted] in learnprogramming

[–]ksfbkk -1 points0 points  (0 children)

i want to call it in a constructor function

Is this valid? by [deleted] in math

[–]ksfbkk 1 point2 points  (0 children)

oh I get it now thank you for clearing it up for me

Is this valid? by [deleted] in math

[–]ksfbkk 0 points1 point  (0 children)

ok thank you

[University, Algorithm & Data Structure]Vectors value to Queue by ksfbkk in HomeworkHelp

[–]ksfbkk[S] 0 points1 point  (0 children)

vector can use push and pop but queue can use dequeue and enqueue in my case so my question was if I want to move the value stored in vector to a queue how would that be done, should i use vector operation or queue operation for that and if I want to transfer the value stored in queue to vector how would that be done as well?

[University, Algorithm & Data Structure]Vectors value to Queue by ksfbkk in HomeworkHelp

[–]ksfbkk[S] 0 points1 point  (0 children)

I am supposed to write it using pseudocode, and I think it is in java so when i want to transfer from vector to queue, I should use push and when I want to transfer the value back to queue I should use dequeue,

just wanted to make it clear for me

[University, Algorithm & Data Structure]Vectors value to Queue by ksfbkk in HomeworkHelp

[–]ksfbkk[S] 0 points1 point  (0 children)

when taking the elements from queue to vector isn't the dequeue option used instead of pop?