Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3d scrolling
#1
I got inspired by johnnos parallax experiments and wrote this one Smile  I remember using the mode-7 library in n6 to do something similar, but this is much simpler and cleaner.
Code:
' Cool scrolling
' --------------
' By Marcus.

set window "Cool scrolling", 640, 480
set redraw off

' Load a tilable image width clouds.
img = loadimage("clouds.png")

' Scroll value.
offset = 0
do
    ' Scroll.
    offset = (offset - 8)%width(primary)

    ' Clear screen and render sky.
    set color 53, 96, 159
    cls
    RenderSky(img, height(primary)/2, 5, offset)

    set color 255, 255, 255   
    set caret width(primary)/2, height(primary) - 16
    center "Press Esc to quit ..."
   
    redraw
    fwait 60
until keydown(KEY_ESCAPE)

' RenderSky
' ---------
function RenderSky(img, h, depth, offset)
    ' Window width and half width.
    ww = width(primary)
    hww = ww/2

    ' Interpolate 1/z from 1 to 1 + depth over the height.
    dz = (1/(1 + depth) - 1)/h
    zi = 1
    set color 255, 255, 255, 0
    for y = 0 to h - 1
        ' Increase 1/z.
        zi = zi + dz
        ' Calculate perspective correct z, width and offset.
        z = 1/zi
        v = (z - 1)/depth
        w = ww/z
        x = hww - (hww - offset%ww)/z
        ' Fill horizontal line using hraster.
        x = x - ceil(x/w)*w
        while x < ww
            draw hraster img, y, x, x + w - 1, 0, v, 1, v
            x = x + w
        wend
    next
endfunc


Attached Files
.zip   cool_scrolling.zip (Size: 62.15 KB / Downloads: 6)
Reply
#2
Great stuff with that sky above :-).
Reply
#3
Very cool indeed... Hey! Multi tasking. If you do not like clouds, flip it upside down. Sea or snowdrift... lol Wink
May your journey be free of incident.
Live long and prosper.
Reply
#4
Very good example, I liked it. One question, is there a function that allows me to copy another piece of another map in a map?.The map is a image.
Reply
#5
I am not sure what you are trying to say. Can you explain what the map images are used for?
May your journey be free of incident.
Live long and prosper.
Reply
#6
Excuse me...I don't know if it is possible to do this with naalaa.Basically it consists of having a map/image A...then I read it and put it in the background...I call this map C. Then I have a map/image that represents a star B. Then it would be to read map B and place it randomly in map C, to simulate multiple stars... that is, C= C+B(x,y)+B1(x,y).... that is, I have an array r,g,b,a with all the information of the background map + the stars stamped on said map.
Reply
#7
(07-21-2022, 01:07 PM)luigui Wrote: Excuse me...I don't know if it is possible to do this with naalaa.Basically it consists of having a map/image A...then I read it and put it in the background...I call this map C. Then I have a map/image that represents a star B. Then it would be to read map B and place it randomly in map C, to simulate multiple stars... that is, C= C+B(x,y)+B1(x,y).... that is, I have an array r,g,b,a with all the information of the background map + the stars stamped on said map.

I'm not quite sure I follow Smile  You can draw any image on any other image. If you want to draw image B on image A at position x, y (in the coordinate system of image A):

Code:
set image A ' Set destination image to A
draw image B, x, y ' Draw image B on A at x, y
set image primary ' Set destination image to the "window".

If you have RGBA data in an array (if I understand you correctly) it's probably easier to write it to an actual image and then use it for drawing.

Code:
rgba = ... ' A 3d array, I guess? rgba[w][h][4]
img = createimage(w, h)
set image img ' Draw pixeldata to img.
for y = 0 to h - 1
  for x = 0 to w - 1
    set color rgba[x][y]
    set pixel x, y
  next
next
set image primary
Reply
#8
Ok. Let me see if I have this correctly. You want to "scan" a map. Set it as a background. Then you want to randomly populate stars onto the background map. I hope I got that right... lol... The one part that still confuses me is, you did not say where that star came from... Perhaps from the background map or maybe one you have on file? Am I close? Or am I still confused? lol...
May your journey be free of incident.
Live long and prosper.
Reply
#9
That's big time cool stuff.

 It looks like to me, that the Hraster  command is leading to more cool 3d stuff.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)