# Qbasicnews.com

## QBasic => QB Discussion & Programming Help => Topic started by: Clay Dragon on January 11, 2008, 10:21:48 PM

 Title: Rotating a squared matrix Post by: Clay Dragon on January 11, 2008, 10:21:48 PM Hi, I'm working on a image (Tile) editor in Qbasic and my Rotate 90 degrees function doesn't work for smaller selections within a bigger image.So, to solve my problem I need to know how I can achieve this in QBasic: We have this matrix and the selection I made and I wish to rotate it 90 degrees clockwise:Before the rotation:(http://i175.photobucket.com/albums/w143/clay_dragon/before.gif)After the rotation:(http://i175.photobucket.com/albums/w143/clay_dragon/after.gif)Please help me!Regards,Clay Dragon Title: Re: Rotating a squared matrix Post by: Mac on January 23, 2008, 03:26:57 AM Quote from: Clay Dragon on January 11, 2008, 10:21:48 PMWe have this matrix and the selection I made and I wish to rotate it 90 degrees clockwiseYou have A(5,5) with content such asabcdefghijklmnopqrstuvwxyGiven you select one of the 9 interior cellsghilmnqrsYou want to rotate the adjacent cells two position clockwise. For example, if the cell chosen is r then you want the resultabcdefghijkvqlopwrmtuxsnyDoes that restate your problem correctly?Mac Title: Re: Rotating a squared matrix Post by: Mac on January 23, 2008, 01:23:53 PM Quote from: Mac on January 23, 2008, 03:26:57 AMDoes that restate your problem correctly?Assuming "yes", this will do itCode:' Populate demo arrayDIM a(5, 5) AS STRING * 1FOR i = 1 TO 5: FOR j = 1 TO 5  k = k + 1  a(i, j) = MID\$("abcdefghijklmnopqrstuvwxy", k, 1)NEXT j: NEXT i' Show RotationsDO: GOSUB Demo: LOOP WHILE R > 0CLSSYSTEMDemo:R = 0: C = 0CLS : PRINT "Array Before"GOSUB DumpAPRINT "Enter coordinates of pivot point"DO  INPUT "Enter 2, 3, or 4. Row"; R  IF R = 0 THEN RETURNLOOP WHILE NOT ((R = 2) OR (R = 3) OR (R = 4))DO  INPUT "Enter 2, 3, or 4. Column"; C  IF C = 0 THEN R = 0: RETURNLOOP WHILE NOT ((C = 2) OR (C = 3) OR (C = 4))GOSUB RotatePRINT "Array After"GOSUB DumpALINE INPUT "Press Enter"; e\$RETURNRotate:c1\$ = a(R - 1, C - 1)c2\$ = a(R, C - 1)a(R - 1, C - 1) = a(R + 1, C - 1)a(R, C - 1) = a(R + 1, C)a(R + 1, C - 1) = a(R + 1, C + 1)a(R + 1, C) = a(R, C + 1)a(R + 1, C + 1) = a(R - 1, C + 1)a(R, C + 1) = a(R - 1, C)a(R - 1, C + 1) = c1\$a(R - 1, C) = c2\$RETURNDumpA:FOR i = 1 TO 5  LOCATE , 30  FOR j = 1 TO 5    IF i = R AND j = C THEN COLOR 13, 0 ELSE COLOR 7, 0    PRINT a(i, j);  NEXT j  PRINTNEXT iPRINT : PRINTRETURN Title: Re: Rotating a squared matrix Post by: Clay Dragon on January 23, 2008, 09:31:20 PM Sorry for coming in so late, mac, but I do appreciate your help very much! However my problem is not simple as that! My first post is describing only a simple example of what I want to achieve! I want to be able to rotate any selection of 2x2, 3x3, 4x4... up to the max of the main matrix ranging from 2x2 up to 56x56.But I got to admit it is a good start and once again I want to thank you very much for your help, mac! Sadly, I must say I wasn't expecting that such a big code snipet would be necessary to realize my first wish:Code:Rotate:c1\$ = a(R - 1, C - 1)c2\$ = a(R, C - 1)a(R - 1, C - 1) = a(R + 1, C - 1)a(R, C - 1) = a(R + 1, C)a(R + 1, C - 1) = a(R + 1, C + 1)a(R + 1, C) = a(R, C + 1)a(R + 1, C + 1) = a(R - 1, C + 1)a(R, C + 1) = a(R - 1, C)a(R - 1, C + 1) = c1\$a(R - 1, C) = c2\$RETURNSo I guess I have to forget that idea it is to much complicated for me unless, of course, you really want to sort my problem out...Clay DragonP.S. I apologize for my bad english... Title: Re: Rotating a squared matrix Post by: Tia on January 24, 2008, 12:53:33 AM usually when you need monstrous amounts of code for certain tasks you may want to separate each task into its own section.  I would start off especially if you want to do this create a menu for each rotation so that a user can select which type of rotation he/she wants to do.  Personally I am not so great at coding but one thing I do know are standards and that was beaten to hell into my brain Title: Re: Rotating a squared matrix Post by: Clay Dragon on January 24, 2008, 01:06:20 AM Thank you for your input Tia!  :) Title: Re: Rotating a squared matrix Post by: Mac on January 24, 2008, 10:20:08 AM Quote from: Clay Dragon on January 23, 2008, 09:31:20 PMSorry for coming in so lateJan 12 - Asked questionJan 23 - Got answerJan 24 - "Sorry for coming in so late"That's funny. You waited for 13 days for a reply and responded within a day. Very nice person.Anyway, yep, it is hard. I give up. Good luck.Mac Title: Re: Rotating a squared matrix Post by: Clay Dragon on January 24, 2008, 09:36:30 PM Quote from: Mac on January 24, 2008, 10:20:08 AMQuote from: Clay Dragon on January 23, 2008, 09:31:20 PMSorry for coming in so lateJan 12 - Asked questionJan 23 - Got answerJan 24 - "Sorry for coming in so late"That's funny. You waited for 13 days for a reply and responded within a day. Very nice person.Anyway, yep, it is hard. I give up. Good luck.MacI said that because you replied twice to my question in the same day! I thought I wasn't fast enough for you! That's all...Anyway, I want to thank you again for your help!Regards,Clay Dragon Title: Re: Rotating a squared matrix Post by: Ralph on January 25, 2008, 01:40:58 AM Just as a challenge, I dug in, trying to come up with a solution for your 5x5 matrix.  I managed to write the code to do the trick for any selection of 2x2, 3x3, 4x4 and the 5x5.  I can rotate the outermost sqare 90 degrees in a clockwise or a counterclockwise direction, as many times as wanted, one by one.As can be seen, the code is quite repetitive, in part, and is susceptible, with a little more work, of being greatly reduced by using more FOR/NEXT, or SELECT CASE/END SELECT, or DO/LOOP.  In that manner, it could easily handle any size of square, up to the limit that I get, 127x127.  Obviously, this would meet the OP's requirement of a 56x56 square. Here's my code:Code:'ArrayRot, by Ralph A. Esquivel, 24 Jan 2008, creates a 5x5 array, then'allows selecting any 2x2, 3x3 or 4x4 submatrix, or the 5x5 matrix, then'rotate it +/-90ø (clock- or counterclock-wise), repeatedlyOPTION BASE 1 'I like to use arrays whose first element is 1.SCREEN 12CLS'size of array will be S,SSS = 5DIM array0(SS, SS) AS STRING * 1 'initial arrayDIM array1(SS, SS) AS STRING * 1 'final array'create array0 and array1FOR y = 1 TO SS  FOR x = 1 TO SS    READ m\$    array0(x, y) = m\$    array1(x, y) = m\$  NEXT xNEXT yGOSUB printArray0firstLine = y * vv 'first line of text'draw gridGOSUB drawGrid'PART THAT REPEATS STARTS HEREDO  DO    'clear all text below grid   LOCATE firstLine + 1, 1   FOR i = 1 TO 12     PRINT STRING\$(78, " ")   NEXT i    'enter size of block to rotate    LOCATE firstLine + 1, 4    PRINT "Enter horizontal dimension of block to rotate 90ø (+/-2 to +/-5): ";    LINE INPUT k\$    d\$ = k\$    d = VAL(d\$)    PRINT d  LOOP WHILE d = 0 OR ABS(d) > 5      DO    DO      'clear old text      cellChosen\$ = ""      LOCATE firstLine + 2, 4      FOR i = 1 TO 11        PRINT STRING\$(78, " ")      NEXT i         'find right-bottom-most letter allowed for top of block w/ dimension chosen      rbmL\$ = array1(SS + 1 - ABS(d), SS + 1 - ABS(d))       'enter letter for left-top letter of block to rotate     a\$ = "Enter top-left cell of block (A TO " + rbmL\$ + "): "     LOCATE firstLine + 2, 4     PRINT a\$;     GOSUB inkey     L\$ = UCASE\$(k\$)     PRINT L\$   LOOP WHILE L\$ = 0 OR L\$ < "A" OR L\$ > "Z"    'find x and y values for L\$ in array1    FOR y = 1 TO SS      FOR x = 1 TO SS        '''PRINT x; y,        IF array1(x, y) = L\$ THEN          ex\$ = "Yes"          EXIT FOR        END IF      NEXT x      IF ex\$ = "Yes" THEN EXIT FOR      PRINT    NEXT y    'reset ex\$    ex\$ = ""    'evaluate if cell chosen is appropriate for block chosen    maxvalue = SS + 1 - ABS(d)    IF x > maxvalue THEN      cellChosen\$ = "Bad"      PRINT " x ="; x; "is too large.  Choose an appopriate cell"      GOSUB pause    END IF    IF y > maxvalue THEN      cellChosen\$ = "Bad"      PRINT " y ="; y; "is too large.  Choose an appopriate cell"      GOSUB pause    END IF  LOOP WHILE cellChosen\$ = "Bad"   'create a temporary array for the block to be rotated  REDIM temp(x TO x + ABS(d) - 1, y TO y + ABS(d) - 1) AS STRING * 1   'rotate block chosen +/-90ø   IF d = 2 THEN    temp(x + 0, y + 0) = array1(x + 0, y + 1)    temp(x + 0, y + 1) = array1(x + 1, y + 1)       temp(x + 1, y + 0) = array1(x + 0, y + 0)    temp(x + 1, y + 1) = array1(x + 1, y + 0)   ELSEIF d = -2 THEN    temp(x + 0, y + 0) = array1(x + 1, y + 0)    temp(x + 0, y + 1) = array1(x + 0, y + 0)       temp(x + 1, y + 0) = array1(x + 1, y + 1)    temp(x + 1, y + 1) = array1(x + 0, y + 1)  END IF  IF d = 3 THEN    temp(x + 0, y + 0) = array1(x + 0, y + 2)    temp(x + 0, y + 1) = array1(x + 1, y + 2)    temp(x + 0, y + 2) = array1(x + 2, y + 2)    temp(x + 1, y + 0) = array1(x + 0, y + 1)    temp(x + 1, y + 1) = array1(x + 1, y + 1)    temp(x + 1, y + 2) = array1(x + 2, y + 1)     temp(x + 2, y + 0) = array1(x + 0, y + 0)    temp(x + 2, y + 1) = array1(x + 1, y + 0)    temp(x + 2, y + 2) = array1(x + 2, y + 0)   ELSEIF d = -3 THEN    temp(x + 0, y + 0) = array1(x + 2, y + 0)    temp(x + 0, y + 1) = array1(x + 1, y + 0)    temp(x + 0, y + 2) = array1(x + 0, y + 0)     temp(x + 1, y + 0) = array1(x + 2, y + 1)    temp(x + 1, y + 1) = array1(x + 1, y + 1)    temp(x + 1, y + 2) = array1(x + 0, y + 1)     temp(x + 2, y + 0) = array1(x + 2, y + 2)    temp(x + 2, y + 1) = array1(x + 1, y + 2)    temp(x + 2, y + 2) = array1(x + 0, y + 2)  END IF  IF d = 4 THEN    temp(x + 0, y + 0) = array1(x + 0, y + 3)    temp(x + 0, y + 1) = array1(x + 1, y + 3)    temp(x + 0, y + 2) = array1(x + 2, y + 3)    temp(x + 0, y + 3) = array1(x + 3, y + 3)    temp(x + 1, y + 0) = array1(x + 0, y + 2)    temp(x + 1, y + 1) = array1(x + 1, y + 2)    temp(x + 1, y + 2) = array1(x + 2, y + 2)    temp(x + 1, y + 3) = array1(x + 3, y + 2)    temp(x + 2, y + 0) = array1(x + 0, y + 1)    temp(x + 2, y + 1) = array1(x + 1, y + 1)    temp(x + 2, y + 2) = array1(x + 2, y + 1)    temp(x + 2, y + 3) = array1(x + 3, y + 1)    temp(x + 3, y + 0) = array1(x + 0, y + 0)    temp(x + 3, y + 1) = array1(x + 1, y + 0)    temp(x + 3, y + 2) = array1(x + 2, y + 0)    temp(x + 3, y + 3) = array1(x + 3, y + 0)  ELSEIF d = -4 THEN    temp(x + 0, y + 0) = array1(x + 3, y + 0)    temp(x + 0, y + 1) = array1(x + 2, y + 0)    temp(x + 0, y + 2) = array1(x + 1, y + 0)    temp(x + 0, y + 3) = array1(x + 0, y + 0)    temp(x + 1, y + 0) = array1(x + 3, y + 1)    temp(x + 1, y + 1) = array1(x + 2, y + 1)    temp(x + 1, y + 2) = array1(x + 1, y + 1)    temp(x + 1, y + 3) = array1(x + 0, y + 1)    temp(x + 2, y + 0) = array1(x + 3, y + 2)    temp(x + 2, y + 1) = array1(x + 2, y + 2)    temp(x + 2, y + 2) = array1(x + 1, y + 2)    temp(x + 2, y + 3) = array1(x + 0, y + 2)    temp(x + 3, y + 0) = array1(x + 3, y + 3)    temp(x + 3, y + 1) = array1(x + 2, y + 3)    temp(x + 3, y + 2) = array1(x + 1, y + 3)    temp(x + 3, y + 3) = array1(x + 0, y + 3)  END IF  IF d = 5 THEN    temp(x + 0, y + 0) = array1(x + 0, y + 4)    temp(x + 0, y + 1) = array1(x + 1, y + 4)    temp(x + 0, y + 2) = array1(x + 2, y + 4)    temp(x + 0, y + 3) = array1(x + 3, y + 4)    temp(x + 0, y + 4) = array1(x + 4, y + 4)    temp(x + 1, y + 0) = array1(x + 0, y + 3)    temp(x + 1, y + 1) = array1(x + 1, y + 3)    temp(x + 1, y + 2) = array1(x + 2, y + 3)    temp(x + 1, y + 3) = array1(x + 3, y + 3)    temp(x + 1, y + 4) = array1(x + 4, y + 3)    temp(x + 2, y + 0) = array1(x + 0, y + 2)    temp(x + 2, y + 1) = array1(x + 1, y + 2)    temp(x + 2, y + 2) = array1(x + 2, y + 2)    temp(x + 2, y + 3) = array1(x + 3, y + 2)    temp(x + 2, y + 4) = array1(x + 4, y + 2)    temp(x + 3, y + 0) = array1(x + 0, y + 1)    temp(x + 3, y + 1) = array1(x + 1, y + 1)    temp(x + 3, y + 2) = array1(x + 2, y + 1)    temp(x + 3, y + 3) = array1(x + 3, y + 1)    temp(x + 3, y + 4) = array1(x + 4, y + 1)    temp(x + 4, y + 0) = array1(x + 0, y + 0)    temp(x + 4, y + 1) = array1(x + 1, y + 0)    temp(x + 4, y + 2) = array1(x + 2, y + 0)    temp(x + 4, y + 3) = array1(x + 3, y + 0)    temp(x + 4, y + 4) = array1(x + 4, y + 0)  ELSEIF d = -5 THEN    temp(x + 0, y + 0) = array1(x + 4, y + 0)    temp(x + 0, y + 1) = array1(x + 3, y + 0)    temp(x + 0, y + 2) = array1(x + 2, y + 0)    temp(x + 0, y + 3) = array1(x + 1, y + 0)    temp(x + 0, y + 4) = array1(x + 0, y + 0)    temp(x + 1, y + 0) = array1(x + 4, y + 1)    temp(x + 1, y + 1) = array1(x + 3, y + 1)    temp(x + 1, y + 2) = array1(x + 2, y + 1)    temp(x + 1, y + 3) = array1(x + 1, y + 1)    temp(x + 1, y + 4) = array1(x + 0, y + 1)    temp(x + 2, y + 0) = array1(x + 4, y + 2)    temp(x + 2, y + 1) = array1(x + 3, y + 2)    temp(x + 2, y + 2) = array1(x + 2, y + 2)    temp(x + 2, y + 3) = array1(x + 1, y + 2)    temp(x + 2, y + 4) = array1(x + 0, y + 2)    temp(x + 3, y + 0) = array1(x + 4, y + 3)    temp(x + 3, y + 1) = array1(x + 3, y + 3)    temp(x + 3, y + 2) = array1(x + 2, y + 3)    temp(x + 3, y + 3) = array1(x + 1, y + 3)    temp(x + 3, y + 4) = array1(x + 0, y + 3)    temp(x + 4, y + 0) = array1(x + 4, y + 4)    temp(x + 4, y + 1) = array1(x + 3, y + 4)    temp(x + 4, y + 2) = array1(x + 2, y + 4)    temp(x + 4, y + 3) = array1(x + 1, y + 4)    temp(x + 4, y + 4) = array1(x + 0, y + 4)  END IF  'change elements in array1 to those in temp, the rotated block  IF d = 2 OR d = -2 THEN    array1(x + 0, y + 0) = temp(x + 0, y + 0)    array1(x + 0, y + 1) = temp(x + 0, y + 1)       array1(x + 1, y + 0) = temp(x + 1, y + 0)    array1(x + 1, y + 1) = temp(x + 1, y + 1)  END IF  IF d = 3 OR d = -3 THEN    array1(x + 0, y + 0) = temp(x + 0, y + 0)    array1(x + 0, y + 1) = temp(x + 0, y + 1)    array1(x + 0, y + 2) = temp(x + 0, y + 2)    array1(x + 1, y + 0) = temp(x + 1, y + 0)    array1(x + 1, y + 1) = temp(x + 1, y + 1)    array1(x + 1, y + 2) = temp(x + 1, y + 2)    array1(x + 2, y + 0) = temp(x + 2, y + 0)    array1(x + 2, y + 1) = temp(x + 2, y + 1)    array1(x + 2, y + 2) = temp(x + 2, y + 2)  END IF  IF d = 4 OR d = -4 THEN    array1(x + 0, y + 0) = temp(x + 0, y + 0)    array1(x + 0, y + 1) = temp(x + 0, y + 1)    array1(x + 0, y + 2) = temp(x + 0, y + 2)    array1(x + 0, y + 3) = temp(x + 0, y + 3)    array1(x + 1, y + 0) = temp(x + 1, y + 0)    array1(x + 1, y + 1) = temp(x + 1, y + 1)    array1(x + 1, y + 2) = temp(x + 1, y + 2)    array1(x + 1, y + 3) = temp(x + 1, y + 3)    array1(x + 2, y + 0) = temp(x + 2, y + 0)    array1(x + 2, y + 1) = temp(x + 2, y + 1)    array1(x + 2, y + 2) = temp(x + 2, y + 2)    array1(x + 2, y + 3) = temp(x + 2, y + 3)    array1(x + 3, y + 0) = temp(x + 3, y + 0)    array1(x + 3, y + 1) = temp(x + 3, y + 1)    array1(x + 3, y + 2) = temp(x + 3, y + 2)    array1(x + 3, y + 3) = temp(x + 3, y + 3)  END IF  IF d = 5 OR d = -5 THEN    array1(x + 0, y + 0) = temp(x + 0, y + 0)    array1(x + 0, y + 1) = temp(x + 0, y + 1)    array1(x + 0, y + 2) = temp(x + 0, y + 2)    array1(x + 0, y + 3) = temp(x + 0, y + 3)    array1(x + 0, y + 4) = temp(x + 0, y + 4)    array1(x + 1, y + 0) = temp(x + 1, y + 0)    array1(x + 1, y + 1) = temp(x + 1, y + 1)    array1(x + 1, y + 2) = temp(x + 1, y + 2)    array1(x + 1, y + 3) = temp(x + 1, y + 3)    array1(x + 1, y + 4) = temp(x + 1, y + 4)    array1(x + 2, y + 0) = temp(x + 2, y + 0)    array1(x + 2, y + 1) = temp(x + 2, y + 1)    array1(x + 2, y + 2) = temp(x + 2, y + 2)    array1(x + 2, y + 3) = temp(x + 2, y + 3)    array1(x + 2, y + 4) = temp(x + 2, y + 4)    array1(x + 3, y + 0) = temp(x + 3, y + 0)    array1(x + 3, y + 1) = temp(x + 3, y + 1)    array1(x + 3, y + 2) = temp(x + 3, y + 2)    array1(x + 3, y + 3) = temp(x + 3, y + 3)    array1(x + 3, y + 4) = temp(x + 3, y + 4)    array1(x + 4, y + 0) = temp(x + 4, y + 0)    array1(x + 4, y + 1) = temp(x + 4, y + 1)    array1(x + 4, y + 2) = temp(x + 4, y + 2)    array1(x + 4, y + 3) = temp(x + 4, y + 3)    array1(x + 4, y + 4) = temp(x + 4, y + 4)  END IF  'print new array1  GOSUB printArray1  LOCATE 17, 4  PRINT "Press to quit exit program, any other key to continue"  GOSUB inkey  IF k\$ = CHR\$(27) THEN ENDLOOPEND'--------------'DATA FOR ARRAYDATA A,B,C,D,EDATA F,G, H,I,JDATA K,L,M,N,ODATA P,Q,R,S,TDATA U,V,W,X,Y'==========================================================================='SUBROUTINESprintArray0:hh = 5: vv = 2FOR y = 1 TO SS  FOR x = 1 TO SS    LOCATE y * vv + 1, x * hh + 4: PRINT array0(x, y)  NEXT xNEXT yRETURNprintArray1:hh = 5: vv = 2FOR y = 1 TO SS  FOR x = 1 TO SS    LOCATE y * vv + 1, x * hh + 4: PRINT array1(x, y)  NEXT xNEXT yRETURNdrawGrid:'the following values were obtained by trial and error for horizontal linesht = 14 * 3: vt = 20FOR x = 1 TO SS + 1  LINE (x * ht, vt)-(x * ht, 9 * vt), 15NEXT x'the following values were obtained by trial and error for vertical linesva = 20: vt = vt + 12FOR y = -1 TO SS  LINE (ht, y * vt + va)-(6 * ht, y * vt + va), 15NEXT yRETURNinkey:k\$ = "": WHILE k\$ = "": k\$ = INKEY\$: WENDRETURNpause:WHILE INKEY\$ = "": WENDRETURN Title: Re: Rotating a squared matrix Post by: Dr_Davenstein on January 25, 2008, 02:20:52 AM I also made a small example. I wrote this in FB, using -lang qb, so i hope it runs ok under QBasic. I didn't add bounds checking because I thought it might be good practice for the guy who wants the code to add it himself.  ;)Code:declare sub rotate_array( mat() as string, px as integer, py as integer, swath as integer )screen 13DEFINT A-Zdim mat(1 to 5, 1 to 5) as stringdim x, y, ch, px, py, swathfor y = 1 to ubound(mat,2)    for x = 1 to ubound(mat,1)        mat(x,y) = chr\$(ch+65)        ch = ch + 1    next xnext yfor y = 1 to ubound(mat,2)    for x = 1 to ubound(mat,1)        locate (y*2)-1,(x*2)-1        print mat(x,y);        locate (y*2)-1,((x+6)*2)-1        print mat(x,y);    next xnext ypx = 3py = 3swath = 1rotate_array( mat(), px, py, swath )clscolor(15)for y = 1 to ubound(mat,2)    for x = 1 to ubound(mat,1)        locate (y*2)-1, (x*2)-1        print mat(x,y);    next xnext ysub rotate_array( mat() as string, px as integer, py as integer, swath as integer )    'BEWARE: NO BOUNDS CHECKING!!!    'adding it might be good practice        dim x, y as integer    dim temp( ubound(mat,1), ubound(mat,2) ) as string        for y = 1 to ubound(mat,2)        for x = 1 to ubound(mat,1)            temp(x,y) = mat(x,y)        next x    next y        for y = -swath to swath        for x = -swath to swath                        color(4)            locate ((py-x)*2)-1, ((px+y)*2)-1            print temp(px+y,py-x);                        mat(px+x,y+py) = temp(px+y,py-x)                        color(14)            locate ((py+y)*2)-1, ((px+x+6)*2)-1            print mat(px+x,py+y);                        sleep 1        next x    next y    end sub Title: Re: Rotating a squared matrix Post by: Ralph on January 25, 2008, 02:09:08 PM Dr_Davenstein:How are you?  Say, I tried your program in QuickBASIC.  The DECLARE SUB requires "parameters".  Since I am not into SUBs enough, I changed your SUB into a subroutine, so, in front of your "rotate", I added GOSUB.  IT WORKED PERFECTLY!  I would like to say that I really feel awed with your very short coding, and I will study it intensely, so that I may learn!  Thank you for posting it.Of course, to reach the OP's goal, he will have to change from SCREEN 13 to SCREEN 12.  And, I don't know if we can accomodate his array with dimension 56x56! Title: Re: Rotating a squared matrix Post by: Clay Dragon on January 25, 2008, 02:56:56 PM Hey guys, both of your code work are awesome! I can't wait to see the final results!Thank you for helping me!Clay dragon Title: Re: Rotating a squared matrix Post by: Dr_Davenstein on January 25, 2008, 09:51:20 PM Hi, Ralph. I've been great, really. Thanks for the compliment. How are you doing? :)Since I haven't seen you for a while, I'd like to mention this because I programmed something interesting recently. Have you ever heard of anaglyph? It's the name for images/movies that require those red/blue 3d glasses to view correctly. I've always wanted to try making something like that. Well, I did and I'm pretty happy with the results. Anyway, Here's a link, if you're interested. :)http://dave-stanley.dyndns.org/programs/stereo.zipHave you programmed anything fun lately? I mean besides the code above. See ya around! ;) Title: Re: Rotating a squared matrix Post by: Mac on January 26, 2008, 01:39:27 AM Quote from: Mac on January 24, 2008, 10:20:08 AMAnyway, yep, it is hard. I give up. Good luck.Evidently not too hard for the first team! Thanks for saving the thread, Ralph and Dr. Davidstein.Mac Title: Re: Rotating a squared matrix Post by: Ralph on January 26, 2008, 02:01:17 AM Dr_Davenstein:QuoteSince I haven't seen you for a while I guess the modern expresion, LOL, is in order.  I haven't ever seen you, nor you, me!  (I just couldn't pass that opportunity up!  I hope you have a good sense of humor.)From time to time, in this or that QB forum, I see you contributing a post or two, and, usually, the theme is beyond my programming understanding and ability, so, I don't get into the responses.As to your anaglyph files, I tried to run the first .bas program from your zip file in QB 4.5; no dice, it stopped me at the first line.  So, rather than try to convert the program to run in QB, I ran your two .exe files.  They ran very smoothly, but I am going to have to find me a pair of blue and red "eye glasses", or, at least, a blue and a red piece of cellophane.  The program seems interesting.  The second .exe program, I ran in "mode" 1, the one you seem to prefer, of the four "modes". Undoubtedly, I'll be  missing the main reason for such programs, until I can get my 3-D eye pieces!The only interesting thing (to me) that I've done is an Excel spreadsheet with IRS Form 1040, which looks "just like" the original, except I haven't used color on it.  I did it for myself, starting out with just the calculations, and ending up with the whole form.  For my simple case, it works fine.  And, once I've inputted all the required data, I just print it out and put it in the mail.  It's been accepted by the IRS for my first go at it for the 2006 tax year, and I will do the same for 2007.  As soon as I send in 2007, I'll advance the one for 2008 as much as I can, assuming some of the probable entries, to see where I can do things to reduce the tax.  I know that there are many programs out there that do this, but, I have always preferred my own.  I always run into things that I   I have not gotten further into fb, as my needs are usually very simple, and I don't want to have to learn more "stuff" whenever I want to do a small program.  QB is so logical for my engineering mind, that I don't want to abandon the simplicity of most of what I do in QB.   Title: Re: Rotating a squared matrix Post by: Ralph on January 26, 2008, 02:24:19 AM ClayDragon:First, thanks for the kudos.  These are always welcome.  But...You said, "I can't wait to see the final results".  What do you mean?  If you want "final results", we expect you to start contributing comments and code.  The reason for these forums is to help people that are interested in programming, or even in just one particular proyect, and learning how to code it.  We help, but don't do the "final result", unless the poster helps, too.  So, post some code and ask away. Title: Re: Rotating a squared matrix Post by: Dr_Davenstein on January 26, 2008, 03:24:18 AM That's cool. I tried doing my own taxes a cople of times, but I realy hated it, so I just take them to a pro these days. They usually get me more anyway, since they know more about our variable tax laws.About the programs: Yeah, unfortunately, they wont compile with any version of QB. They use a FB library that me and a few friends programmed. Title: Re: Rotating a squared matrix Post by: Dr_Davenstein on January 26, 2008, 03:24:58 AM Quote from: Ralph on January 26, 2008, 02:24:19 AMClayDragon:First, thanks for the kudos.  These are always welcome.  But...You said, "I can't wait to see the final results".  What do you mean?  If you want "final results", we expect you to start contributing comments and code.  The reason for these forums is to help people that are interested in programming, or even in just one particular proyect, and learning how to code it.  We help, but don't do the "final result", unless the poster helps, too.  So, post some code and ask away.Seconded! ;) Title: Re: Rotating a squared matrix Post by: Clay Dragon on January 26, 2008, 06:11:10 PM Quote from: Ralph on January 26, 2008, 02:24:19 AMClayDragon:First, thanks for the kudos.  These are always welcome.  But...You said, "I can't wait to see the final results".  What do you mean?  If you want "final results", we expect you to start contributing comments and code.  The reason for these forums is to help people that are interested in programming, or even in just one particular proyect, and learning how to code it.  We help, but don't do the "final result", unless the poster helps, too.  So, post some code and ask away.By "final results", I meant the code snipet I could use to replace the part that is not working properly in my tile editor. I don't have your coding skills. I used to be good at coding but now I'm quite rusted after years of inactivity in the coding department...So here is the code anyway: (the following is the sub that doesn't work properly. The very part that does work only for a complete grid selection is in the very end of the sub starting from case "R". That's the part that I want to replace with your code snipet)If you want all the source code, it is here (http://www.cooptel.qc.ca/~clay/qbasic/rpgfx25.zip) (executable included).Code:flip.rotate:IF x% = xmax% - 3 OR y% = ymax% - 3 THEN GOTO 11COLOR 10LOCATE 23, 1SELECT CASE A\$ CASE "H": PRINT "Define area for horizontal flip..." CASE "V": PRINT "Define area for vertical flip..." CASE "R": PRINT "Define area for rotation..."END SELECTCOLOR 15B\$ = "": mx% = x%: my% = y%: x% = x% + 6: y% = y% + 6DO LOCATE 23, 36: PRINT "     ": LOCATE 23, 36 IF A\$ = "H" OR A\$ = "V" THEN  PRINT LTRIM\$(STR\$((x% - mx%) / 3)) + "x" + LTRIM\$(STR\$((y% - my%) / 3)) ELSE  PRINT LTRIM\$(STR\$((x% - mx%) / 3)) + CHR\$(253) END IF GET (mx% + (x% - mx%) / 2 - 2, my% + (y% - my%) / 2 - 2)-(mx% + (x% - mx%) / 2 + 2, my% + (y% - my%) / 2 + 2), buffer DO WHILE B\$ = ""  FOR i% = 0 TO 1   LINE (mx%, my%)-(x%, y%), 15 * i%, B   LINE (mx% + (x% - mx%) / 2, my% + (y% - my%) / 2 - 2)-(mx% + (x% - mx%) / 2, my% + (y% - my%) / 2 + 2), 15 * i%, B   LINE (mx% + (x% - mx%) / 2 - 2, my% + (y% - my%) / 2)-(mx% + (x% - mx%) / 2 + 2, my% + (y% - my%) / 2), 15 * i%, B   FOR j% = 1 TO 300    B\$ = INKEY\$    IF B\$ <> "" THEN EXIT FOR   NEXT j%   IF B\$ <> "" THEN EXIT FOR  NEXT i% LOOP LINE (mx%, my%)-(x%, y%), 19, B PUT (mx% + (x% - mx%) / 2 - 2, my% + (y% - my%) / 2 - 2), buffer, PSET B\$ = UCASE\$(B\$) SELECT CASE B\$  CASE CHR\$(0) + CHR\$(72): GOSUB check.up: IF A\$ = "R" THEN GOSUB check.left  CASE CHR\$(0) + CHR\$(80):   GOSUB check.down   IF A\$ = "R" THEN    GOSUB check.right    IF mx% - my% <> x% - y% THEN x% = mx% + 6: y% = my% + 6   END IF  CASE CHR\$(0) + CHR\$(77):   GOSUB check.right   IF A\$ = "R" THEN    GOSUB check.down    IF mx% - my% <> x% - y% THEN x% = mx% + 6: y% = my% + 6   END IF  CASE CHR\$(0) + CHR\$(75): GOSUB check.left: IF A\$ = "R" THEN GOSUB check.up  CASE CHR\$(13): EXIT DO  CASE CHR\$(27): x% = mx%: y% = my%: GOTO 10 END SELECT B\$ = ""LOOPLINE (mx%, my%)-(x%, y%), 15, BIF A\$ = "H" OR A\$ = "V" THEN COLOR 10 LOCATE 23, 1 PRINT "Mirror effect (Y/N)?                    " B\$ = "" DO WHILE B\$ = ""  B\$ = UCASE\$(INKEY\$)  IF B\$ <> "" THEN IF B\$ <> "Y" AND B\$ <> "N" THEN B\$ = "" LOOP LOCATE 23, 22: PRINT B\$ mirror% = ASC(B\$) \ 89END IFIF A\$ = "R" THEN COLOR 10 LOCATE 23, 1 PRINT "Rotate which way: (R)ight or (L)eft?    " B\$ = "" DO WHILE B\$ = ""  B\$ = UCASE\$(INKEY\$)  IF B\$ <> "" THEN IF B\$ <> "R" AND B\$ <> "L" THEN B\$ = "" LOOP LOCATE 23, 38: PRINT B\$END IFCOLOR 15LINE (mx% + (x% - mx%) / 2, my% + (y% - my%) / 2 - 2)-(mx% + (x% - mx%) / 2, my% + (y% - my%) / 2 + 2), 19, BLINE (mx% + (x% - mx%) / 2 - 2, my% + (y% - my%) / 2)-(mx% + (x% - mx%) / 2 + 2, my% + (y% - my%) / 2), 19, BLINE (mx%, my%)-(x%, y%), 19, BFOR j% = mx% / 3 TO x% / 3 - 1 FOR i% = my% / 3 TO y% / 3 - 1  buffer(j%, i%) = POINT(171 + j%, 1 + i%) NEXT i%NEXT j%FOR j% = mx% / 3 TO x% / 3 - 1 FOR i% = my% / 3 TO y% / 3 - 1  SELECT CASE A\$   CASE "H":    IF i% < (my% / 3 + y% / 3) / (mirror% + 1) THEN     LINE (1 + j% * 3, 1 + ((my% / 3 + y% / 3) - i% - 1) * 3)-(2 + j% * 3, 2 + ((my% / 3 + y% / 3) - i% - 1) * 3), buffer(j%, i%), BF     PSET (171 + j%, 1 + (my% / 3 + y% / 3) - i% - 1), buffer(j%, i%)    END IF   CASE "V":    IF j% < (mx% / 3 + x% / 3) / (mirror% + 1) THEN     LINE (1 + ((mx% / 3 + x% / 3) - j% - 1) * 3, 1 + i% * 3)-(2 + ((mx% / 3 + x% / 3) - j% - 1) * 3, 2 + i% * 3), buffer(j%, i%), BF     PSET (171 + (mx% / 3 + x% / 3 - j% - 1), 1 + i%), buffer(j%, i%)    END IF   CASE "R":    IF B\$ = "R" THEN     LINE (1 + (i% * 3), 1 + (j% * 3))-(2 + (i% * 3), 2 + (j% * 3)), buffer(j%, y% / 3 - i% - 1), BF     PSET (171 + i%, 1 + j%), buffer(j%, y% / 3 - i% - 1)    ELSE     LINE (1 + (i% * 3), 1 + (j% * 3))-(2 + (i% * 3), 2 + (j% * 3)), buffer(x% / 3 - j% - 1, i%), BF     PSET (171 + i%, 1 + j%), buffer(x% / 3 - j% - 1, i%)    END IF  END SELECT NEXT i%NEXT j%x% = mx%: y% = my%GOTO 10 Title: Re: Rotating a squared matrix Post by: Ralph on January 28, 2008, 06:26:58 PM Claydragon, you wrote:QuoteBy "final results", I meant the code snipet I could use to replace the part that is not working properly in my tile editor. I don't have your coding skills. I used to be good at coding but now I'm quite rusted after years of inactivity in the coding department...I understand you.  However, there is too much code for me to try to understand just what it is that you need.  I would suggest that you write pseudocode to explain what you need.  Then, maybe I can help you.  But, perhaps Dr_Davenstein can help you, at this point?  Title: Re: Rotating a squared matrix Post by: Clay Dragon on September 18, 2009, 01:46:41 AM I solved my problem! Thanks