Move the circle by shares of the keyboard

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • merak
    New Member
    • Dec 2012
    • 4

    Move the circle by shares of the keyboard

    Move the circle by shares of the keyboard
    PANEL shares Alfatyh from right to left Wen top to bottom using Switch or for Please help me to and ÇĘäě you a wonderful book for learning drawing in C + + I was not going to weigh you
    Thank you
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I have no idea what you said.

    Comment

    • merak
      New Member
      • Dec 2012
      • 4

      #3
      Insufficiency
      Department Ahrkha from right to left and from top to bottom across the keyboard

      Comment

      • merak
        New Member
        • Dec 2012
        • 4

        #4
        Look at this code in the language of HTML5
        And you know what I want
        Save this page HTML code in Notepad and Stdahr evoked the right circle money up under
        (
        Code:
        <!doctype html>
        <html>
        <head>
        <meta charset="UTF-8" />
        <title>Canvas Test</title>
        </head>
        <body>
        <section>
        
        <div>
        <canvas id="canvas" width="300" height="200">
        This text is displayed if your browser does not support HTML5 Canvas.
        </canvas>
        </div>
        
        <script type="text/javascript">
        var canvas;
        var ctx;
        var dx = 5;
        var dy = 5;
        var x = 150;
        var y = 100;
        var WIDTH = 300;
        var HEIGHT = 200;
        
        function circle(x,y,r) {
        ctx.beginPath();
        ctx.arc(x, y, r, 0, Math.PI*2, true);
        ctx.fill();
        }
        
        function rect(x,y,w,h) {
        ctx.beginPath();
        ctx.rect(x,y,w,h);
        ctx.closePath();
        ctx.fill();
        ctx.stroke();
        }
        
        function clear() {
        ctx.clearRect(0, 0, WIDTH, HEIGHT);
        }
        
        function init() {
        canvas = document.getElementById("canvas");
        ctx = canvas.getContext("2d");
        return setInterval(draw, 10);
        }
        
        function doKeyDown(evt){
        switch (evt.keyCode) {
        case 38:  /* Up arrow was pressed */
        if (y - dy > 0){
        y -= dy;
        }
        break;
        case 40:  /* Down arrow was pressed */
        if (y + dy < HEIGHT){
        y += dy;
        }
        break;
        case 37:  /* Left arrow was pressed */
        if (x - dx > 0){
        x -= dx;
        }
        break;
        case 39:  /* Right arrow was pressed */
        if (x + dx < WIDTH){
        x += dx;
        }
        break;
        }
        }
        
        function draw() {
        clear();
        ctx.fillStyle = "white";
        ctx.strokeStyle = "black";
        rect(0,0,WIDTH,HEIGHT);
        ctx.fillStyle = "purple";
        circle(x, y, 10);
        }
        
        init();
        window.addEventListener('keydown',doKeyDown,true);
        </script>
        </section>
        </body>
        </html>
        )



        I am a newbie in C + +, I could not turn this code into the language of C + +
        Last edited by Rabbit; Dec 20 '12, 06:08 PM. Reason: Please use code tags when posting code.

        Comment

        • merak
          New Member
          • Dec 2012
          • 4

          #5
          This is a difficult question I do not understand

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            I doubt anyone here can help you. Converting javascript to C++ reuires in-depth knowledge of both Javascript and C++ which means your problem is too big for a thread like this.

            Also, I have no idea what you want to do.

            I suggest posting a simpler question instead of this vague large one.

            Comment

            • divideby0
              New Member
              • May 2012
              • 131

              #7
              Though I don't really get what you're wanting to do, graphics wise, you can *probably* get close to this using one of the older turboc compilers - I have no idea with modern compilers. check here for turbo's graphic routines. setInterval should be fun to replicate... try playing around with delay, sleep, or maybe making something from time_t

              Code:
              ...
              #include <graphics.h>
              #include <conio.h>
              ...
              
              int main(void)
              {
              
              // declare and initialize any graphics related variables
              int ch;
              
              // init graphics mode
              
              for(;;) 
              {
                 ch = getch();
                 if(ch == exit_program_normal_key) break;
              
                 if(ch == 0) // extended key hit 
                 {
                    switch(getch()) 
                    {
                        // process arrow keys
                    }
               
                    // redraw graphics if desired 
                 }
              
                 // some sort of timer
                 // redraw graphics
              }
              
              // clean up graphics
              return 0;
              }
              if you require initial user input, ask for and process it before entering the for loop. if you're expecting internet interaction, then don't even bother with turbo.

              keep in mind that whatever you come up with, it will be compiler specific and not very portable; it's not something that can be done in standard c/c++.

              Comment

              Working...