StarWars crawl -Test-
Posted: Sun Mar 27, 2016 1:55 pm
Here is a snippet of what I wanted to make since... and now sB 5.5 -> perspective shaping
made it possible
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
made it possible
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