Cool-looking Blitz3D example code

Blitz3D Forums/Blitz3D Programming/Cool-looking Blitz3D example code

puki(Posted 2005) [#1]
I've had B3D since 2001 - never noticed this code snippet in there before:

I find it interesting. Sort of memorising.

Has anyone got any similar little demos to this (sort of hypnotic) - how about posting them?


Graphics3D 640,480

SetBuffer BackBuffer()

SeedRnd MilliSecs()


; create camera
camera=CreateCamera()
CameraClsColor camera,160,160,160
PositionEntity camera,0,0,-30
middle=CreatePivot()
EntityParent camera,middle

; create add texture - white cirlce on a black background
For n=0 To 50
Color 5+(n*5),5+(n*5),5+(n*5)
Oval 10+n,10+n,236-(n*2),236-(n*2),1
Next

blob_tex=CreateTexture(256,256)
blob=CreateImage(256,256)
GrabImage blob,0,0
CopyRect 0,0,256,256,0,0,ImageBuffer(blob),TextureBuffer(blob_tex)
FreeImage blob

max_blobs=100

; create blobs using add blend mode
Dim blobs(max_blobs) ; blob sprites
Dim xyblobs#(max_blobs,2) ; blob vector

For n=0 To max_blobs
	blobs(n)=CreateSprite()
	EntityFX blobs(n),1
	EntityBlend blobs(n),3 ;set blend mode to add
	EntityTexture blobs(n),blob_tex
	xyblobs(n,0)=Rnd(-.1,.1)
	xyblobs(n,1)=Rnd(-.1,.1)
	xyblobs(n,2)=Rnd(-.1,.1)
	EntityColor blobs(n),Rand(0,255),Rand(0,255),Rand(0,255) ;give it a colour
	Next

; create cube texture
Color 255,255,255
Rect 0,0,256,256,1
For n=0 To 7
	If n=0 Then Color 0,0,0
	If n=1 Then Color 0,0,255
	If n=2 Then Color 0,255,0
	If n=3 Then Color 0,255,255
	If n=4 Then Color 255,0,0
	If n=5 Then Color 255,0,255
	If n=6 Then Color 255,255,0
	If n=7 Then Color 255,255,255
	Rect n*32,n*32,32,32,1
	Next
Color 0,0,0
For n=0 To 255 Step 32
Line 0,n,255,n
Line n,0,n,255
Next

cube_tex=CreateTexture(256,256)
cube=CreateImage(256,256)
GrabImage cube,0,0
CopyRect 0,0,256,256,0,0,ImageBuffer(cube),TextureBuffer(cube_tex)
FreeImage cube

; create cube
cube=CreateCube()
ScaleEntity cube,11,11,11
EntityTexture cube,cube_tex
EntityFX cube,17 ;set fullbright and 2 sided textures
EntityBlend cube,2 ;set multiply blend

Repeat

; move the blobs around
For n=0 To max_blobs
	MoveEntity blobs(n),xyblobs(n,0),xyblobs(n,1),xyblobs(n,2)
	;bounce off sides
	If EntityX(blobs(n))<-10 Or EntityX(blobs(n))>10 Then xyblobs(n,0)=-xyblobs(n,0)
	If EntityY(blobs(n))<-10 Or EntityY(blobs(n))>10 Then xyblobs(n,1)=-xyblobs(n,1)
	If EntityZ(blobs(n))<-10 Or EntityZ(blobs(n))>10 Then xyblobs(n,2)=-xyblobs(n,2)
	Next

; turn camera
TurnEntity middle,.1,.2,.3


UpdateWorld
RenderWorld
Flip


Until KeyHit(1)




IPete2(Posted 2005) [#2]
...to be resussitated you must first burst!

lol


edit ...in reply so as not to clutter up this thread...sorry.


puki(Posted 2005) [#3]
I shall speak with your mother.


QuickSilva(Posted 2005) [#4]
Puki, where is this file located as I have never seen it either. I do agree though, mesmorising...

Jason.


puki(Posted 2005) [#5]
It is the example code for the 'EntityBlend' command.


puki(Posted 2005) [#6]
p.s. don't modify it directly as you can permantly effect your example code - so just copy and paste it as new code if you are going to edit it.


Ice9(Posted 2005) [#7]
Here's one I did a few years ago that's fun to look at for a few hours

;Coded by Staton Richardson
;Arbitrage 
;10/28/2002
;Sphere painter

Graphics3D 1024,768,32
SetBuffer BackBuffer()

Type VertEffect
Field Vertex
Field theta#
Field VNX#
Field VNY#
Field VNZ#
Field speed#
End Type

sphere=CreateSphere(40)
TurnEntity sphere,Rnd(360),Rnd(360),Rnd(360)
;EntityFX sphere,16
EntityAlpha sphere,0.40
camera=CreateCamera()
CameraClsMode camera,False,True

CameraRange camera,1,100000
PositionEntity camera,0,0,-2
light1=CreateLight(2) 
PositionEntity light1,2000,2000,-2000
LightColor light1,255,0,0

light2=CreateLight(2) 
PositionEntity light2,-2000,2000,-2000
LightColor light2,0,255,0

light3=CreateLight(2) 
PositionEntity light3,2000,-2000,2000
LightColor light3,0,0,255

AmbientLight 20,20,20
surf=GetSurface(sphere,1)
Vcount=CountVertices(surf)

	For x=1 To Vcount-1 	
		Vert.VertEffect = New VertEffect
		vert\theta#=Rnd(360)
		Vert\Vertex=x
		Vert\VNX#=VertexNX#(surf,Vert\Vertex)
		Vert\VNY#=VertexNY#(surf,Vert\Vertex)
		Vert\VNZ#=VertexNZ#(surf,Vert\Vertex)
		Vert\Speed#=Rnd(5)+5
	Next
	
	

While KeyDown(1)=0
	cXtheta#=(cXtheta#+0.1)Mod 360
	cYtheta#=(cYtheta#+0.13)Mod 360
	lXtheta#=(lXtheta#+0.3)Mod 360
	lYtheta#=(lYtheta#+0.7)Mod 360
	;heighttheta#=(heighttheta#+0.01) Mod 360
	ScaleEntity camera,1.1+Sin(cXtheta#)*0.5,1.1+Cos(cYtheta#)*0.5,0.95+Sin(cYtheta#)*0.9
	PointEntity camera,sphere
	PositionEntity camera,Cos(cXtheta#)*1.55,Sin(cYtheta#)*1.45,Sin(cYtheta#)*1.65
	TurnEntity camera,0,0,0.004
	PositionEntity light1,Cos(lXtheta#)*800+800,Sin(lYtheta#)*800+800,Cos(lYtheta#)*-800-800
	PositionEntity light2,Sin(lXtheta#)*-800-800,Cos(lYtheta#)*800+800,Sin(lYtheta#)*-800-800
	PositionEntity light3,Cos(lXtheta#)*800+800,Sin(lYtheta#)*-800-800,Sin(lYtheta#)*800+800
	For Vert.VertEffect= Each VertEffect
		Vert\theta#=(Vert\theta#+Vert\Speed#)Mod 360
		stheta#=Sin(Vert\theta#)*0.0035		
		VertexCoords surf,Vert\Vertex,(VertexX#(surf,Vert\Vertex)+(Vert\VNX#*stheta#)),(VertexY#(surf,Vert\Vertex)+(Vert\VNY#*stheta#)),(VertexZ#(surf,Vert\Vertex)+(Vert\VNZ#*stheta#))
	Next
	TurnEntity sphere,0.01,0.2,0.05
	UpdateNormals sphere
	UpdateWorld	
	Flip	
	RenderWorld	
	Flip
	RenderWorld
Wend




puki(Posted 2005) [#8]
Yeh, I like that - for the first 5 seconds or so I thought 'what the hell is this?'

The key is to just sit their and watch it turn into a ball - which it keeps doing - you just have to be patient.

I like this - in a screensaver kind of way. It's sort of modern arty - a bit trippy too (especially when the ball moves in and out of the screen).


big10p(Posted 2005) [#9]
I love trippy effects like this. Send it to Jeff Minter! :)


Banshee(Posted 2005) [#10]
The nearest thing I have is this part written 'scene' demo. It needs more before it's finished and i'll probably never get around to it - I wanted to change the ninja model to a girl dancing but I did this when my hard disk crashed and didn't have a 3d modeller so I had to move onto another project and that was that...

http://www.bansheestudios.com/stuff/GridTest.zip


puki(Posted 2005) [#11]
I liked that - but I shall remove the model as I think the demo looks better without the model.

Largeness.


Beaker(Posted 2005) [#12]
Probably seen this one before, and it only entertains for a few seconds, but:
;Beakers Hairy Balls 2003

Graphics3D 640,480
SetBuffer BackBuffer()

cam = CreateCamera ()
MoveEntity cam,0,0,-5

ball = CreateMesh()
EntityFX ball,32+2

ball2 = CreateSphere(5)
ScaleMesh ball2,3,3,3
EntityFX ball2,32+2
ClearTextureFilters 

tex = CreateTexture (128,128, 4+1)	;LoadTexture ("fur.png",4+1)
ScaleTexture tex,0.2,0.2
EntityTexture ball,tex

For x = 0 To TextureWidth(tex)-1
	For y = 0 To TextureHeight(tex)-1
		slot = Rand(1,3)
		r = 0
		g = 0
		b = 0
		Select slot
			Case 1
				r = 255
			Case 2
				g = 255
			Case 3
				b = 255
		End Select
		
		a = Rand(255)
		If a < 220 a = 0
		If x Mod 3 <> 1 Then a =0 
		argb = (a Shl 24) Or (r Shl 16) Or (g Shl 8) Or b
		WritePixel x,y,argb,TextureBuffer(tex)
	Next
Next


surf = GetSurface(ball2,1)
For f# = 0 To -0.02 Step -0.001
	ScaleMesh ball2,1.008,1.008,1.008
	RotateMesh ball2,0,-(f*20.0),0
	n# = 1-(-(f)*100.0/2.0)
	For vert = 0 To CountVertices(surf)-1
		VertexColor surf,vert,255,255,255,n
	Next
	AddMesh ball2,ball
Next
FreeEntity ball2

While Not KeyDown(1)
	Flip False
	RenderWorld
	TurnEntity ball,0.03,0.12,0.03
Wend
End



puki(Posted 2005) [#13]
>' Probably seen this one before'

"Beaker" - I am the only Blitzer to acknowledge your demo:

http://www.blitzbasic.com/codearcs/codearcs.php?code=627


Banshee(Posted 2005) [#14]
woo that's pretty, and hard to focus on.


Beaker(Posted 2005) [#15]
puki - not quite. I originally put it in the code archive because a lot of people were (on various threads) asking a) how to do vert alpha and b) how to do fur type effects.