creating fun mood lamp

BlitzMax Forums/BlitzMax Programming/creating fun mood lamp

rocketdude786(Posted 2015) [#1]
i tried a few different versions but it only generates green
Global r,b,g
Global r2,b2,g2
Global spd = 10
rll:Int = Rnd(3)
While Not KeyDown(KEY_ESCAPE)
	Cls
	Select rll
		Case 0
			'subtract from void fields
			If r < 0 Then r:-spd Else r:+spd
			g2 = g
			If g2 Then g:-5
			b2 = b
			If b2 Then b:-5
			If r2 Then rll = 0 Else rll = Rnd(3)
			If rll = 0 Then r2 = Null
		Case 1
			'subtract from void fields
			If g < 0 Then g:-spd Else g:+spd
			r2 = r
			If r2 Then r:-5
			b2 = b
			If b2 Then b:-5
			If g2 Then rll = 1 Else rll = Rnd(3)
			If rll = 0 Then g2 = Null
		Case 2
			'subtract from void fields
			If b > 0 Then b:-spd Else b:+spd
			g2 = g
			If g2 Then g:-5
			r2 = r
			If r2 Then r:-5
			If b2 Then rll = 2
			If b2 Then b2:-5 Else rll = Rnd(3)
			If rll = 0 Then b2 = Null
	End Select
	SetColor r,g,b
	DrawText "Fun Mood Lamp"+"[]"+r+"[]"+g+"[]"+b,2,2
	SetColor(255,255,255)
	
	Flip
Wend



col(Posted 2015) [#2]
Hiya,
There are a couple of basic flaws in your example...

. No Graphics command? it is just an example but posting a compilable example is usually better when asking for help.
. No 'Strict'ness
. Rnd and Rand should really take 2 parameters - a minimum and maximum. You're better off using the integer version ( Rand ) as you're using integers.
. Use 'SeedRnd Millisecs()' for a quick way to use a different seed to generate random numbers from.
. Your main loop will saturate the color channels - that is the color range values should be between 0 and 255 but your code doesn't check for this correctly.

There may be more once you iron out those bugs.


rocketdude786(Posted 2015) [#3]
finally made a working demo. tell me what you think.
Const WIDTH = 640,HEIGHT = 480, DEPTH = 32

Graphics WIDTH,HEIGHT,DEPTH
	
Global x, y
Global ang
Global vdist
Global rlum, glum, blum
Global rang, gang, bang

While Not KeyDown(KEY_ESCAPE)
Local xr, yr
Local xg, yg
Local xb, yb

	vdist = Rnd(255)
	ang:+ Rnd(10)
	xr = Cos(ang/3*1)*vdist

vdist = Rnd(255)
	yr = Sin(ang/3*1)*vdist
vdist = Rnd(255)
	xg = Cos(ang/3*2)*vdist
vdist = Rnd(255)
	yg = Sin(ang/3*2)*vdist
vdist = Rnd(255)
	xb = Cos(ang/3*3)*vdist
vdist = Rnd(255)
	yb = Sin(ang/3*3)*vdist
	
	'red green
	'green blue
	'blue red
	rang = ATan2(xr-xg, yr-yg)*180 / Pi
	gang = ATan2(xg-xb, yg-yb)*180 / Pi
	bang = ATan2(xb-xr, yb-yr)*180 / Pi
	
	rlum = xr
	glum = xg
	blum = xb
	Cls
	SetColor rlum, glum, blum
	'SetColor 255, 255, 255
	SetLineWidth 8
	DrawLine xr+255, yr+255, 255, 255
	DrawLine xg+255, yb+255, 255, 255
	DrawLine xb+255, yb+255, 255, 255
	DrawText "Fun Mood Lamp",0,0
	Flip
Wend



col(Posted 2015) [#4]
I thought a 'mood lamp' would change slowly and smoothly from one colour to the next?
This appears to be quite fast and choppy. If you use some kind of interpolation function then'll be able to easily change the colour channels to smoothly fade from one colour to the next.


rocketdude786(Posted 2015) [#5]
heres one with separate channels.
Const WIDTH = 640,HEIGHT = 480, DEPTH = 32

Graphics WIDTH,HEIGHT,DEPTH
	
Global x, y
Global ang
Global vdist
Global rlum, glum, blum
Global rang, gang, bang
Global rbng, gbng, bbng
Global raxs, gaxs, baxs

While Not KeyDown(KEY_ESCAPE)
Local xr, yr
Local xrb, yrb
Local xg, yg
Local xgb, ygb
Local xb, yb
Local xbb, ybb

	raxs = 127
	gaxs = 127
	baxs = 127
	
	angr:+ Rnd(10)
	angg:+ Rnd(10)
	angb:+ Rnd(10)
	
	'If angr > raxs Then angr:-raxs
	xr = Cos(angr)*raxs+127
	yr = Sin(angr)*raxs
	'If angg > gaxs Then angg:-gaxs
	xg = Cos(angg-120)*gaxs+127
	yg = Sin(angg-120)*gaxs
	'If angb > baxs Then angb:-baxs
	xb = Cos(angb-240)*baxs+127
	yb = Sin(angb-240)*baxs
	
	'red green
	'green blue
	'blue red
	rang = ATan2(xr-xg, yr-yg)*180 / Pi
	gang = ATan2(xg-xb, yg-yb)*180 / Pi
	bang = ATan2(xb-xr, yb-yr)*180 / Pi
	
	rlum = xr
	glum = xg
	blum = xb
	
	Cls
	'SetColor 255, 255, 255
	SetLineWidth 8
	SetColor rlum, 0,0
	DrawLine xr+255, yr+255, 255, 255
	SetColor 0, glum, 0
	DrawLine xg+255, yb+255, 255, 255
	SetColor 0, 0, blum
	DrawLine xb+255, yb+255, 255, 255
	SetColor rlum, glum, blum
	DrawText "Fun Mood Lamp",0,0
	Flip
Wend



dw817(Posted 2015) [#6]
Umm ... I'm not getting any kind of mood lamp ? Just a series of fat colored lines ?

A mood lamp looks more like this maybe ?
Strict
Local i,z#
Graphics 512,384
SetBlend alphablend
SetAlpha .25
Repeat
  For i=63 To 1 Step-1
    SetColor 255-i*3+Sin(z#)*32,255-i*3+Sin(z#*2)*32,255-i*3+Sin(z#*4)*32
    DrawOval 256-i,176-i,i*2,i*2
    z#=z#+.005
  Next
  Flip
Until KeyDown(27)