simple drawing question

Previous topic - Next topic

mike_g

hi ive just started with glbasic on the gp2x. going nicely so far


ive chopped together some code. here it is:

// --------------------------------- //
// Project: Keyboardtypography
// Start: Monday, April 30, 2007
// IDE Version: 4.104


main_loop:
count1 = 0
count2 = 0
count3 = 0
LOADSPRITE "line.bmp", 0
WHILE TRUE // Endless-Loop (can use the counts to change the RGB values based on how many times the key has been pressed previously)

      DRAWLINE 100, 100, 110, 120, RGB(0, 0, 255); // Cyan

    IF KEY(57) = 1; PRINT "CLICKER is Pressed", 100, 100;

     DRAWLINE 100, 200, 150, 10, RGB(100, count1, count1);
     count1 = count1 +1;
     IF count1 >= 254 THEN count1 = 0;
     PRINT count1, 200, 200;
     ENDIF;
       IF KEY(30) = 1; PRINT "A is Pressed", 120, 100;
      FILLRECT 9,    50,    39,    80,    RGB(100, count2, count2) ;
     count2 = count2 +1;
     IF count2 >= 254 THEN count2 = 0;
     PRINT count2, 200, 220;
ENDIF;
IF KEY(32) = 1; PRINT "B is Pressed", 120, 100;
      FILLRECT 40,    50,    70,    80,    RGB(100, count3, count3) ;
     
     count3 = count3 +1;
     IF count3 >= 254 THEN count3 = 0;
     PRINT count3, 200, 230;
ENDIF;
    SHOWSCREEN
WEND
SHOWSCREEN
GOTO main_loop

///END of code


---basically what i want to do now is to draw a circle the same size as the square on the first keypress in the same place as the square. it would need to stay there after the key has been pressed also.

for each consectutive keypress i need a single line linking up each position of square .
and the line would also need to stay until clearscreen as with the circle.

any ideas?

regards
mike

mike_g

ignore the previous code. updated:

// --------------------------------- //
// Project: keyboardcircles
// Start: Monday, April 30, 2007
// IDE Version: 4.104


main_loop:
count1 = 0
count2 = 0
count3 = 0
count4 = 0
count5 = 0
count6 = 0
count7 = 0
count8 = 0


WHILE TRUE // Endless-Loop (can use the counts to change the RGB values based on how many times the key has been pressed previously)
FILLRECT 0, 0, 320, 240, RGB(255, 255, 255) // White


    IF KEY(57) = 1; PRINT "CLICKER is Pressed(will be CLS)", 100, 100;
    DRAWLINE 100, 200, 150, 10, RGB(100, count1, count1);
     count1 = count1 +1;
     IF count1 >= 254 THEN count1 = 0;
     PRINT count1, 200, 200;
     ENDIF;
     
       IF KEY(30) = 1; PRINT "A is Pressed", 120, 100;
      count2 = count2 +1;
     IF count2 >= 50 THEN count2 = 0;
      circ( 24, 65, count2,  RGB(0, 0, 0));
      PRINT count2, 200, 220;
      ENDIF;
     
     IF KEY(32) = 1; PRINT "B is Pressed", 120, 100;
      count3 = count3 +1;
     IF count3 >= 50 THEN count3 = 0;
      circ( 40, 65, count3,  RGB(179, 173, 132));
     PRINT count3, 200, 230;
    ENDIF;
   
    IF KEY(31) = 1; PRINT "X is Pressed", 120, 100;
      count4 = count4 +1;
     IF count4 >= 50 THEN count4 = 0;
      circ( 55, 65, count4,  RGB(77, 179, 113));
     PRINT count4, 200, 230;
    ENDIF;
   
    IF KEY(17) = 1; PRINT "Y is Pressed", 120, 100;
      count5 = count5 +1;
     IF count5 >= 50 THEN count5 = 0;
      circ( 70, 65, count5,  RGB(255, 0, 0));
     PRINT count5, 200, 230;
    ENDIF;
   
        IF KEY(42) = 1; PRINT "L is Pressed", 120, 100;
      count6 = count6 +1;
     IF count6 >= 50 THEN count6 = 0;
      circ( 85, 65, count6,  RGB(42, 28, 96));
     PRINT count6, 200, 230;
    ENDIF;
   
           IF KEY(54) = 1; PRINT "R is Pressed", 120, 100;
      count7 = count7 +1;
     IF count7 >= 50 THEN count7 = 0;
      circ( 100, 65, count7,  RGB(255, 255, 0));
     PRINT count7, 200, 230;
    ENDIF;
   
    SHOWSCREEN
WEND


SHOWSCREEN


GOTO main_loop


FUNCTION aliases:
//                   PC Key     : GP2X key
vk_space=57       // Space bar  : Joy click
vk_up=200         // Arrow Up   : Joy Up
vk_down=208       // Arrow Down : Joy Down
vk_left=203       // Arrow Left : Joy Left
vk_right=205      // Arrow Right: Joy Right
vk_a=30           // Letter 'A' : A Face button
vk_b=32           // Letter 'D' : B Face button
vk_x=31           // Letter 'S' : X Face button
vk_y=17           // Letter 'W' : Y Face button
vk_l=42           // Left Shift : Left Shoulder
vk_r=54           // Right Shift: Right Shoulder
vk_start=28       // Enter      : Start button
vk_select=15      // Tab        : Select button
vk_volup=201      // Page Down  : Volume Up
vk_voldown=209    // Page Up    : Volume Down
vk_escape=1       // Escape     : Volume Up&Down
vk_none=0         // No key     : No key

white   = RGB(255,255,255)
cyan    = RGB(0,255,255)
magenta = RGB(255,0,255)
ENDFUNCTION // KEYMAP

// ------------------------------------------------------------- //
// -=#  CIRC  #=-
// ------------------------------------------------------------- //
FUNCTION circ: x, y, r, c
    // These values are defined LOCAL:
// x, y, r, c

x1=SIN(0)*r
y1=COS(0)*r
FOR j=1 TO 360
    x2=SIN(j)*r
    y2=COS(j)*r
    DRAWLINE x+x1,y+y1,x+x2,y+y2,c
    x1=x2
    y1=y2
NEXT

ENDFUNCTION // CIRC



cheers for the circle code whoever did it BTW
P.S if i was to get the new breakout cradle and plugged in a usb keyboard would glbasic accept input from it?

regards
mike

Kitty Hello

Not yet. Should be easy to implement, though.

mike_g

thanks ill take my chances and get a cradle over the weekend.

any ideas about the previous line drawing question? this would now apply to the centre of the circles drawn. ie. how to draw lines from each in the right order and line color which stay on the screen until i tell it to clear?



regards

mike

Kitty Hello

If you want something to stay, then remember it in a variable, and draw it for every SHOWSCREEN.