Author 
Topic: colour circle (Read 935 times) 

zzz000abc
Full Member
member is offline
Gender:
Posts: 270


colour circle
« Thread started on: May 9^{th}, 2017, 4:04pm » 

hi, there is a post in LB forum with title colour circle by tenochtitlanuk http://libertybasic.conforums.com/index.cgi?action=display&board=open&num=1487615262&start=0#1487615262 here is an attempt to code that: Code: WindowWidth=DisplayWidth:WindowHeight=DisplayHeight
f=25:t=1/f:k=2/f
open"disc"for graphics as#1
r=255:x0=400:y0=400:rd=300:dc=atn(1)/45
for i=0 to 360 step t
x=x0+rd*cos(i*dc):y=y0+rd*sin(i*dc)
if i>0 and i<60 then r=r0.5*k:g=g+1.5*k
if i>60 and i<119 then r=r1.5*k:g=g+0.5*k
if i>120 and i<180 then g=g0.5*k:b=b+k*1.5
if i>180 and i<239 then g=g1.5*k:b=b+0.5*k
if i>240 and i<300 then b=b0.5*k:r=r+1.5*k
if i>300 and i<355 then b=b1.5*k:r=r+0.5*k
if i>=355 then r=255
#1 "discard;down"
#1 "size 2;color ";r;" ";g;" ";b
#1 "line ";x0;" ";y0;" ";x;" ";y
next
wait

« Last Edit: May 9^{th}, 2017, 4:12pm by zzz000abc » 
Logged




tsh73
JBSupporter
member is offline
Gender:
Posts: 3662


Re: colour circle
« Reply #1 on: May 10^{th}, 2017, 02:07am » 

Hello zzz000abc It sure looks cool  but how you can be sure your RGB changes right way? I put it to Excel  look if it is what you wanted?
EDIT now with JB itself Code:nomainwin
global winW, winH, xmin, xmax, ymin, ymax
open "test" for graphics_nsb_nf as #gr
#gr "trapclose [quit]"
#gr "down"
global pi
pi = acs(1)
#gr "home"
#gr "posxy w h"
winW=2*w: winH=2*h
'f(x)=1.5*x^22*sin(5*x), x in [2,3]
xmin=0: xmax=360
nPoints=360
dx=(xmaxxmin)/nPoints 'so this will be step in math coordinates
ymin=20
ymax=270
#gr "size 1"
f=25:t=1/f:k=2/f
r=255:x0=400:y0=400:rd=300:dc=atn(1)/45
for i=0 to 360 step t
x=x0+rd*cos(i*dc):y=y0+rd*sin(i*dc)
if i>0 and i<60 then r=r0.5*k:g=g+1.5*k
if i>60 and i<119 then r=r1.5*k:g=g+0.5*k
if i>120 and i<180 then g=g0.5*k:b=b+k*1.5
if i>180 and i<239 then g=g1.5*k:b=b+0.5*k
if i>240 and i<300 then b=b0.5*k:r=r+1.5*k
if i>300 and i<355 then b=b1.5*k:r=r+0.5*k
if i>=355 then r=255
' #1 "discard;down"
' #1 "size 2;color ";r;" ";g;" ";b
' #1 "line ";x0;" ";y0;" ";x;" ";y
#gr "color red"
#gr "set ";sx(i);" ";sy(r)
#gr "color green"
#gr "set ";sx(i);" ";sy(g)
#gr "color blue"
#gr "set ";sx(i);" ";sy(b)
next
'and finally, add axis
#gr "color black"
#gr "size 1"
#gr "line ";sx(xmin);" ";sy(0);" ";sx(xmax);" ";sy(0)
#gr "line ";sx(0);" ";sy(ymin);" ";sx(0);" ";sy(ymax)
'labeling
#gr "place ";sx(0)+5;" ";sy(0)5
#gr "\0,0"
#gr "place ";sx(xmax)20;" ";sy(0)5
#gr "\X"
#gr "place ";sx(0)+5;" ";sy(ymax)+20
#gr "\Y"
#gr "flush"
#gr, "getbmp drawing 1 1 ";winW;" ";winH
bmpsave "drawing", "graph.bmp"
wait
[quit]
close #gr
end
'"any" function. You can change it as you like
function f(x)
f=1.5*x^22*sin(5*x)
end function
'To translate X from interval [a,b] to [c,d] we'll do (Xa)/(ba)*(dc)+c.
'create two functions: sx(x) and sy(y)
function sx(x)
sx=(xxmin)/(xmaxxmin)*winW
end function
function sy(y)
sy=winH(yymin)/(ymaxymin)*winH 'Y is inverted, so winH...
end function

« Last Edit: May 10^{th}, 2017, 3:43pm by tsh73 » 
Logged

Q: "And if I took your codes and compile them, and sell them for a profit"? A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it  please do. (enjoying JB 1.01 on WinXP, netbook and desktop)



bplus
Senior Member
member is offline
Gender:
Posts: 1286


Re: colour circle
« Reply #2 on: May 10^{th}, 2017, 08:20am » 

Hi zzz, did you change this line: Code: from 370? I was going to comment but see it different now.
Hi tsh, "the right way" ? I am pretty sure zzz was going for pretty and he did get that! PLUS (my own specification too) a method that spreads the color changes out evenly over the circle area.
Then there are the JB constraints which pretty much rules out individual pixel drawing, you could really do a job with pixel by pixel operation but who wants to wait that long? Imagine wanting to show off a picture and having to develop the film each time you display it.
Nice work, john tenochtitlanuk and/or the guy he got the idea from.
Good eye zzz000abc! for finding this gem, playing and sharing it with us.


Logged

B+



tenochtitlanuk ( John F)
Full Member
member is offline
Gender:
Posts: 432


Re: colour circle
« Reply #3 on: May 10^{th}, 2017, 10:00am » 

The idea comes from Rosetta Code which has 'inspired' me to produce LB/JB solutions to many tasks. To get the 'wheel' to fadetoblack or to white you HAVE to plot a pixel at a time and wait. I do have other things to do in my life, and a colourful graphic is something to cheer me up perhaps the next morning. See LB Forum
NB If an OP edits a post, the convention is to add to the original post a line to say what was edited. I too noticed the 370 had changed..


Logged

Visit my LB/JB pages at http://www.diga.me.uk/index.html I use XP and Ubuntu Linux on old machines!



tsh73
JBSupporter
member is offline
Gender:
Posts: 3662


Re: colour circle
« Reply #4 on: May 10^{th}, 2017, 3:23pm » 

RE:"the right way" it looks for me like graphs of R , G , B of (t) should be symmetrical. I just don't see the reason why not. So then I see "R" curve moved some 20 pixels up, I suspect programming error.
For example, here's the graph for rainbow$( ) function Code:nomainwin
global winW, winH, xmin, xmax, ymin, ymax
open "test" for graphics_nsb_nf as #gr
#gr "trapclose [quit]"
#gr "down"
#gr "home"
#gr "posxy w h"
winW=2*w: winH=2*h
'f(x)=1.5*x^22*sin(5*x), x in [2,3]
xmin=0: xmax=360
nPoints=360
dx=(xmaxxmin)/nPoints 'so this will be step in math coordinates
ymin=20
ymax=270
#gr "size 1"
#gr "color red"
c$=rainbow$(xmin/xmax)
y=val(word$(c$,1))
#gr "set ";sx(xmin);" ";sy(y) 'just set first dot
for x=xmin to xmax step dx
c$=rainbow$(x/xmax)
y=val(word$(c$,1))
#gr "goto ";sx(x);" ";sy(y) 'then connect dots
next
#gr "color green"
c$=rainbow$(xmin/xmax)
y=val(word$(c$,2))
#gr "set ";sx(xmin);" ";sy(y) 'just set first dot
for x=xmin to xmax step dx
c$=rainbow$(x/xmax)
y=val(word$(c$,2))
#gr "goto ";sx(x);" ";sy(y) 'then connect dots
next
#gr "color blue"
c$=rainbow$(xmin/xmax)
y=val(word$(c$,3))
#gr "set ";sx(xmin);" ";sy(y) 'just set first dot
for x=xmin to xmax step dx
c$=rainbow$(x/xmax)
y=val(word$(c$,3))
#gr "goto ";sx(x);" ";sy(y) 'then connect dots
next
'and finally, add axis
#gr "color black"
#gr "size 1"
#gr "line ";sx(xmin);" ";sy(0);" ";sx(xmax);" ";sy(0)
#gr "line ";sx(0);" ";sy(ymin);" ";sx(0);" ";sy(ymax)
'labeling
#gr "place ";sx(0)+5;" ";sy(0)5
#gr "\0,0"
#gr "place ";sx(xmax)20;" ";sy(0)5
#gr "\X"
#gr "place ";sx(0)+5;" ";sy(ymax)+20
#gr "\Y"
#gr "flush"
#gr, "getbmp drawing 1 1 ";winW;" ";winH
bmpsave "drawing", "graph.bmp"
wait
[quit]
close #gr
end
'"any" function. You can change it as you like
function f(x)
f=1.5*x^22*sin(5*x)
end function
'To translate X from interval [a,b] to [c,d] we'll do (Xa)/(ba)*(dc)+c.
'create two functions: sx(x) and sy(y)
function sx(x)
sx=(xxmin)/(xmaxxmin)*winW
end function
function sy(y)
sy=winH(yymin)/(ymaxymin)*winH 'Y is inverted, so winH...
end function
'
' 0..1 into redgreenbluered continuous colors
function rainbow$(x)
hi = int((x*6) mod 6)+ 5*(x<0) 'fixed to 0..5
f = (x*6) mod 1 + (x<0) 'frac, 0..1
q = (1f)
select case hi
case 0
r = 1: g = f: b = 0
case 1
r = q: g = 1: b = 0
case 2
r = 0: g = 1: b = f
case 3
r = 0: g = q: b = 1
case 4
r = f: g = 0: b = 1
case 5
r = 1: g = 0: b = q
end select
R = int(r*255)
G = int(g*255)
B = int(b*255)
rainbow$= R;" ";G;" ";B
end function

« Last Edit: May 10^{th}, 2017, 3:24pm by tsh73 » 
Logged

Q: "And if I took your codes and compile them, and sell them for a profit"? A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it  please do. (enjoying JB 1.01 on WinXP, netbook and desktop)



tsh73
JBSupporter
member is offline
Gender:
Posts: 3662


Re: colour circle
« Reply #5 on: May 10^{th}, 2017, 3:30pm » 

Here's Bluatigro rainbow$ function
from here LB \ games and graphics \ julia fractel


Logged

Q: "And if I took your codes and compile them, and sell them for a profit"? A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it  please do. (enjoying JB 1.01 on WinXP, netbook and desktop)



tsh73
JBSupporter
member is offline
Gender:
Posts: 3662


Re: colour circle
« Reply #6 on: May 10^{th}, 2017, 3:39pm » 

tenochtitlanuk ( John F) R G B from linked thread looks really like mine. But it looks like some points got misplaced See for yourself if I broke something. Code:nomainwin
global winW, winH, xmin, xmax, ymin, ymax
open "test" for graphics_nsb_nf as #gr
#gr "trapclose [quit]"
#gr "down"
global pi
pi = acs(1)
#gr "home"
#gr "posxy w h"
winW=2*w: winH=2*h
'f(x)=1.5*x^22*sin(5*x), x in [2,3]
xmin=0: xmax=360
nPoints=360
dx=(xmaxxmin)/nPoints 'so this will be step in math coordinates
ymin=20
ymax=270
#gr "size 1"
#gr "color red"
c$=rainbow$(xmin/xmax)
y=val(word$(c$,1))
#gr "set ";sx(xmin);" ";sy(y) 'just set first dot
for x=xmin to xmax step dx
c$=rainbow$(x/xmax)
y=val(word$(c$,1))
#gr "goto ";sx(x);" ";sy(y) 'then connect dots
next
#gr "color green"
c$=rainbow$(xmin/xmax)
y=val(word$(c$,2))
#gr "set ";sx(xmin);" ";sy(y) 'just set first dot
for x=xmin to xmax step dx
c$=rainbow$(x/xmax)
y=val(word$(c$,2))
#gr "goto ";sx(x);" ";sy(y) 'then connect dots
next
#gr "color blue"
c$=rainbow$(xmin/xmax)
y=val(word$(c$,3))
#gr "set ";sx(xmin);" ";sy(y) 'just set first dot
for x=xmin to xmax step dx
c$=rainbow$(x/xmax)
y=val(word$(c$,3))
#gr "goto ";sx(x);" ";sy(y) 'then connect dots
next
'and finally, add axis
#gr "color black"
#gr "size 1"
#gr "line ";sx(xmin);" ";sy(0);" ";sx(xmax);" ";sy(0)
#gr "line ";sx(0);" ";sy(ymin);" ";sx(0);" ";sy(ymax)
'labeling
#gr "place ";sx(0)+5;" ";sy(0)5
#gr "\0,0"
#gr "place ";sx(xmax)20;" ";sy(0)5
#gr "\X"
#gr "place ";sx(0)+5;" ";sy(ymax)+20
#gr "\Y"
#gr "flush"
#gr, "getbmp drawing 1 1 ";winW;" ";winH
bmpsave "drawing", "graph.bmp"
wait
[quit]
close #gr
end
'"any" function. You can change it as you like
function f(x)
f=1.5*x^22*sin(5*x)
end function
'To translate X from interval [a,b] to [c,d] we'll do (Xa)/(ba)*(dc)+c.
'create two functions: sx(x) and sy(y)
function sx(x)
sx=(xxmin)/(xmaxxmin)*winW
end function
function sy(y)
sy=winH(yymin)/(ymaxymin)*winH 'Y is inverted, so winH...
end function
'
' 0..1 into redgreenbluered continuous colors
function rainbowTsh$(x)
hi = int((x*6) mod 6)+ 5*(x<0) 'fixed to 0..5
f = (x*6) mod 1 + (x<0) 'frac, 0..1
q = (1f)
select case hi
case 0
r = 1: g = f: b = 0
case 1
r = q: g = 1: b = 0
case 2
r = 0: g = 1: b = f
case 3
r = 0: g = q: b = 1
case 4
r = f: g = 0: b = 1
case 5
r = 1: g = 0: b = q
end select
R = int(r*255)
G = int(g*255)
B = int(b*255)
rainbow$= R;" ";G;" ";B
end function
'============================
'bluatigro rainbow
function rgb$( r , g , b )
r = int( r ) and 255
g = int( g ) and 255
b = int( b ) and 255
rgb$ = str$( r ) ;" ";g;" ";b
end function
function rainbowBLu$( deg )
deg = deg*360
r = sin( rad( deg ) ) * 127 + 128
g = sin( rad( deg  120 ) ) * 127 + 128
b = sin( rad( deg + 120 ) ) * 127 + 128
rainbow$ = rgb$( r , g , b )
end function
function rad( deg )
rad = deg * pi / 180
end function
'============================
'tenochtitlanuk rainbow
function rainbow$( deg )
angle = deg*360
sector =int( angle /60) ' ...split into six 60 degree sectors, labelled 0 to 5
slope =( angle mod 60) /60 *255 ' ...and each split into 1 degree sectors.
scan
select case sector
case 0
col$ ="255 "; str$( int( slope)); " 0"
case 1
col$ =str$( int( 256 slope)); " 255 0"
case 2
col$ ="0 255 "; str$( int( slope))
case 3
col$ ="0 "; str$( int( 256 slope)); " 255"
case 4
col$ =str$( int( slope)); " 0 255"
case 5
col$ ="255 0 "; str$( int( 256 slope))
end select
red =val( word$( col$, 1)): grn =val( word$( col$, 2)): blu =val( word$( col$, 3))
rainbow$ = rgb$( red , grn , blu )
end function


Logged

Q: "And if I took your codes and compile them, and sell them for a profit"? A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it  please do. (enjoying JB 1.01 on WinXP, netbook and desktop)



bplus
Senior Member
member is offline
Gender:
Posts: 1286


Re: colour circle
« Reply #7 on: May 10^{th}, 2017, 4:50pm » 

I throw my circle into the hat, now that I am reminded I worked with blu's rainbow function too!
Code:'rainbow circle.txt for JB [B+=MGA] 20170510
'oh yeah, blu's rainbow! easy
global H$, XMAX, YMAX, PI
H$ = "#gr"
XMAX = 500
YMAX = 500
PI = acs(1)
nomainwin
WindowWidth = XMAX + 8
WindowHeight = YMAX + 32
UpperLeftX = (1200  XMAX) / 2 'or delete if XMAX is 1200 or above
UpperLeftY = (700  YMAX) / 2 'or delete if YMAX is 700 or above
open "Rainbow Circle thanks bluatigro" for graphics_nsb_nf as #gr
#gr "setfocus"
#gr "trapclose quit"
#gr "when leftButtonUp lbu"
#gr "when characterInput keyPress"
#gr "down"
#gr "fill black"
#gr "size 2"
cx =XMAX/2 : cy =YMAX/2
for a = 0 to 2*PI step PI/3600
scan
x1 = cx+ 250 * cos(a)
y1 = cy + 250 * sin(a)
call rainbow H$, a/(2*PI)
#gr "line ";cx;" ";cy;" ";x1;" ";y1
next
#gr "flush"
wait
sub rainbow H$, fraction
radians = fraction * 2 * PI
r = sin( radians ) * 127 + 128
g = sin( radians  2 / 3 * PI ) * 127 + 128
b = sin( radians + 2 / 3 * PI ) * 127 + 128
#H$ "color ";r;" ";g;" ";b
end sub
sub keyPress H$, k$
call quit H$
end sub
sub lbu H$, x, y
call quit H$
end sub
sub quit H$
close #H$
end
end sub


Logged

B+



zzz000abc
Full Member
member is offline
Gender:
Posts: 270


Re: colour circle
« Reply #8 on: May 11^{th}, 2017, 12:50am » 

Quote:the convention is to add to the original post a line to say what was edited 

sorry for not following the convention.
Quote:from 370? I was going to comment but see it different now. 

Hi, B+ I was doing experiment after getting the output for fine tuning. So I posted the code parts of which looks weird.
Quote:I put it to Excel  look if it is what you wanted? 

Hi,tsh are you talking about y coordinates of the graphs? the problem is with exact division. I didn't get what is meant by program error.I will provide complete analysis in the next post. here is the modified code which can with stand excel test I think. Code: WindowWidth=DisplayWidth:WindowHeight=DisplayHeight
f=24:t=1/f:k=2/f
open"disc"for graphics as#1
r=240:x0=400:y0=400:rd=300:dc=atn(1)/45
for i=0 to 360 step t
x=x0+rd*cos(i*dc):y=y0+rd*sin(i*dc)
if i>0 and i<60 then r=r0.5*k: g=g+1.5*k
if i>60 and i<120 then r=r1.5*k:g=g+0.5*k
if i>120 and i<180 then g=g0.5*k: b=b+1.5*k
if i>180 and i<239.95 then g=g1.5*k:b=b+0.5*k
if i>240 and i<299 then b=b0.5*k: r=r+1.5*k
if i>300 and i<360 then b=b1.5*k:r=r+0.5*k
#1 "discard;down"
#1 "size 2;color ";r;" ";g;" ";b
#1 "line ";x0;" ";y0;" ";x;" ";y
next
wait
on the other hand if you think pattern(shape) of red color (blue colored line) differs from other two colors pattern then you are mistaken. you just imagine excel sheet is folded and left and right edges joined you can see same patterns for the three colors.


Logged




Rod
Administrator
member is offline
Graphics = Goosebumps!
Gender:
Posts: 3182


Re: colour circle
« Reply #9 on: May 11^{th}, 2017, 02:06am » 

I have not been able to run and examine the code. However the point of a color wheel is not to look nice it is to deliver a unique color every pixel step. The mouse can never find two similar values. Maximum spread of color in minimum area. So things like size = 2 and line drawing won't cut it.
That's the point John makes about plotting x,y


Logged




tsh73
JBSupporter
member is offline
Gender:
Posts: 3662


Re: colour circle
« Reply #10 on: May 11^{th}, 2017, 04:11am » 

zzz000abc, Quote:on the other hand if you think pattern(shape) of red color (blue colored line) differs from other two colors pattern 

I see the shape is the same. But I see red curve minimum is about 20, while all others are from 0.
Rod, Quote:However the point of a color wheel is not to look nice it is to deliver a unique color every pixel step. 

we don't actually *need* an instrument for "unique color every pixel". It's all about getting pretty picture, really.


Logged

Q: "And if I took your codes and compile them, and sell them for a profit"? A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it  please do. (enjoying JB 1.01 on WinXP, netbook and desktop)



bplus
Senior Member
member is offline
Gender:
Posts: 1286


Re: colour circle
« Reply #11 on: May 11^{th}, 2017, 08:29am » 

Gotta say, I like pretty too!
What is the point or getting every point right if JB doesn't have point function? (builtin, I mean, JB does have tsh who makes great points and even has algo to get a color point in JB).
But it is a good point too to be reminded the point of a color wheel is to get a unique color off it to use in drawing, like an artist palette which most often doesn't look pretty.
Hey, maybe we could build a getColor dialog window with a less than perfect color circle.


Logged

B+



tenochtitlanuk ( John F)
Full Member
member is offline
Gender:
Posts: 432


Re: colour circle
« Reply #12 on: May 11^{th}, 2017, 12:02pm » 

Yup, Anatoly, for me too it is all about getting pretty pictures!
Rod Code:a unique color every pixel step To get a display that allowed you to point at and select every possible 24 bit colour, you'd need an image with 2^24 pixels, ie 2^12 or 2048x2048, so these colour wheels are presenting a subset. Now how about moving by mouse through a 3D colour space 256x256x256??? I might do an animated GIF of 256 layers each 256x256 of such an object.....


Logged

Visit my LB/JB pages at http://www.diga.me.uk/index.html I use XP and Ubuntu Linux on old machines!



tsh73
JBSupporter
member is offline
Gender:
Posts: 3662


Re: colour circle
« Reply #13 on: May 11^{th}, 2017, 1:43pm » 

Quote:Now how about moving by mouse through a 3D colour space 256x256x256 

I *think* I've seen color selector in form of RGB circle and 0..255 slider. Though I cannot point to program I've seen it  just too many programs. Might as well made it out.
EDIT just checked Gimp and myPaint color circles are by default small  160x160 Though it could be scaled by dragging.

« Last Edit: May 11^{th}, 2017, 1:51pm by tsh73 » 
Logged

Q: "And if I took your codes and compile them, and sell them for a profit"? A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it  please do. (enjoying JB 1.01 on WinXP, netbook and desktop)



bplus
Senior Member
member is offline
Gender:
Posts: 1286


Re: colour circle
« Reply #14 on: May 11^{th}, 2017, 4:16pm » 

Yes, tons of sliders maybe in JB wiki ?
But Sliders aren't pretty ;))


Logged

B+



