StarWars crawl -Test-

Post Reply
Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

StarWars crawl -Test-

Post by Operator »

Here is a snippet of what I wanted to make since... and now sB 5.5 -> perspective shaping
made it possible :D

It runs in landscape orientation on iPhone 4
and iPad Mini 1.gen... and will create a folder
to store the image slices...

Feel free to re-use and please HELP to speed
this up..., enjoy...

Crawl-Text-Link:
https://www.dropbox.com/s/1c2hrztsrsh1w ... l.png?dl=0

StarwarsMidi-Link:
https://www.dropbox.com/s/3i8ild05w4unh ... s.mid?dl=0

Code: Select all

REM Star Wars IV Crawl -Test-
REM sB 5.5 / iPhone 4 / iOS 6.1 / by Operator
REM 
REM One single "big" image of the intro text
REM can't be used, since prog. will abort if
REM DRAW IN cmd. runs out of mem or position
REM is "far" from screen limits...
REM so we slice the whole text (img) and move 
REM all the perspective shaped slices/stripes
REM Drawing in Sprite is also used to avoid
REM Draw Img. in "abort"...
REM 
REM runs on iPhone4, iPad Mini 1Gen landscape
REM star wars midi out of:
REM http://www.galaxyfaraway.com/gfa/1998/12/star-wars-midis/ 
REM 

'load crawl img or another image :)
img$ = "crawl.png"
'img$ = "Examples/Graphics/images/turtle.png"
'img$ = "Examples/Graphics/images/firtree.png"
GET IMAGE img$ SIZE img.w,img.h

device$ = DEVICE_TYPE$()

'don't reduce #of slices below 18,26
'otherwise DRAW Img. IN may abort..
'if you increase the value -> slower :/
img.slices = 18
IF device$ = "iPad" THEN img.slices = 26

NOTES LOAD "Starwars.mid"

GRAPHICS
GRAPHICS CLEAR
OPTION SPRITE POS CENTRAL
SET ORIENTATION LANDSCAPE

GET SCREEN SIZE scr.w,scr.h
scr_w2 = scr.w/2
scr_h2 = scr.h/2

'use of sprite to increase the draw range of DRAW IMAGE IN cmd.
'if not used Draw Img. In will abort
SPRITE "expand draw in" BEGIN scr.w*1.2,scr.h*1.2
SPRITE END
SPRITE "expand draw in" SHOW

'GOTO skip 'comment out if slices are saved
           'and you want to play with values

'calc. scale values for x and y
scl.x = scr.w/img.w
scl.y = scr.h/img.h

'set image scale to fit screen height
img.scl = scl.y
img.x = 0
img.y = 0

DRAW COLOR 1,1,1
DRAW SIZE 1
DRAW IMAGE img$ AT img.x,img.y SCALE img.scl
PAUSE 1
'rectangle coordinates (sprite scan area)
r.x1 = 0
r.y1 = 0
r.x2 = img.w*img.scl
r.y2 = img.h*img.scl/(img.slices-1)
r.DY = r.y2 - r.y1
FOR i = 0 TO img.slices-2
  'DRAW RECT r.x1,(r.y1+i*r.DY) TO r.x2,(r.y2+i*r.DY)
  SPRITE i SCAN r.x1,(r.y1+i*r.DY), r.x2,r.DY
  PAUSE 0.2
NEXT i
GRAPHICS CLEAR 0,0,0

'show first scaned sprites, re-scan and save
'will create ImgSlices directory
DIR "ImgSlices" CREATE
FOR i = 0 TO img.slices -2
  SPRITE i AT scr_w2,(scr.w/r.x2)*(r.DY/2) SCALE scr.w/r.x2
  SPRITE i STAMP
  SPRITE i SCAN r.x1,r.y1,scr.w,(scr.w/r.x2*r.DY)
  SPRITE i SAVE "ImgSlices/"&i&".png"
  PAUSE 0.2
  SPRITE i HIDE
  GRAPHICS CLEAR 0,0,0
NEXT i

skip:

'-----------------------------------------
'Perspective processing of the img. slices 

'position of camera and camera distance d 
'from the screen, change (reduction) may lead 
'DRAW Img IN to abort
cam_y = 160    'orig-val 160
cam_z = -100   'orig-val -100
cam_x = 0      'orig-VAL 0
cam_d = 1.2    'orig-val 1.2

GET IMAGE "ImgSlices/0.png" SIZE sl.w,sl.h
strip.w = sl.w/3
strip.h = sl.h/3
IF device$ = "iPad" THEN 
  strip.w = sl.w/6
  strip.h = sl.h/6
END IF
strip.w2 = strip.w/2
strip.x = 0
strip.y = 0
strip_vanish_h = 10
strips.maxx = img.slices-1
DIM strip.z(strips.maxx,2)
strip.base_ = 0 
strip.speed = 2

'preload strip.z array, each strip i has two
'z-values
FOR i = 0 TO strips.maxx-1
  strip.z(i,0) = strip.base_
  strip.z(i,1) = strip.base_ - strip.h
  strip.base_ = strip.z(i,1)
  'DRAW TEXT i&" "&strip.z(i,0)&" "&strip.z(i,1) AT 0,+i*20
NEXT i

'set strip coordinates, z will be overwritten
x1 = -strip.x + strip.w2 ! y1 = strip.y ! z1 = 0
x2 = -strip.x - strip.w2 ! y2 = strip.y ! z2 = 0
x3 = -strip.x - strip.w2 ! y3 = strip.y ! z3 = -strip.h
x4 = -strip.x + strip.w2 ! y4 = strip.y ! z4 = -strip.h

NOTES PLAY
REFRESH OFF
T0 = TIME()


LOOP:
T1 = TIME()
SPRITE "expand draw in" BEGIN
GRAPHICS CLEAR 0,0,0

FOR i = 0 TO strips.maxx-1
  Trans(x1,y1,strip.z(i,0))
  x1T = Trans.x_scr 
  y1T = Trans.y_scr
  
  Trans(x2,y2,strip.z(i,0))
  x2T = Trans.x_scr
  y2T = Trans.y_scr
  
  Trans(x3,y3,strip.z(i,1))
  x3T = Trans.x_scr
  y3T = Trans.y_scr
  
  Trans(x4,y4,strip.z(i,1))
  x4T = Trans.x_scr
  y4T = Trans.y_scr
  
  IF strip.z(i,0) >= 0 THEN
    'DRAW QUAD x1T,y1T, x2T,y2T, x3T,y3T, x4T,y4T
    DRAW IMAGE "ImgSlices/"&i&".png" IN x1T,y1T, x2T,y2T, x4T,y4T, x3T,y3T
  END IF 
NEXT i

counter += 1
fps = counter/(TIME()-T0)
DRAW TEXT "FPS: "&STR$(fps) AT 0,0
'REFRESH
SPRITE END

dT = TIME()-T1
FOR i = 0 TO strips.maxx-1
  strip.z(i,0) += strip.speed*dT
  strip.z(i,1) += strip.speed*dT
NEXT i

GOTO LOOP



DEF Trans(x,y,z)
 'translate
  x_cam = x - .cam_x
  y_cam = y - .cam_y
  z_cam = z - .cam_z
  IF z_cam = 0 THEN
    z_cam = 0.00001
    DRAW TEXT "Div by 0 avoided" AT 0,30
    'DEBUG PAUSE
  END IF
 'project
  x_proj = x_cam * .cam_d/-z_cam
  y_proj = y_cam * .cam_d/-z_cam
 'scale
  x_scr = .scr_w2 + .scr_w2 * x_proj
  y_scr = .strip_vanish_h + .scr_h2 * y_proj
END DEF
Attachments
image.jpg
image.jpg (100.01 KiB) Viewed 2582 times

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: StarWars crawl -Test-

Post by rbytes »

Here is my mod. It seems to do a nice scroll, and doesn't take a lot of code. I had to experiment with image scale to avoid crashing the draw in command, but it works. I have tried to adjust the parameters to work on all devices, but don't have time to test it right now. It does run perfectly on my iPad.

The nice thing is that there is virtually no speed limit. Try reducing the pause in the cycle loop and you can really make those letters fly!

Code: Select all

REM Star Wars IV Crawl -Test-
REM sB 5.5 / iPhone 4 / iOS 6.1 / by Operator
REM 
REM Mods by ricardo
REM 
REM runs on iPhone4, iPad Mini 1Gen landscape
REM star wars midi out of:
REM http://www.galaxyfaraway.com/gfa/1998/12/star-wars-midis/ 
REM 

'load crawl img or another image :)
img$ = "crawl.png"
'img$ = "Examples/Graphics/images/turtle.png"
'img$ = "Examples/Graphics/images/firtree.png"
GET IMAGE img$ SIZE img.w,img.h
device$ = DEVICE_TYPE$()
NOTES LOAD "Starwars.mid"
NOTES PLAY
GRAPHICS
GRAPHICS CLEAR 0,0,0
REFRESH OFF
OPTION SPRITE POS CENTRAL
SET ORIENTATION LANDSCAPE
'SET TOOLBAR off

GET SCREEN SIZE scr.w,scr.h
scr_w2 = scr.w/2
scr_h2 = scr.h/2
ratiow=scr.w/1024
ratioh=scr.h/768
X$="flytext"
'use of sprite to increase the draw range of DRAW IMAGE IN cmd.
'if not used Draw Img. In will abort
SPRITE X$ BEGIN scr.w*1.2,scr.h*1.2
    DRAW IMAGE img$ IN scr.w*.3,0,scr.w*.7,0,-50,scr.h,scr.w+50,scr.h
SPRITE END
'SPRITE X$ AT scr.w*.6,00*ratioh SCALE 2,1
'SPRITE X$ SHOW

FOR spawn=1 TO 200
  'DRAW PIXEL RND(scr.w),RND(scr.h) COLOR 1,1,1,1
  FILL CIRCLE RND(scr.w),RND(scr.h) SIZE RND(3)
NEXT spawn
REFRESH
SPRITE X$ SHOW
FOR cycle=1 TO 10000
  SPRITE X$ AT scr.w*.7-cycle/(10*ratiow),1200*ratioh-cycle/2 SCALE 2.2-(cycle/(950*ratiow)),1-(cycle/(2250*ratioh))
  PAUSE .02
  'PAUSE .002
  IF 2.2-(cycle/(950*ratiow))=<0 THEN   ' letters pass out of sight
    PAUSE 5
    END
  ENDIF
NEXT cycle
END



[/code]
Attachments
image.png
image.png (309.75 KiB) Viewed 2563 times
image.png
image.png (307.58 KiB) Viewed 2563 times
The only thing that gets me down is gravity...

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: StarWars crawl -Test-

Post by Operator »

:shock: Nice hack ...
iPhone 4 will abort if "sprite aid" is not
expanded to:
SPRITE X$ BEGIN scr.w*1.3,scr.h*1.3

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: StarWars crawl -Test-

Post by rbytes »

Thanks. I haven't tried it on my phone yet, so will maybe need to add that. Also I notice that using a single sprite produces some distortion. The lines of text get more squashed vertically the farther you read. This might be improved if the three paragraphs of text are separated into three sprites that follow each other into the beyond.
The only thing that gets me down is gravity...

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: StarWars crawl -Test-

Post by Operator »

I will also experiment with Sprites...
One thing: since you Draw In in a Sprite,
the lower left corner is cut off, the left
limit of the sprite is 0, so all (-) image
points are not stored...

Post Reply