// Copyright (c) 2007 Alberto Ruiz // All Rights Reserved. // Published under the BSD License. using Clutter; using GLib; using Gdk; using Math; class SuperOh { private Clutter.Timeline timeline; private Clutter.Group oh_group; private uint n_hands; construct { n_hands = 5; Clutter.Stage default_stage = (Clutter.Stage) Clutter.Stage.get_default (); timeline = new Clutter.Timeline (360, 60); timeline.loop = true; timeline.new_frame += frame_cb; Clutter.Actor stage = Clutter.Stage.get_default (); stage.set_size (800, 600); Gdk.Pixbuf redhand = Gdk.Pixbuf.from_file ("redhand.png", null); Clutter.Alpha alpha = new Clutter.Alpha (); alpha.set_timeline (timeline); alpha.set_func (Clutter.sine_func, null, null); oh_group = new Clutter.Group (); Clutter.Texture hand_texture = Clutter.Texture.from_pixbuf (redhand); for (uint i = 0; i < n_hands ; i++) { Clutter.CloneTexture hand = new Clutter.CloneTexture (hand_texture); int w = hand_texture.get_width (); int h = hand_texture.get_height (); int x = default_stage.get_width () / 2 + get_radius () * Math.cos ((float) i * (float) 3.14159265358979323846 / ((float) n_hands / 2.)) - w / 2; int y = (float) default_stage.get_height () / 2. + get_radius () * Math.sin ((float) i * (float) 3.14159265358979323846 / ((float) n_hands / 2.)) - (float) h / 2.; hand.set_position (x, y); oh_group.add_actor ((Clutter.Actor) hand); } oh_group.show_all (); } public void timeline_start () { timeline.start (); } private uint get_radius () { Clutter.Stage default_stage = (Clutter.Stage) Clutter.Stage.get_default (); return (default_stage.get_width () + default_stage.get_height ()) / 6; } private void frame_cb (Clutter.Timeline tl, int frame_num) { Clutter.Stage default_stage = (Clutter.Stage) Clutter.Stage.get_default (); oh_group.rotate_z (frame_num, (int) default_stage.get_width () / 2, (int) default_stage.get_height () / 2); for (int i = 0; i < n_hands; i++) { Clutter.Actor hand = oh_group.get_nth_child(i); float angle = frame_num * -1; hand.rotate_x (angle, (int) hand.get_width () / 2, (int) hand.get_height () / 2); hand.rotate_y (angle, (int) hand.get_width () / 2, (int) hand.get_height () / 2); } } public Clutter.Group get_group () { return oh_group; } } class TestActors { static void main (string[] args) { Clutter.init (out args); Clutter.Stage stage = (Clutter.Stage) Clutter.Stage.get_default (); Clutter.Color background; stage.get_color(out background); background.red = (char) 0x61; background.green = (char) 0x64; background.blue = (char) 0x8c; background.alpha = (char) 0xff; stage.set_color (out background); SuperOh hands = new SuperOh (); hands.timeline_start (); stage.add_actor (hands.get_group ()); stage.show_all (); Clutter.main (); } }