Author Topic: Zoom effect sources + explanations  (Read 3381 times)

0 Members and 1 Guest are viewing this topic.

Offline .:] Druid [:.

  • freebasic n00b
  • Pentium
  • *****
  • Posts: 563
  • Karma: 47
    • View Profile
    • Intro-Inferno
Zoom effect sources + explanations
« on: December 09, 2006 »
The zoom effect used on Vision Factory's cracktro
-------------------------------------------------

Here is a small explanation about the zoom effect
I used in the Vision Factory win32 port.

First of all, I won't post the full code of it
since all the rest can be found directly here
on DBF-GVY Forum (music, loading an image, scroller)

So, we gonna start with the basic: drawing a line...

A line is made of points, pixels..so, to put a point
on screen, I'll use:

   FeedPixels ( X , Y , rgb(255,255,255) )

(yes you need the sub but it's included, and thanks to
it's author...just I don't remember who write it.
Let me know and i'll correct it of course!)

So, you wrote a white point on screen, at position X-Y.

Now, you can use a loop to draw a line like this:

   FOR X=1 TO 100
      FeedPixels ( X , Y , rgb(255,255,255) )
   NEXT

Here, we have a line from 1 to 100 at Y. (exemple 1.bas)

I hope you follow till here since we gonna make...a square

Using the same idea:

   FOR Y=1 TO 100
      FOR X=1 TO 100
         FeedPixels ( X , Y , rgb(255,255,255) )
      NEXT
   NEXT

We have now a square of 100*100 with upper left corner @ 1,1 (X,Y)

with that in mind, you see it's not complicated to increase/decrease
its size) by using other variables: Minimum size, Maximum size.
With only those 2 variables it won't work: you need to know if
you need to increase or to decrease its size...

  Â  if SQ_Size=SQ_Max_Size then Temp_Orientation=1 'Is the square at the max size?
  Â  if SQ_Size=SQ_Min_Size then Temp_Orientation=0 'Is the square at the min size?
  Â  if Temp_Orientation=0 then SQ_Size=SQ_Size+2
  Â  if Temp_Orientation=1 then SQ_Size=SQ_Size-2

  Â  
  Â  For Y=1 to SQ_Size
  Â  
  Â  Â  Â  For X=1 To SQ_Size
  Â  Â  Â  Â  Â  FeedPixels(X , Y,rgb(102,102,102))
  Â  Â  Â  Next
  Â  
  Â  Next

(exemple 2.bas)

SO far, so good: we have one cube and its size changes as expected..so, let's add a second
square just next to him...but the coordinates changes!

No big deal in fact: we have the size of our square in realtime (woaow ;p):


  Â  if SQ_Size=SQ_Max_Size then Temp_Orientation=1 'Is the square at the max size?
  Â  if SQ_Size=SQ_Min_Size then Temp_Orientation=0 'Is the square at the min size?
  Â  Â  Â  
  Â  if Temp_Orientation=0 then SQ_Size=SQ_Size+2
  Â  if Temp_Orientation=1 then SQ_Size=SQ_Size-2
  Â  
  Â  FOR I=0 to 2
  Â  Â  Â  
  Â  Â  Â  For Y=1 to SQ_Size
  Â  Â  Â  
  Â  Â  Â  Â  Â  For X=(I*SQ_Size) + 1 to (I*SQ_Size)+ SQ_Size
  Â  Â  Â  Â  Â  Â  Â  FeedPixels(X , Y,rgb(102,102,102))
  Â  Â  Â  Â  Â  Next
  Â  Â  Â  
  Â  Â  Â  Next
  Â  Â  Â  
  Â  Next

So, we only draw 2 now, but have a closer look:

   For X=(I*SQ_Size) + 1 to (I*SQ_Size)+ SQ_Size

   => SQ_Size is the actual size of the screen..so to display the square at
  Â  Â  Â  Â  Â the right place, we added a variable ("I" .. not very original) and we
   Â  Â calculate it's position: if its the second square, it's 2 (i=2) * the actual square size

Easy no?  (Exemple 4.bas)

hey, but wait a minute...it's not a chessboard, there is only one color so far!
True...so, let's not put some space between the two grey one.

First, we'll just change our source:

For X=(2*I*SQ_Size) + 1 to (2*I*SQ_Size)+ SQ_Size

Now, we have 2 squares zooming and one empty space in between.....time to add the second color, no?
By adding FeedPixels(X , Y + SQ_Size,rgb(255,255,255))Â  next to the first one FeedPixels and it'll make it!
(Exemple 5.bas)

We're almost done, it's getting close...but well, now, we have to fill the empty space..and don't forget to mix
colors....it's grey-white-grey..and not grey-grey-grey .... or no chessbord :)

Well, just add those 2 lines and it's filled:

      FeedPixels(X + SQ_Size , Y,rgb(255,255,255))Â  Â  Â  Â  Â  Â  Â  Â  
  Â  Â  Â  Â  Â  Â  Â  FeedPixels(X + SQ_Size , Y + SQ_Size,rgb(102,102,102))

Now we have 8 squares zooming..but not the full screen yet!  (exemple 6.bas)

So, now we calculate the amount of squares, depending on it actual size:

  Â  SQ_Amount_H=Screen_H/SQ_Size 'how many squares to draw (height)
  Â  SQ_Amount_W=Screen_W/SQ_Size 'how many squares to draw (width)

So, we can replace the " FOR I=0 to 2" by "FOR I=0 to SQ_Amount_H" ....

do
  Â  if SQ_Size=SQ_Max_Size then Temp_Orientation=1 'Is the square at the max size?
  Â  if SQ_Size=SQ_Min_Size then Temp_Orientation=0 'Is the square at the min size?
  Â  Â  Â  
  Â  if Temp_Orientation=0 then SQ_Size=SQ_Size+1
  Â  if Temp_Orientation=1 then SQ_Size=SQ_Size-1
  Â  
  Â  SQ_Amount_H=Screen_H/SQ_Size 'how many squares to draw (height)
  Â  SQ_Amount_W=Screen_W/SQ_Size 'how many squares to draw (width)
  Â  
  Â  
  Â  For J=0 to SQ_Amount_W
  Â  Â  Â  For I=0 to SQ_Amount_H
  Â  Â  Â  Â  Â  For Y=(2*I*SQ_Size) + 1 to (2*I*SQ_Size)+ SQ_Size
  Â  Â  Â  Â  Â  Â  Â  For X=(2*J*SQ_Size) To (2*J*SQ_Size)+ SQ_Size
  Â  Â  Â  Â  Â  Â  Â  Â  Â  FeedPixels(X , Y,rgb(102,102,102))
  Â  Â  Â  Â  Â  Â  Â  Â  Â  FeedPixels(X , Y + SQ_Size,rgb(255,255,255))
  Â  Â  Â  Â  Â  Â  Â  Â  Â  FeedPixels(X + SQ_Size , Y,rgb(255,255,255))  Â  Â  Â  Â  Â  Â  Â  
  Â  Â  Â  Â  Â  Â  Â  Â  Â  FeedPixels(X + SQ_Size , Y + SQ_Size,rgb(102,102,102))
  Â  Â  Â  Â  Â  Â  Â  Next
  Â  Â  Â  Â  Â  Next
  Â  Â  Â  Next
  Â  Next
  Â  
  Â  
  Â  ptc_update(@screenbuffer(0))
  Â  ERASE screenbuffer
  Â  
loop until inkey$ = CHR$(27)



And yes..it's done :)Â  (exemple final.bas)


There are probably tons of other methods...I found that one and it worked.
If you have any comment, suggestion, improvement, ... it's always welcome!

Cheers,
Druid
[sheep]: im sure he wants to goto prison.. they didnt get him last time.. he was promised a big cock up his arse.. and no doubt looking forward to it.. lets hope he gets his wish this year.

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Zoom effect sources + explanations
« Reply #1 on: December 09, 2006 »
Nicely done tutorial druid-tro. Very clear in easy steps.
I think the more tutorials the better, so karma++.
Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: Zoom effect sources + explanations
« Reply #2 on: December 10, 2006 »
Indeed. Thanks for the info.

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Zoom effect sources + explanations
« Reply #3 on: December 11, 2006 »
Cool beans dude - very very good explanation! karma+

Drew
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk