As you will see, i commented the code. It is tested to animate squared pictures.
A short summary of what it does:
1. it loads the picture you want it to animate
2. it generates a bigger picture and copies the original into the bigger one (otherwise the edges would get cut off)
3. it rotates the picture
4. it saves the rotated picture into an animstrip (which is nothing more then a really big picture)
Hint: be careful with big pictures... blitz seems to have a maximal number of pixels a picture can have that it sees it completely. (at least with LoadAnimImage())
The Code:
; ---------------------------------------------------------------------------------------------
; --------------------------------- WRITTEN BY BLITZADICT -------------------------------------
; ---------------------------------------------------------------------------------------------
; Die Variablen werden gesetzt
Global TitelDesProgrammes$ = "Animator"
SeedRnd MilliSecs()
Const Breite = 1024
Const Hoehe = 768
FarbTiefe = 0
FensterModus = 1
; Konfiguration des Fensters + Programmtitelausgabe
Graphics Breite, Hoehe, FarbTiefe, FensterModus
AppTitle TitelDesProgrammes$
; ----------------------- COPY THE CODE FROM HERE IF U WISH TO IMPLEMENT -----------------------------
; ----------------------- IT INTO YOUR OWN -----------------------------------------------------------
; the variables below must be global, because the program wont run otherwise
Global AnzahlGrade = 360; change here to have the animation more or less steps (more has not been tested)
Global MultiplikationsFaktor = 360/AnzahlGrade ; that the picture gets animated in a full circle
Dim AnimationBild(AnzahlGrade)
AnimFont = LoadFont("Times New Roman", 30, 0, 1, 0)
SetFont AnimFont
Function AnimationenGenerieren(BildName$, ZielBildName$ = "Leer"); The first variable is the name of the picture you want to animate and the secound the name you want the animation to be saved with
GrundBild = LoadImage(BildName$) ; Loads the picture to be animated
MaskImage GrundBild, 255, 255, 255
Bild = CreateImage((ImageWidth(GrundBild)+22), (ImageHeight(GrundBild)+22)) ; Because of the rotation, the picture gets copied into another, bigger one (otherwise the edges might get cut off)
SetBuffer ImageBuffer(Bild)
Color 255, 255, 255 ; draws a rect of white color... this is the color which gets ignored
Rect 0, 0, ImageWidth(Bild), ImageHeight(Bild)
DrawImage GrundBild, 11, 11
SetBuffer BackBuffer()
MidHandle Bild ; The handle of the Picture to be rotated gets set to the center
MaskImage Bild, 255, 255, 255 ; The color white gets ignored
Animation = CreateImage((AnzahlGrade*ImageWidth(Bild)), ImageHeight(Bild))
SetBuffer ImageBuffer(Animation) ; The Animstrip gets created and filled white (i always ignore white)
Color 255, 255, 255
Rect 0, 0, (360*ImageWidth(Bild)), ImageHeight(Bild)
SetBuffer BackBuffer()
For Grade = 0 To AnzahlGrade-1 ; 0 = 360
Cls
AnimationBild(Grade) = CopyImage(Bild)
RotateImage AnimationBild(Grade), Grade*MultiplikationsFaktor
Color 255, 255, 255
Text 20, 20, "Rotating Image '" + BildName$ + "' " + Grade + " Steps done."
Flip
Next
For Grade = 0 To AnzahlGrade-1 ; 0 = 360
SetBuffer ImageBuffer(Animation)
DrawImage AnimationBild(Grade), ((Grade * ImageWidth(Bild))+1*ImageWidth(Bild)/2), 0+(1*ImageHeight(Bild)/2)
SetBuffer BackBuffer()
Cls
Color 255, 255, 255
Text 20, 20, "Painting: " + Grade + " Steps done."
Flip
Next
Cls
Text 20, 20, "Saving"
Flip
If ZielBildName$ = "Leer" Then ; If you dont give the AnimStrip a specific name, the name of the animated picture plus " Animated.bmp" gets used
LaengeDesNamens = Len (BildName$)
ZwischenName$ = Left$(BildName$, (LaengeDesNamens-4))
NeuerZielBildName$ = ZwischenName$ + " Animated_" + AnzahlGrade + ".bmp"
SaveImage Animation, NeuerZielBildName$
Else ; If you give the AnimStrip a specific name, it gets used
SaveImage Animation, ZielBildName$
End If
End Function
Repeat
Color 0, 0, 0
Cls
Color 255, 255, 255
Text 30, 30, "Please Press 'a' to start the Animation"
Text 30, 60, "Please Press 'q' to end this program"
Flip
If KeyHit(30) Then
AnimationenGenerieren("Picture") ; enter here the name of the picture you want to animate
End If
If KeyHit(16) Then
End
End If
Until KeyHit(1)It surely is not perfect, but it runs perfect. And since this creates animstrips you then use in your programs, speed is not of the essence here ;)
Feel free to use the code to your liking.
/edit: corrected a bad grammatical error :)