Graph not being plot












0















I have built a JavaScript P5.js program to plot graphs. Everything works apart from the points do not appear on the display, and when they do they don't follow the trend the graph should.



function setup() {
H = 800;
W = 800;
wFreq = 20;
hFreq = 20;
wDist = H / hFreq;
hDist = W / wFreq;
uLength = 10;

createCanvas(W, H);
}

function formula(x) {
//0x² + 0x - 0
sum = 0;
sum += x*x;
sum += 0;
sum += 0;
return sum
}

function draw() {
background(220);
translate(0, 0)

rect(0, H/2, W, 0);
rect(W/2, 0, 0, H);

translate(0, H/2);
for(i = W/2; i -= 1; i > 0) {
rect((i-0.5) * wDist /2, -uLength/2, 0, uLength);
}

translate(W/2, -H);
for(i = H/2; i -= 1; i > 0) {
rect(-uLength/2,i * (hDist -1) /(4*(10/hFreq)), uLength, 0);
}

translate(200, 200);
for(i = -wFreq; i += 1; i < wFreq) {
rect(i*wDist, formula(i), 1, 1);
}
}









share|improve this question

























  • I don't think 0x² + 0x - 0 is what you meant to write

    – Joseph Young
    Nov 20 '18 at 18:03
















0















I have built a JavaScript P5.js program to plot graphs. Everything works apart from the points do not appear on the display, and when they do they don't follow the trend the graph should.



function setup() {
H = 800;
W = 800;
wFreq = 20;
hFreq = 20;
wDist = H / hFreq;
hDist = W / wFreq;
uLength = 10;

createCanvas(W, H);
}

function formula(x) {
//0x² + 0x - 0
sum = 0;
sum += x*x;
sum += 0;
sum += 0;
return sum
}

function draw() {
background(220);
translate(0, 0)

rect(0, H/2, W, 0);
rect(W/2, 0, 0, H);

translate(0, H/2);
for(i = W/2; i -= 1; i > 0) {
rect((i-0.5) * wDist /2, -uLength/2, 0, uLength);
}

translate(W/2, -H);
for(i = H/2; i -= 1; i > 0) {
rect(-uLength/2,i * (hDist -1) /(4*(10/hFreq)), uLength, 0);
}

translate(200, 200);
for(i = -wFreq; i += 1; i < wFreq) {
rect(i*wDist, formula(i), 1, 1);
}
}









share|improve this question

























  • I don't think 0x² + 0x - 0 is what you meant to write

    – Joseph Young
    Nov 20 '18 at 18:03














0












0








0








I have built a JavaScript P5.js program to plot graphs. Everything works apart from the points do not appear on the display, and when they do they don't follow the trend the graph should.



function setup() {
H = 800;
W = 800;
wFreq = 20;
hFreq = 20;
wDist = H / hFreq;
hDist = W / wFreq;
uLength = 10;

createCanvas(W, H);
}

function formula(x) {
//0x² + 0x - 0
sum = 0;
sum += x*x;
sum += 0;
sum += 0;
return sum
}

function draw() {
background(220);
translate(0, 0)

rect(0, H/2, W, 0);
rect(W/2, 0, 0, H);

translate(0, H/2);
for(i = W/2; i -= 1; i > 0) {
rect((i-0.5) * wDist /2, -uLength/2, 0, uLength);
}

translate(W/2, -H);
for(i = H/2; i -= 1; i > 0) {
rect(-uLength/2,i * (hDist -1) /(4*(10/hFreq)), uLength, 0);
}

translate(200, 200);
for(i = -wFreq; i += 1; i < wFreq) {
rect(i*wDist, formula(i), 1, 1);
}
}









share|improve this question
















I have built a JavaScript P5.js program to plot graphs. Everything works apart from the points do not appear on the display, and when they do they don't follow the trend the graph should.



function setup() {
H = 800;
W = 800;
wFreq = 20;
hFreq = 20;
wDist = H / hFreq;
hDist = W / wFreq;
uLength = 10;

createCanvas(W, H);
}

function formula(x) {
//0x² + 0x - 0
sum = 0;
sum += x*x;
sum += 0;
sum += 0;
return sum
}

function draw() {
background(220);
translate(0, 0)

rect(0, H/2, W, 0);
rect(W/2, 0, 0, H);

translate(0, H/2);
for(i = W/2; i -= 1; i > 0) {
rect((i-0.5) * wDist /2, -uLength/2, 0, uLength);
}

translate(W/2, -H);
for(i = H/2; i -= 1; i > 0) {
rect(-uLength/2,i * (hDist -1) /(4*(10/hFreq)), uLength, 0);
}

translate(200, 200);
for(i = -wFreq; i += 1; i < wFreq) {
rect(i*wDist, formula(i), 1, 1);
}
}






javascript p5.js






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 18:15









Kevin Workman

34.1k54172




34.1k54172










asked Nov 20 '18 at 18:00









Samuel PollardSamuel Pollard

1




1













  • I don't think 0x² + 0x - 0 is what you meant to write

    – Joseph Young
    Nov 20 '18 at 18:03



















  • I don't think 0x² + 0x - 0 is what you meant to write

    – Joseph Young
    Nov 20 '18 at 18:03

















I don't think 0x² + 0x - 0 is what you meant to write

– Joseph Young
Nov 20 '18 at 18:03





I don't think 0x² + 0x - 0 is what you meant to write

– Joseph Young
Nov 20 '18 at 18:03












1 Answer
1






active

oldest

votes


















1














Note that your calls to translate() stack.



I'm not sure exactly where you want your points to show up, but to help you debug, I can see the points if I change your translate(200, 200); call to translate(400, 400); instead.



You'll have to play with the values you pass in to achieve the effect you want. You also might want to look up the push() and pop() functions in the reference.



You might also consider not using translate() at all, and using the coordinates directly in your drawing code.






share|improve this answer























    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',
    autoActivateHeartbeat: false,
    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%2f53398888%2fgraph-not-being-plot%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









    1














    Note that your calls to translate() stack.



    I'm not sure exactly where you want your points to show up, but to help you debug, I can see the points if I change your translate(200, 200); call to translate(400, 400); instead.



    You'll have to play with the values you pass in to achieve the effect you want. You also might want to look up the push() and pop() functions in the reference.



    You might also consider not using translate() at all, and using the coordinates directly in your drawing code.






    share|improve this answer




























      1














      Note that your calls to translate() stack.



      I'm not sure exactly where you want your points to show up, but to help you debug, I can see the points if I change your translate(200, 200); call to translate(400, 400); instead.



      You'll have to play with the values you pass in to achieve the effect you want. You also might want to look up the push() and pop() functions in the reference.



      You might also consider not using translate() at all, and using the coordinates directly in your drawing code.






      share|improve this answer


























        1












        1








        1







        Note that your calls to translate() stack.



        I'm not sure exactly where you want your points to show up, but to help you debug, I can see the points if I change your translate(200, 200); call to translate(400, 400); instead.



        You'll have to play with the values you pass in to achieve the effect you want. You also might want to look up the push() and pop() functions in the reference.



        You might also consider not using translate() at all, and using the coordinates directly in your drawing code.






        share|improve this answer













        Note that your calls to translate() stack.



        I'm not sure exactly where you want your points to show up, but to help you debug, I can see the points if I change your translate(200, 200); call to translate(400, 400); instead.



        You'll have to play with the values you pass in to achieve the effect you want. You also might want to look up the push() and pop() functions in the reference.



        You might also consider not using translate() at all, and using the coordinates directly in your drawing code.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 18:15









        Kevin WorkmanKevin Workman

        34.1k54172




        34.1k54172
































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398888%2fgraph-not-being-plot%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

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)