Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 5 FirstFirst 1234 ... LastLast
Results 16 to 30 of 71

Thread: Canvas Problem

  1. #16
    New Coder donna1's Avatar
    Join Date
    Nov 2012
    Location
    london
    Posts
    99
    Thanks
    9
    Thanked 4 Times in 4 Posts
    Code:
    What could you even do without HTML and CSS in javascript?
    with html5 canvas you can draw and write text and everything in javascript.
    It can be interactive too and do moving graphics.

    the only other thing I may need is PHP to read and write to a database on a server, it seems a shame that javascript cant do that directly?
    Last edited by donna1; 12-05-2012 at 02:04 AM.

  2. #17
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,688
    Thanks
    80
    Thanked 4,647 Times in 4,609 Posts
    I have to admit that I would never bother to use === for something like this:
    Code:
    			if(tileTopCount===map[x].length){
    I mean, we *KNOW* that both of those values are numbers. The one because we made it so, the other because the .length property is guaranteed to be so.

    So why do we need to test that the types are equal?

    If JavaScript were more sensitive to what === means, I might be more inclined to use it. For example, if === distinguished between integers and non-integers. But it doesn't, because JavaScript doesn't see a distinction between them.

    I commonly only use === when I'm comparing against something being returned by some function and where I can't guarantee the type being returned.

    Still, it's a nice operator to have in your arsenal.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  3. #18
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,688
    Thanks
    80
    Thanked 4,647 Times in 4,609 Posts
    Quote Originally Posted by donna1 View Post
    with html5 canvas you can draw and write text and everything in javascript.
    It can be interactive too and do moving graphics.
    Yes. And it's overkill in probably more than half the things I see it being used for.

    And it's no substitute for many HTML tags and CSS properties.

    For example, if you draw text on a canvas, then that text is SET at the number of pixels you used when you drew it.

    If I put HTML text on a page, using CSS such as
    Code:
    <span style="font-size: x-large;">Headline</span>
    then the browser user can easily cause the font size to grow or shrink, so it can be much more user-friendly to, say, people with limited vision.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  4. #19
    New Coder donna1's Avatar
    Join Date
    Nov 2012
    Location
    london
    Posts
    99
    Thanks
    9
    Thanked 4 Times in 4 Posts
    I really dont like this ===

    I dont agree with even the two distinctions of = and ==
    That caused me loads of bugs last week before I realised they are completely different

    Another stupid idea from someone, who has probably wasted combined millions of hours in errors since

  5. #20
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,688
    Thanks
    80
    Thanked 4,647 Times in 4,609 Posts
    Quote Originally Posted by donna1 View Post
    [CODE]
    the only other thing I may need is PHP to read and write to a database on a server, it seems a shame that javascript cant do that directly?
    So PHP can also draw on canvases, creating images that can then be just dropped into an HTML page.

    Except for animation, why learn to even use JavaScript? Or why learn to create HTML with PHP? Just use PHP to create images and never learn anything more.

    Sorry, but pfui. You remind me of the ranks and ranks of COBOL programmers who never learned anything else and are now stuck doing nothing but maintaining ancient legacy code. Or the steam engine repairmen who refused to learn diesel engines. Or the scribes who refused to learn how to work a printing press. Or...

    Learn as much as you possibly can!

    I've been programming for over 40 years now, and I *STILL* try to learn something new as often as possible. New languages, new techniques, new tricks for better database efficiency, etc., etc., etc.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  6. #21
    Regular Coder
    Join Date
    Jun 2010
    Posts
    134
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by donna1 View Post
    I really dont like this ===

    I dont agree with even the two distinctions of = and ==
    That caused me loads of bugs last week before I realised they are completely different

    Another stupid idea from someone, who has probably wasted combined millions of hours in errors since
    How is it stupid? = means you are setting a value for something. For the Majority of the time I use === not ==.

    I can tell you really don't know a lot about programming in Javascript.

  7. #22
    Regular Coder
    Join Date
    Jun 2010
    Posts
    134
    Thanks
    0
    Thanked 3 Times in 3 Posts
    oh and == and === means you are comparing

  8. #23
    Regular Coder
    Join Date
    Jun 2010
    Posts
    134
    Thanks
    0
    Thanked 3 Times in 3 Posts
    One last thing, How come I have to load my page twice for my map to display?

  9. #24
    New Coder donna1's Avatar
    Join Date
    Nov 2012
    Location
    london
    Posts
    99
    Thanks
    9
    Thanked 4 Times in 4 Posts
    OPendant I agree that it is slightly harder in javascript to increase font size, as you have to set the text style as a string of "font + size pt"
    Not logical, should just be a fontsize = number, but still its not that difficult to change with a sting

  10. #25
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,688
    Thanks
    80
    Thanked 4,647 Times in 4,609 Posts
    Quote Originally Posted by donna1 View Post
    I really dont like this ===

    I dont agree with even the two distinctions of = and ==
    That caused me loads of bugs last week before I realised they are completely different

    Another stupid idea from someone, who has probably wasted combined millions of hours in errors since
    So presumably you would like the PASCAL solution better?

    Pascal uses := for assignment and = for comparison.

    And it's just as easy there to make the mistake of using = when you meant := as it is to make the JavaScript/Java/C/C++/C#/PHP (and other languages!!!!) mistake of using = when you meant ==.

    If you REALLY want confusion, use BASIC, which only has =. And what do you think
    Code:
        A = B = C = 7
    means in BASIC??

    HINT: A will get a value of FALSE. Probably.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  11. #26
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,688
    Thanks
    80
    Thanked 4,647 Times in 4,609 Posts
    Quote Originally Posted by donna1 View Post
    OPendant I agree that it is slightly harder in javascript to increase font size, as you have to set the text style as a string of "font + size pt"
    Not logical, should just be a fontsize = number, but still its not that difficult to change with a sting
    ** WRONG **

    Yes, your JAVASCRIPT code can COMPLETELY REDRAW the canvas, assuming you code like that and assuming you choose to change the fontsize number.

    The BROWSER USER can *NOT* cause that to happen unless you give her/him some way to REQUEST the change in font size.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  12. #27
    New Coder donna1's Avatar
    Join Date
    Nov 2012
    Location
    london
    Posts
    99
    Thanks
    9
    Thanked 4 Times in 4 Posts
    You put the word IF before a comparison and LET before an assignment and you can use = in both cases.

  13. #28
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,688
    Thanks
    80
    Thanked 4,647 Times in 4,609 Posts
    Quote Originally Posted by pdiddles03 View Post
    One last thing, How come I have to load my page twice for my map to display?
    Because you coded something wrong?

    How can we guess without seeing your code?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  14. #29
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,688
    Thanks
    80
    Thanked 4,647 Times in 4,609 Posts
    Quote Originally Posted by donna1 View Post
    You put the word IF before a comparison and LET before an assignment and you can use = in both cases.
    Sure about that?

    Code:
    LET A = B = C = 7
    Only the first = there is an assignment!
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  15. #30
    New Coder donna1's Avatar
    Join Date
    Nov 2012
    Location
    london
    Posts
    99
    Thanks
    9
    Thanked 4 Times in 4 Posts
    yes well in my language you couldnt have a statement like A=B=C=7
    doesnt make any sense anyway
    if you want them all to be 7
    LET A=7;
    LET B=A;
    LET c=A;


 
Page 2 of 5 FirstFirst 1234 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •