Help with a script

Discussion in 'Jiggy Runtime Development' started by psychofish25, May 1, 2008.

  1. psychofish25

    psychofish25 New Member

    Joined:
    Nov 20, 2007
    Messages:
    259
    Likes Received:
    3
    I am trying to write a code in which every time I tap on the screen to color changes. I was wondering why when I tap, it goes transparent, shows my background, and doesn't respond.

    Code:
    // com.program.colors
    // /Applications/Colors.app/main.js
    Plugins.load( "UIKit" );
    var window = new UIWindow( UIHardware.fullScreenApplicationContentRect );
    window.orderFront();
    window.makeKey();
    window.setHidden( false );
    window.backgroundColor = [ 1 , 1 , 1 , 1 ];
    var mainView = new UIView()
    window.setContentView( mainView );
    mainView.onTap = function()
    {
    var color1=Math.floor(Math.random());
    var color2=Math.floor(Math.random());
    var color3=Math.floor(Math.random());
    var color4=Math.floor(Math.random())*255;
    window.backgroundColor=[color1,color2,color3,color4];
    }
  2. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    i dont know if you realize it here, but you must assaign specific colors to each color, then assaign the random to the background color

    eg for color:

    var black = [ 0 , 0 , 0 , 255 ];

    then for window.backgroundColor = you must make this random between the colors you make
  3. psychofish25

    psychofish25 New Member

    Joined:
    Nov 20, 2007
    Messages:
    259
    Likes Received:
    3
    Oh okay.

    Sorry I'm a python coder and used to composing tuples. Thanks for the tip. Do you know where I could find a list of all the normal colors? This pattern doesn't quite make sense to me.
  4. PAEz

    PAEz New Member

    Joined:
    Jan 29, 2008
    Messages:
    201
    Likes Received:
    10
    or you could do it like this....

    Code:
    Plugins.load( "UIKit" );
    var window = new UIWindow( UIHardware.fullScreenApplicationContentRect );
    window.orderFront();
    window.makeKey();
    window.setHidden( false );
    window.backgroundColor = [ 1 , 1 , 1 , 1 ];
    var mainView = new UIView()
    window.setContentView( mainView );
    mainView.onTap = function()
    {
    var colour= new Array();
    colour[0]=Math.random();
    colour[1]=Math.random();
    colour[2]=Math.random();
    colour[3]=Math.random()*255;
    window.backgroundColor=colour;
    }
    just noticed ya new post... I think the colours goes...
    red, green, blue, alpha
    0-1, 0-1, 0-1, 0-255
  5. psychofish25

    psychofish25 New Member

    Joined:
    Nov 20, 2007
    Messages:
    259
    Likes Received:
    3
    Thanks for you help guys but I found the right problem.

    I was taking the floor of a math.rand which can only be from 0 to .999999 so every color was zero.

    Replacing floor with rand did the trick
  6. PAEz

    PAEz New Member

    Joined:
    Jan 29, 2008
    Messages:
    201
    Likes Received:
    10
    thats right but to be precise the reason it was crashing was just as you said, the floor thing made everything equal 0...but the alpha must be 1 and above..so it kept setting alpha to 0 and crashing
    colours start from 0 and go to 1
  7. psychofish25

    psychofish25 New Member

    Joined:
    Nov 20, 2007
    Messages:
    259
    Likes Received:
    3
    well alpha of zero doesnt crash the program, but instead doesn't show the color, so that wasn't really my problem. I later found out that last digit was alpha and fixed it at 1, so now I'm good.
  8. PAEz

    PAEz New Member

    Joined:
    Jan 29, 2008
    Messages:
    201
    Likes Received:
    10
    hahaha....derrrrr...i thought it crashed coz i could see the jiggy screen as the background had become tottaly transparent (obviously)

    Please Register or Log in to view images


    thanx for pointing that out, i feel like an idiot

    Please Register or Log in to view images

Share This Page