Changing color in Ruby.

For general discussion related FlowStone
Post Reply
User avatar
lalalandsynth
Posts: 600
Joined: Sat Oct 01, 2016 12:48 pm

Changing color in Ruby.

Post by lalalandsynth »

I am trying to get more into Ruby , but man, not sure where to begin.

I am trying to change the color of the text in this piece of code. I can change it to black but I need Gray.
Where can I find a reference to learn about what Brushes are and what colors are available or preferably how to change this line so it can accept color input. I got quickly overwhelmed trying to google my way forward.

# Text
text_brush = Brush.new white
@font = Font.new "Segoe UI", 1.5, "bold"
sf = StringFormat.new
sf.setAlignment "center"
sf.setLineAlignment "center"
view.setTextRenderingHint "ClearTypeGridFit"
User avatar
lalalandsynth
Posts: 600
Joined: Sat Oct 01, 2016 12:48 pm

Re: Changing color in Ruby.

Post by lalalandsynth »

No way ! I figured it out ! woohoo :P

The colors were defined earlier in the code so I added gray !

dgrey = Color.new 125, 126, 126
black = Color.new 0, 11, 16
white = Color.new 240
selec_col = @col
User avatar
nix
Posts: 817
Joined: Tue Jul 13, 2010 10:51 am

Re: Changing color in Ruby.

Post by nix »

nice one mate,
I know that feeling.
Maybe there is alpha too-
a fourth delimit?
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: Changing color in Ruby.

Post by RJHollins »

nix wrote:nice one mate,
I know that feeling.
Maybe there is alpha too-
a fourth delimit?

From the Manual:
Color
You can't get anywhere without a Color so let's start here. Color objects are defined by three primary
colour components (red, green and blue) plus an optional transparency which is called Alpha. Each
component is an integer value in thsete range 0-255.
To create a Color object:
myColor = Color.new a,r,g,b
Where a is the alpha, r is the red component, g is the green component and b is the blue component.
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Changing color in Ruby.

Post by tulamide »

lalalandsynth wrote:Where can I find a reference to learn about what Brushes are and what colors are available or preferably how to change this line so it can accept color input.

I'm not sure if I mention it once a day or twice per minute, but all about Ruby in Flowstone can be found (and must be read) in User Manual, Chapter 8
"There lies the dog buried" (German saying translated literally)
User avatar
lalalandsynth
Posts: 600
Joined: Sat Oct 01, 2016 12:48 pm

Re: Changing color in Ruby.

Post by lalalandsynth »

Thanks , reading it.
User avatar
Spogg
Posts: 3368
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England
Contact:

Re: Changing color in Ruby.

Post by Spogg »

You might find my own experience and literature collection useful:

viewtopic.php?f=2&t=12169&p=42199&hilit=spogg+is+learning#p42194

Cheers

Spogg
User avatar
lalalandsynth
Posts: 600
Joined: Sat Oct 01, 2016 12:48 pm

Re: Changing color in Ruby.

Post by lalalandsynth »

Thanks , having a look.

So I am trying to reverse an array and so far I can do this and it works.
output 0, @in.lines.reverse.join("\n")

But , now I only want to reverse every other number in the array.

So I might have an array like this.

1
34
2
35
3
36
4
47

But I want to reverse it in this manner.

1
47
2
36
3
35
4
34

Rather then.
34
4
35
3
36
2
47
1

Any tops on sorting the list and choosing what to reverse?
I might even want to randomize the value of every other number. Or reverse every third value.
I have done this before with great pains on green , but should be simple with Ruby.
Post Reply