Page 1 sur 1

Coverflow Apple-Like

Publié : sam. 08/août/2009 10:46
par KrisJNT
Et voici un coverflow : (c'est juste un bout de code comme ça. Vous pouvez l'améliorer comme vous le souhaitez :D )

Code : Tout sélectionner

Structure folderI
	sprite.l
	name$
EndStructure

Global Dim fnf.folderI(255)
Global max = 0

InitSprite():InitSprite3D():InitMouse()

UseJPEGImageDecoder():UsePNGImageDecoder()

Sprite3DQuality(#PB_Sprite3D_BilinearFiltering)

MessageRequester("Avant tout...", "Pour profiter du programme, veuillez choisir un dossier contenant des fichiers MP3 et des sous-dossiers contenant eux-même chacun un fichier AlbumArt*.jpg")

path$ = PathRequester("Choisissez un dossier...", "")

OpenScreen(1024, 768, 32, "Test 3D Sprites")

ExamineDirectory(0, path$, "*.*")
NextDirectoryEntry(0):NextDirectoryEntry(0)

i = 0

While NextDirectoryEntry(0)
	If DirectoryEntryType(0) = #PB_DirectoryEntry_Directory
		fnf(i)\name$ = DirectoryEntryName(0)
		ExamineDirectory(1, path$ + fnf(i)\name$, "AlbumArt*.jpg")
		If NextDirectoryEntry(1)
			idi = LoadImage(#PB_Any, path$ + fnf(i)\name$ + "\" + DirectoryEntryName(1))
			w = ImageWidth(idi)
			h = ImageHeight(idi)
			If w > h
				ResizeImage(idi, 128, Int(128*h/w))
			Else	
				ResizeImage(idi, Int(128*w/h), 128)
			EndIf
			id = CreateSprite(#PB_Any, 128, 128, #PB_Sprite_Texture)
			StartDrawing(SpriteOutput(id))
				Box(0, 0, 128, 128, $FF00FF)
				DrawImage(ImageID(idi), Int((128-ImageWidth(idi))/2), Int((128-ImageHeight(idi))/2))
			StopDrawing()
			TransparentSpriteColor(id, $FF00FF)
			fnf(i)\sprite = CreateSprite3D(#PB_Any, id)
		Else
			id = LoadSprite(#PB_Any, "folder.png", #PB_Sprite_Texture)
			TransparentSpriteColor(id, $FF00FF)
			fnf(i)\sprite = CreateSprite3D(#PB_Any, id)
		EndIf
		i + 1
	Else
		If GetExtensionPart(DirectoryEntryName(0)) = "mp3"
			fnf(i)\name$ = DirectoryEntryName(0)
			id = LoadSprite(#PB_Any, "musicfile.png", #PB_Sprite_Texture)
			TransparentSpriteColor(id, $FF00FF)
			fnf(i)\sprite = CreateSprite3D(#PB_Any, id)
			i + 1
		EndIf
	EndIf
Wend

max = i - 1

fid = LoadFont(0, "Franklin Gothic Medium", 11, #PB_Font_HighQuality)

current = 0

Repeat
	FlipBuffers()
	ClearScreen(0)
	
	StartDrawing(ScreenOutput())
		DrawingFont(fid)
		DrawingMode(#PB_2DDrawing_Default)
		x = (1024 - TextWidth(fnf(current)\name$) - TextHeight(fnf(current)\name$)) / 2
		xc = x + TextHeight(fnf(current)\name$) / 2
		Circle(xc, 160 + TextHeight(fnf(current)\name$) / 2, TextHeight(fnf(current)\name$) / 2, $808080)
		Circle(TextWidth(fnf(current)\name$) + xc, 160 + TextHeight(fnf(current)\name$) / 2, TextHeight(fnf(current)\name$) / 2, $808080)
		Box(xc, 160, TextWidth(fnf(current)\name$), TextHeight(fnf(current)\name$), $808080)
		DrawingMode(#PB_2DDrawing_Transparent)
		DrawText(xc+1, 160+1, fnf(current)\name$, 0)
		DrawText(xc, 160, fnf(current)\name$, $FFFFFF)
	StopDrawing()
	
	Start3D()

	For i = 0 To current - 1
			TransformSprite3D(fnf(i)\sprite, 0, 0, 96, 16, 96, 112, 0, 128)
			DisplaySprite3D(fnf(i)\sprite, 448-40 - (40 * (current - 1 - i)), 20)
	Next
	
	For i = max To current + 1 Step -1
		TransformSprite3D(fnf(i)\sprite, 0, 16, 96, 0, 96, 128, 0, 112)
		DisplaySprite3D(fnf(i)\sprite, 448-10 + 40 * (i - current + 1), 20)
	Next
	
 	TransformSprite3D(fnf(current)\sprite, 0, 0, 128, 0, 128, 128, 0, 128)
 	DisplaySprite3D(fnf(current)\sprite, 448, 20)
	
	Stop3D()
	ExamineMouse()
	
	If GetAsyncKeyState_(#VK_LEFT) Or MouseDeltaX() > 0
		If Not temoinL
			prev = current
			current - 1
			If current = -1		
				current = 0
			Else
				For h = 0 To 16 Step 2
					FlipBuffers()
					ClearScreen(0)
					Start3D()
						For i = 0 To prev - 1
							TransformSprite3D(fnf(i)\sprite, 0, 0, 96, 16, 96, 112, 0, 128)
							DisplaySprite3D(fnf(i)\sprite, 448-40 - (40 * (prev - 1 - i)), 20)
						Next
						For i = max To prev + 1 Step -1
							TransformSprite3D(fnf(i)\sprite, 0, 16, 96, 0, 96, 128, 0, 112)
							DisplaySprite3D(fnf(i)\sprite, 448-10 + 40 * (i - prev + 1), 20)
						Next
		 				TransformSprite3D(fnf(prev)\sprite, 0, h, 128-2*h, 0, 128-2*h, 128, 0, 128-h)
						DisplaySprite3D(fnf(prev)\sprite, 448+2*h, 20)
					Stop3D()
					
				Next
				For h = 0 To 16 Step 2
					FlipBuffers()
					ClearScreen(0)
					Start3D()
						For i = 0 To current - 1
							TransformSprite3D(fnf(i)\sprite, 0, 0, 96, 16, 96, 112, 0, 128)
							DisplaySprite3D(fnf(i)\sprite, 448-40 - (40 * (current - 1 - i)), 20)
						Next
						For i = max To current + 1 Step -1
							TransformSprite3D(fnf(i)\sprite, 0, 16, 96, 0, 96, 128, 0, 112)
							DisplaySprite3D(fnf(i)\sprite, 448-10 + 40 * (i - current + 1), 20)
						Next
						TransformSprite3D(fnf(current)\sprite, 0, 0, 96+h, 16-h, 96+2*h, 112+h, 0, 128)
						DisplaySprite3D(fnf(current)\sprite, 448-2*(16-h), 20)
					Stop3D()
				Next
			EndIf
			temoinL = 1
			ctrL = ElapsedMilliseconds()
		EndIf
		
	Else
		temoinL = 0
	EndIf
	
	If GetAsyncKeyState_(#VK_RIGHT) Or MouseDeltaX() < 0
		If Not temoinR
			prev = current
			current + 1
			If current = max + 1
				current = max
			Else
				For h = 0 To 16 Step 2
					FlipBuffers()
					ClearScreen(0)
					Start3D()
						For i = 0 To prev - 1
							TransformSprite3D(fnf(i)\sprite, 0, 0, 96, 16, 96, 112, 0, 128)
							DisplaySprite3D(fnf(i)\sprite, 448-40 - (40 * (prev - 1 - i)), 20)
						Next
						For i = max To prev + 1 Step -1
							TransformSprite3D(fnf(i)\sprite, 0, 16, 96, 0, 96, 128, 0, 112)
							DisplaySprite3D(fnf(i)\sprite, 448-10 + 40 * (i - prev + 1), 20)
						Next
		 				TransformSprite3D(fnf(prev)\sprite, 0, 0, 128-2*h, h, 128-2*h, 128-h, 0, 128)
						DisplaySprite3D(fnf(prev)\sprite, 448-2*h, 20)
					Stop3D()
					
				Next
				For h = 0 To 16 Step 2
					FlipBuffers()
					ClearScreen(0)
					Start3D()
						For i = 0 To current - 1
							TransformSprite3D(fnf(i)\sprite, 0, 0, 96, 16, 96, 112, 0, 128)
							DisplaySprite3D(fnf(i)\sprite, 448-40 - (40 * (current - 1 - i)), 20)
						Next
						For i = max To current + 1 Step -1
							TransformSprite3D(fnf(i)\sprite, 0, 16, 96, 0, 96, 128, 0, 112)
							DisplaySprite3D(fnf(i)\sprite, 448-10 + 40 * (i - current + 1), 20)
						Next
						TransformSprite3D(fnf(current)\sprite, 0, 16-h, 96+2*h, 0, 96+2*h, 128, 0, 112+h)
						DisplaySprite3D(fnf(current)\sprite, 448+2*(16-h), 20)
					Stop3D()
				Next
			EndIf
			temoinR = 1
			ctrR = ElapsedMilliseconds()
		EndIf
	Else
		temoinR = 0
	EndIf
	
	If ElapsedMilliseconds() - ctrL >= 100
		temoinL = 0
	EndIf
	If ElapsedMilliseconds() - ctrR >= 100
		temoinR = 0
	EndIf
	
Until GetAsyncKeyState_(#VK_ESCAPE)
Et les images :
Image
Image

Vous m'en direz des nouvelles ^^ !