Author Topic: Star Backgound  (Read 32699 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Star Backgound
« Reply #60 on: June 30, 2018, 07:08:51 am »
Johnno56, I can try to rewrite it if you give me your code in SDL. I'm not saying I'll do it, but I can try it after I come back if you want.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Star Backgound
« Reply #61 on: June 30, 2018, 07:37:27 am »
This maybe help you more:

Code: QB64: [Select]
  1. 'The command is: blt(slot, sx, sy, sw, sh, dx, dy)
  2. 'slot: where the image is stored
  3. 'sx: Source X coordinate
  4. 'sy: Source Y coordinate
  5. 'sw: Source image width
  6. 'sh: Source image height
  7. 'dx: Destination screen X coordinate
  8. 'dy: Destination screen Y coordinate
  9. '-----------------------------------------------
  10.  
  11.  
  12. 'create source image: (165 frames contains number)
  13.  
  14. source& = _NEWIMAGE(800, 600, 256)
  15. _DEST source& 'after this i write to graphic screen source&, but is unvisible!
  16. FOR y = 0 TO 800 STEP 40
  17.     FOR x = 0 TO 600 STEP 60
  18.         frame = frame + 1
  19.         LINE (x, y)-(x + 59, y + 39), , B
  20.         _PRINTSTRING (x + 5, y + 8), STR$(frame)
  21. NEXT x, y
  22.  
  23. 'show source:
  24. SCREEN source&
  25.  
  26. 'as i see, _Putimage can be the same as blt?:
  27. SCREEN _NEWIMAGE(320, 240, 256)
  28.  
  29.  
  30. FOR ShowY = 0 TO 800 STEP 40
  31.     FOR ShowX = 0 TO 600 STEP 60
  32.         _PUTIMAGE (140, 130), source&, 0, (ShowX, ShowY)-(ShowX + 59, ShowY + 39)
  33.         SLEEP
  34.     NEXT ShowX
  35. NEXT ShowY
  36.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Star Backgound
« Reply #62 on: June 30, 2018, 07:39:09 am »
        _PUTIMAGE 'full source image to fit full destination area after _SOURCE and _DEST are set
       

        _PUTIMAGE , sourceHandle&, destHandle& 'size full source to fit full destination area
       

        _PUTIMAGE (dx1, dy1), sourceHandle&, destHandle& 'full source to top-left corner destination position
       

        _PUTIMAGE (dx1, dy1)-(dx2, dy2), sourceHandle&, destHandle& 'size full source to destination coordinate area
       

        _PUTIMAGE (dx1, dy1), sourceHandle&, destHandle&, (sx1, sy1)-(sx2, sy2) 'portion of source to the top-left corner of the destination page
       

        _PUTIMAGE , sourceHandle&, destHandle&, (sx1, sy1)-(sx2, sy2) 'portion of source to full destination area
       

        _PUTIMAGE (dx1, dy1)-(dx2, dy2), sourceHandle&, destHandle&,(sx1, sy1) 'right side of source from top-left corner to destination
       

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Star Backgound
« Reply #63 on: June 30, 2018, 08:46:35 am »
Petr,

I have attached the program and images. I made this in mid December of 2016. The images are crude but they serve the purpose of demo.

Sdlbasic does have the ability to create an executable, the only problem is, I am using Linux and the executable is OS specific.

J

I hope this helps...
* walking.zip (Filesize: 52.16 KB, Downloads: 249)
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Star Backgound
« Reply #64 on: June 30, 2018, 10:02:39 am »
I love it when I translate code from one Basic to another without a single error!
Code: QB64: [Select]
  1. _TITLE "Walking Man trans by bplus started 2018-06-30"
  2. 'QB64 version 2017 1106/82 (the day before they switched to version 1.2)
  3. CONST xmax = 800
  4. CONST ymax = 600
  5. SCREEN _NEWIMAGE(xmax, ymax, 32)
  6. _SCREENMOVE 360, 60
  7.  
  8. walk& = _LOADIMAGE("walking720x146.png") ' 8 positions at 90 x 146   walk& is same as slot number
  9. manW = 90 'width of man image
  10. manH = 146 'height of man image
  11. manN = 0 'man number 0 to 7 as walks = nSteps mod 8
  12. nSteps = 0
  13. manY = (ymax - manH) \ 2 'place top man image at manY always as walks across the screen
  14. manX = -manW 'start off screen by 1 manW  manX is x location on screen of man
  15.  
  16. WHILE 0 = 0
  17.     CLS
  18.     ' blt(1, x*90, 0, 90, 146, movex, 45)
  19.     '
  20.     '   blt(sprite number,starting x position, starting y position, image width, image height, destination x, and y)
  21.     '
  22.     '   (I prefer a strip of characters. Others may use a 'grid' of characters.)
  23.     '
  24.     '   Sprite #1 is the 'walking' strip of characters
  25.     '
  26.     '   when x = 0 it will grab the first image locate at x*90 with a width of 90px and a height of 146px
  27.     '   and display it at 'movex'x and 45y. Perform a short delay; increment to the next image; If the
  28.     '   image grabbed is greater than 7 (the last image) then reset the image count to 0 (first image).
  29.     '   move the curent image 5 pixels to the right. If the image moves off screen, make it reappear on
  30.     '   the other side. Continue doing this until the escape key is pressed.
  31.  
  32.  
  33.     '' _PUTIMAGE [STEP] [(dx1, dy1)-[STEP][(dx2, dy2)]][, sourceHandle&][, destHandle&][, ][STEP][(sx1, sy1)[-STEP][(sx2, sy2)]][_SMOOTH]
  34.  
  35.     'THE SKINNY: (notice the unintuitive positions of source handle and destination handle)
  36.     'destination coordinates:  (x, y)-(x2, y2)  <<<< syntax
  37.     'then source (image) handle (walk),
  38.     'then destination handle = 0 for screening, then coordinates of image in
  39.     'finally source coordinates off image of image handle:  (x, y)-(x2, y2)  <<<< syntax
  40.  
  41.     _PUTIMAGE (manX, manY)-STEP(manW, manH), walk&, 0, (manN * 90, 0)-STEP(manW, manH)
  42.     manN = (manN + 1) MOD 8 'increase image index until hit 7 then back to 0
  43.     manX = manX + 10
  44.     IF manX >= xmax THEN manX = -manW 'move man back to left side of screen when hit right side
  45.     _DISPLAY 'like   waitvbl(100) in sdlbas
  46.     _LIMIT 10 'like wait(100) this limits displays to 10 per second
  47.  
  48.  
Man Walking.PNG
* Man Walking.PNG (Filesize: 9.36 KB, Dimensions: 808x624, Views: 324)
« Last Edit: June 30, 2018, 10:06:16 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Star Backgound
« Reply #65 on: June 30, 2018, 10:07:41 am »
Well didn't need nSteps but can't remove it now. ;(

Too bad I can't make posts without single error! ;D
« Last Edit: June 30, 2018, 10:11:22 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Star Backgound
« Reply #66 on: June 30, 2018, 10:25:31 am »
OH hey! Who can have man walk across Mars, first! ?

Or use Mars as a sort of treadmill?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Star Backgound
« Reply #67 on: June 30, 2018, 03:12:05 pm »
Hi Johnno56. I see that BPlus  tried it too. So here is my version:

Code: QB64: [Select]
  1. '
  2. '   Walking
  3. '
  4.  
  5. 'setDisplay(1024,232,32,1)
  6. SCREEN _NEWIMAGE(1024, 232, 32) ' (this is _DEST 0, or 0 in use with _PUTIMAGE)
  7. movex = -90
  8.  
  9. 'loadImage("assets/walking720x146.png",1)
  10. source& = _LOADIMAGE(".\assets\walking720x146.png", 32)
  11.  
  12.  
  13.  
  14. x = 0
  15. WHILE 0 = 0
  16.     CLS
  17.     '    blt(1,x*90,0,90,146,movex,45)
  18.     _PUTIMAGE (movex, 45), source&, 0, (x * 90, 0)-(x * 90 + 90, 146)
  19.     '
  20.     '   blt(sprite number,starting x position, starting y position, image width, image height, destination x, and y)
  21.     '
  22.     '   (I prefer a strip of characters. Others may use a 'grid' of characters.)
  23.     '
  24.     '   Sprite #1 is the 'walking' strip of characters
  25.     '
  26.     '   when x = 0 it will grab the first image locate at x*90 with a width of 90px and a height of 146px
  27.     '   and display it at 'movex'x and 45y. Perform a short delay; increment to the next image; If the
  28.     '   image grabbed is greater than 7 (the last image) then reset the image count to 0 (first image).
  29.     '   move the curent image 5 pixels to the right. If the image moves off screen, make it reappear on
  30.     '   the other side. Continue doing this until the escape key is pressed.
  31.     '    waitvbl()
  32.     '   wait(100)
  33.     _DELAY .1
  34.  
  35.     x = x + 1
  36.     '    if x > 7 then: x = 0: end if
  37.     IF x > 7 THEN x = 0
  38.     movex = movex + 5
  39.     '    if movex > 1024 then: movex = -90: end if
  40.     IF movex > 1024 THEN movex = -90
  41.  
  42.     'if key(27) then: exit while: end if
  43.     IF _KEYHIT = 27 THEN EXIT WHILE
  44. _FREEIMAGE source&
  45.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Star Backgound
« Reply #68 on: June 30, 2018, 03:56:12 pm »
And here  walks to and fro:

Code: QB64: [Select]
  1.  
  2.  
  3. '
  4. '   Walking
  5. '
  6.  
  7. 'setDisplay(1024,232,32,1)
  8. SCREEN _NEWIMAGE(1024, 232, 32) ' (this is _DEST 0, or 0 in use with _PUTIMAGE)
  9. movex = -90
  10.  
  11. 'loadImage("assets/walking720x146.png",1)
  12. source& = _LOADIMAGE(".\assets\walking720x146.png", 32)
  13. source2& = ReverseImage&(source&)
  14.  
  15. movestep = 5
  16. x = 0
  17. WHILE 0 = 0
  18.     CLS
  19.     '    blt(1,x*90,0,90,146,movex,45)
  20.     IF walk = 0 THEN _PUTIMAGE (movex, 45), source&, 0, (x * 90, 0)-(x * 90 + 90, 146)
  21.     IF walk = 1 THEN _PUTIMAGE (movex, 45), source2&, 0, (x * 90, 0)-(x * 90 + 90, 146)
  22.     '
  23.     '   blt(sprite number,starting x position, starting y position, image width, image height, destination x, and y)
  24.     '
  25.     '   (I prefer a strip of characters. Others may use a 'grid' of characters.)
  26.     '
  27.     '   Sprite #1 is the 'walking' strip of characters
  28.     '
  29.     '   when x = 0 it will grab the first image locate at x*90 with a width of 90px and a height of 146px
  30.     '   and display it at 'movex'x and 45y. Perform a short delay; increment to the next image; If the
  31.     '   image grabbed is greater than 7 (the last image) then reset the image count to 0 (first image).
  32.     '   move the curent image 5 pixels to the right. If the image moves off screen, make it reappear on
  33.     '   the other side. Continue doing this until the escape key is pressed.
  34.     '    waitvbl()
  35.     '   wait(100)
  36.     _DELAY .1
  37.  
  38.     ' IF walk = 0 THEN x = x + 1 ELSE x = x - 1
  39.     IF walk = 0 THEN x = x + 1: IF x > 7 THEN x = 0
  40.     IF walk = 1 THEN x = x - 1: IF x < 0 THEN x = 7
  41.     '    if x > 7 then: x = 0: end if
  42.  
  43.     movex = movex + movestep
  44.     '    if movex > 1024 then: movex = -90: end if
  45.     IF movex > 1024 THEN
  46.         IF walk = 0 THEN walk = 1: movestep = -5
  47.     END IF
  48.     IF movex < -90 THEN walk = 0: movestep = 5
  49.     'if key(27) then: exit while: end if
  50.     IF _KEYHIT = 27 THEN EXIT WHILE
  51. _FREEIMAGE source&
  52.  
  53.  
  54.  
  55. FUNCTION ReverseImage& (image AS LONG)
  56.     H = _HEIGHT(image&)
  57.     W = _WIDTH(image&)
  58.     IF _PIXELSIZE(image&) <= 1 THEN D = 256 ELSE D = 32
  59.     ReverseImage& = _NEWIMAGE(W, H, D)
  60.     _MAPTRIANGLE (0, 0)-(W, 0)-(0, H), image& TO(W, 0)-(0, 0)-(W, H), ReverseImage&
  61.     _MAPTRIANGLE (0, H)-(W, H)-(W, 0), image& TO(W, H)-(0, H)-(0, 0), ReverseImage&
  62.  
« Last Edit: June 30, 2018, 03:57:22 pm by Petr »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Star Backgound
« Reply #69 on: June 30, 2018, 06:00:30 pm »
Thanks guys.

I would not have had a snowball's chance of figuring out all that 'source' stuff...

'bplus': Thank you for the comments. Puts my chaotic thoughts into some semblance of order... lol

'petr': Two things. 1. Reverseimage! Cool. and 2. You are the first person that I know of that uses the correct phrase, "to and fro". Cool...

Now. Who wants to make him sing and dance in colour? Nah. Kidding. Forget the singing! Still kidding. Run and dance... lol

Thanks for the help guys. Much appreciated.

J
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Star Backgound
« Reply #70 on: July 01, 2018, 10:26:08 am »
Hi Johnno,

Just for clarification, the translation of Walking Man demo does Run on your system and QB64 version now?

I was reading over an old _PUTIMAGE() thread at TJP and see that your system or QB64 version was failing to load images. That is fixed now, correct?

I had posted another demo using _PUTIMAGE there working with Cyber's font sheet not having read the original posts, now having read those posts, found your loading image problem. That's why I ask if that problem is fixed, I am curious what fixed it?
« Last Edit: July 01, 2018, 10:28:08 am by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Star Backgound
« Reply #71 on: July 01, 2018, 10:57:29 am »
Hi bplus,

You are correct. Both yours and Petr's translation run on my machine. As to the images not loading, I'll have to go back an search for it, but at this time I cannot recall why the images were having difficulties. I'll check it out and get back to you.

J
Logic is the beginning of wisdom.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Star Backgound
« Reply #72 on: July 01, 2018, 11:08:34 am »
I just read through the postings on TJP and I'm still as confused as I was then. Chances are it was probably due to a stupid typo on my part. The only thing I can think of was that Steve had mentioned something about a suspect version of qb64 that had messed up line endings. Since then I have downloaded the current version of qb64 and the problem has not returned. But I still suspect a typo....

J
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Star Backgound
« Reply #73 on: July 01, 2018, 12:24:52 pm »
You know after I posted my question, I might have found an answer to the confusion.

It is about saving the exe with the source code, that way it has the same access to additional files as the source without having to fully path the filenames for loading files. You know that little thing you had to tick off in the Run Menu of IDE.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Star Backgound
« Reply #74 on: July 01, 2018, 12:33:32 pm »
You know after I posted my question, I might have found an answer to the confusion.

It is about saving the exe with the source code, that way it has the same access to additional files as the source without having to fully path the filenames for loading files. You know that little thing you had to tick off in the Run Menu of IDE.

Maybe I should say, tick on, "Save EXE in the source folder". I remember that little thing ticked me off when I was trying out a new download of QB64, code was working but files weren't loading.