Pointless Circle thingy...

Blitz3D Forums/Blitz3D Programming/Pointless Circle thingy...

You know how you sometimes find yourself coding for the sake of it... with no real aim... and you end up with something... well... kinda interesting and pointless at the same time...

Here's an example of such a thing!

Graphics 640,480

outerr = Rand(0,220)
innerr = outerr - Rand(10,outerr)
col = Rand(0,16777215)

Repeat


	LockBuffer FrontBuffer()
	
	For x=-outerr To outerr
		For y=-outerr To outerr
		
			r= Sqr((x*x)+(y*y))

			
			If r>=innerr And r<=outerr Then
				If intriangle(x,y,0,0,Sin(ang)*(outerr*2),Cos(ang)*(outerr*2),Sin(ang+2)*(outerr*2),Cos(ang+2)*(outerr*2)) Then 
					If r=innerr Or r=outerr Then c=16777215 Else c=col
					WritePixelFast x+320,y+240,c
				EndIf
			EndIf
		
		Next
	Next
	
	UnlockBuffer FrontBuffer()
	
	ang = (ang + 1) Mod 360
	
	If ang = 0 Then
		outerr = Rand(0,220)
		innerr = outerr - Rand(10,outerr)
		col = Rand(0,16777215)
	EndIf
		
		
	
Until KeyHit(1)


Function InTriangle(x,y,x1,y1,x2,y2,x3,y3)
	ab# = (y-y1)*(x2-x1) - (x-x1)*(y2-y1) 
	ca# = (y-y3)*(x1-x3) - (x-x3)*(y1-y3)
	bc# = (y-y2)*(x3-x2) - (x-x2)*(y3-y2)
	Return ab*bc>0 And bc*ca>0
End Function


I get a blank screen?

EDIT:
But I ran it in debug - in normal mode it works okay.

Pointless Circle


Funny, all my circles end up with an infinite number of points.

I get a blank screen in debug also. Not sure why?

Jason.

Me too , try this...

Graphics 640,480
SetBuffer BackBuffer()

outerr = Rand(0,220)
innerr = outerr - Rand(10,outerr)
col = Rand(0,16777215)

Repeat


	LockBuffer BackBuffer()
	
	For x=-outerr To outerr
		For y=-outerr To outerr
		
			r= Sqr((x*x)+(y*y))

			
			If r>=innerr And r<=outerr Then
				If intriangle(x,y,0,0,Sin(ang)*(outerr*2),Cos(ang)*(outerr*2),Sin(ang+2)*(outerr*2),Cos(ang+2)*(outerr*2)) Then 
					If r=innerr Or r=outerr Then c=16777215 Else c=col
					WritePixelFast x+320,y+240,c
				EndIf
			EndIf
		
		Next
	Next
	
	UnlockBuffer BackBuffer()
	Flip
	
ang = (ang + 1) Mod 360
	
	If ang = 0 Then
		outerr = Rand(0,220)
		innerr = outerr - Rand(10,outerr)
		col = Rand(0,16777215)
	EndIf
		
		
	
Until KeyHit(1)


Function InTriangle(x,y,x1,y1,x2,y2,x3,y3)
	ab# = (y-y1)*(x2-x1) - (x-x1)*(y2-y1) 
	ca# = (y-y3)*(x1-x3) - (x-x3)*(y1-y3)
	bc# = (y-y2)*(x3-x2) - (x-x2)*(y3-y2)
	Return ab*bc>0 And bc*ca>0
End Function


Yep, that works in debug. What`s the difference? Is it just adding a simple flip?

Jason.

What`s the difference?
I don't think windowed modes (like debug) support drawing to the frontbuffer.

That is most likely the cause but putting a flip in Robs original code still seems to cure the problem.

Jason.

Hehe, that's pretty funnnky!

Wahay! Draw your own CD layers :)

-

Seriously, though - although you state it's "pointless", this is VERY useful to me, as I get a bit lost on me trig, and I am now able to figure out how to draw circles/clock-timers etc. using snippets from your code (if you dont mind, that is?) ;)

Good stuff!

Hey, the next thing is to figure out how to draw alphabetic letters arranged in a curve around the hub...

figure out how to draw alphabetic letters arranged in a curve


... but we don't have a way to edit a thread's title !

Hey, the next thing is to figure out how to draw alphabetic letters arranged in a curve around the hub...
Having given this some thought (about 3 seconds worth ;) I think the easiest way is to create a disc mesh coords mapped as x being the radius and y being the circumference, then just texture it.