Results 1 to 8 of 8
  1. #1
    monica is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default Colour increasing and retaining animation

    Hi,
    I want to do animation for a calendar application. Each day of the month is represented as a grid cell. Each grid cell is with a background colour(blue). On certain condition i select some cells where i need to do animation. kindly help me how to perform animation for more than one grid where background colour increases(to dark blue) and then retaining back to the original background colour (blue).

    Thank you :)

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    What have you done so far? Can you show us your pertinent code and describe your problem and set up in much greater detail?

  3. #3
    monica is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default

    Hi,
    This interface has so many panels and components. so consider for example, there is a panel that has 10 grid cells, all with 'blue' background colour. If you could tell me how to apply the before said animation(smoothly change colour from blue to dark blue and again come back to blue) to more than one grid cell at the same time, then i can apply it to my code.
    Thank you.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by monica View Post
    Hi,
    This interface has so many panels and components. so consider for example, there is a panel that has 10 grid cells, all with 'blue' background colour. If you could tell me how to apply the before said animation(smoothly change colour from blue to dark blue and again come back to blue) to more than one grid cell at the same time, then i can apply it to my code.
    Thank you.
    What's a grid? A JPanel? A JLabel? Is this Swing? AWT? Where's your pertinent code?

    I hate to keep asking questions, but you seem to be reluctant to provide the details we've requested. Please see my link below on how to ask smart questions to see tips on what information would help us help you.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by monica View Post
    Hi,
    This interface has so many panels and components. so consider for example, there is a panel that has 10 grid cells, all with 'blue' background colour. If you could tell me how to apply the before said animation(smoothly change colour from blue to dark blue and again come back to blue) to more than one grid cell at the same time, then i can apply it to my code.
    Thank you.
    The RGB values for blue are 00, 00, FF; the RGB values for dark blue are 00, 00, x, where x <= FF. Use a timer that sets x to the value FF, FE ... x, ... FE, FF and use that x value to set the background color.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by JosAH View Post
    The RGB values for blue are 00, 00, FF; the RGB values for dark blue are 00, 00, x, where x <= FF. Use a timer that sets x to the value FF, FE ... x, ... FE, FF and use that x value to set the background color.
    That could work if she's using Swing unless she's using JLabels and without setting the opaque to true, which is why I've been asking for the details.

  7. #7
    monica is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default

    Hi,
    Sorry for framing a bad questions. I will go through the link that Fubarable gave and i will try to post proper questions from next time. Thank you for answering though.

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    OT: Fading colors is well supported in JavaFX.
    Java Code:
    import javafx.animation.KeyFrame;
    import javafx.animation.Timeline;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.paint.Color;
    import javafx.stage.Stage;
    import java.util.Random;
    
    def ROWS = 8;
    def COLS = 8;
    def SIDE = 50;
    def GAP = 4;
    def RADIUS = 8;
    def INTERVAL = 0.5s;
    def FADE = 2s;
    def rand = new Random();
    def BLUE = Color.hsb(240, 1.0, 1.0);
    def DARKBLUE = Color.hsb(240, 1.0, 0.5);
    var cells = [for (r in [0..<ROWS], c in [0..<COLS]) {
                Rectangle {
                  x: c * (SIDE + GAP)
                  y: r * (SIDE + GAP)
                  width: SIDE
                  height: SIDE
                  fill: Color.hsb(240, 1.0, 1.0);
                  arcWidth: RADIUS
                  arcHeight: RADIUS
                }
              }];
    
    function colorRandomCell(): Void {
      def cell = cells[rand.nextInt(ROWS * COLS)];
      Timeline {
        keyFrames: KeyFrame {
          time: FADE
          values: [{
              def temp = cell;
              if (temp.fill.equals(BLUE)) {
                temp.fill => DARKBLUE;
              } else {
                temp.fill => BLUE;
              }
            }]
        }
      }.playFromStart();
    }
    
    Timeline {
      repeatCount: Timeline.INDEFINITE
      keyFrames: KeyFrame {
        time: INTERVAL
        action: colorRandomCell;
      }
    }.playFromStart();
    
    Stage {
      title: "Color changer"
      scene: Scene {
        width: GAP + (SIDE + GAP) * COLS
        height: GAP + (SIDE + GAP) * ROWS
        content: [Group {
            layoutX: GAP
            layoutY: GAP
            content: cells
          }]
      }
    }
    db
    Last edited by DarrylBurke; 05-15-2011 at 08:14 PM. Reason: Updated the code

Similar Threads

  1. Increasing/decreasing an int variable with boundrys
    By david522 in forum New To Java
    Replies: 5
    Last Post: 05-12-2011, 01:04 AM
  2. Increasing Java heap space
    By davetheant in forum New To Java
    Replies: 2
    Last Post: 02-03-2011, 03:24 AM
  3. Replies: 18
    Last Post: 07-19-2010, 01:18 PM
  4. increasing jvm heap space
    By kizyle502 in forum Advanced Java
    Replies: 1
    Last Post: 05-15-2010, 11:51 AM
  5. all maximal increasing subsequences
    By hassanJava in forum Advanced Java
    Replies: 3
    Last Post: 04-23-2008, 05:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •