Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

setFillColor - no matter what I type I only get some mind of hue between black and grey.
Started by Simon Bøasæter Oct 20 2019 01:46 AM

2 replies to this topic
setfillcolor newbie

Best Answer XeduR @Spyric , 20 October 2019 - 09:36 AM

What you are literally doing is creating a single global variable called random that you give a pseudo random value between 1 and 255. You then use this single value for red, green and blue in the setFillColor() method. This is essentially the same as just providing one value to the method.

 

If you want random non-greyscale colours, then you need three different random values, for instance:

object:setFillColor( math.random(), math.random(), math.random() )

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Simon Bøasæter

[GLOBAL: userInfoPane.html]
Simon Bøasæter
  • Observer

  • 6 posts
  • Corona SDK

Hello there and thanks for the help in advance. I am currently working on the balloon game which is provided in the tutorial and my goal for now is to make random colored balloons in my menu. However, no matter what I input as color values they only come out as black, white or grey. I am using setFillColor on the balloon image, I changed the color of the balloon to white in the actual png.

 

What is the problem, I dont quite understand why :( 

I appreciate all the help I can get as this one got me quite puzzled. Here is the code.

  for i=0,20 do
    i=i+1
    random = math.random(1,255)
    offsetX = offsetX + math.random(10,30)
    offsetY = offsetY + math.random(-50,30)
    test = "balloon" .. i
    test = display.newImageRect( "balloon.png", 100, 100)
    test:setFillColor(random/255,random/255,random/255,random/255)
    test.x = display.contentCenterX + offsetX
    test.y = display.contentCenterY+display.viewableContentHeight-offsetY
    physics.addBody( test, "dynamic" , {radius = 50, bounce=0.5})
    test.gravityScale = -1
    test.linearDamping = 1
    test.alpha = 0.9
  end


[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 981 posts
  • Corona SDK

  Best Answer

What you are literally doing is creating a single global variable called random that you give a pseudo random value between 1 and 255. You then use this single value for red, green and blue in the setFillColor() method. This is essentially the same as just providing one value to the method.

 

If you want random non-greyscale colours, then you need three different random values, for instance:

object:setFillColor( math.random(), math.random(), math.random() )

  • Simon Bøasæter likes this

[TOPIC: post.html]
#3

Simon Bøasæter

[GLOBAL: userInfoPane.html]
Simon Bøasæter
  • Observer

  • 6 posts
  • Corona SDK

 

What you are literally doing is creating a single global variable called random that you give a pseudo random value between 1 and 255. You then use this single value for red, green and blue in the setFillColor() method. This is essentially the same as just providing one value to the method.

 

If you want random non-greyscale colours, then you need three different random values, for instance:

object:setFillColor( math.random(), math.random(), math.random() )

oh that makes sense, thanks alot for the help! 




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: setfillcolor, newbie