seed r259 - trunk/examples/lightsoff



Author: hortont
Date: Wed Nov 12 10:45:27 2008
New Revision: 259
URL: http://svn.gnome.org/viewvc/seed?rev=259&view=rev

Log:
Adjustable 'light' size for lights off.



Modified:
   trunk/examples/lightsoff/back.svg
   trunk/examples/lightsoff/board.js
   trunk/examples/lightsoff/front.svg
   trunk/examples/lightsoff/light.js
   trunk/examples/lightsoff/main.js
   trunk/examples/lightsoff/score.js

Modified: trunk/examples/lightsoff/back.svg
==============================================================================
--- trunk/examples/lightsoff/back.svg	(original)
+++ trunk/examples/lightsoff/back.svg	Wed Nov 12 10:45:27 2008
@@ -9,8 +9,8 @@
    xmlns:xlink="http://www.w3.org/1999/xlink";
    xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd";
    xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape";
-   width="563.97571"
-   height="193.50128"
+   width="251.11343"
+   height="85.04348"
    id="svg3307"
    sodipodi:version="0.32"
    inkscape:version="0.46"
@@ -20,6 +20,17 @@
   <defs
      id="defs3309">
     <linearGradient
+       id="linearGradient3169">
+      <stop
+         style="stop-color:#ffffff;stop-opacity:0.024;"
+         offset="0"
+         id="stop3171" />
+      <stop
+         style="stop-color:#ffffff;stop-opacity:0.42399999;"
+         offset="1"
+         id="stop3173" />
+    </linearGradient>
+    <linearGradient
        id="linearGradient3155">
       <stop
          style="stop-color:#222222;stop-opacity:1;"
@@ -34,16 +45,6 @@
          offset="1"
          id="stop3159" />
     </linearGradient>
-    <linearGradient
-       inkscape:collect="always"
-       xlink:href="#linearGradient3155"
-       id="linearGradient2542"
-       gradientUnits="userSpaceOnUse"
-       x1="563.97571"
-       y1="193.50128"
-       x2="563.97571"
-       y2="-5.4687498e-06"
-       gradientTransform="translate(60.869289,572.7544)" />
     <inkscape:perspective
        sodipodi:type="inkscape:persp3d"
        inkscape:vp_x="0 : 526.18109 : 1"
@@ -51,6 +52,26 @@
        inkscape:vp_z="744.09448 : 526.18109 : 1"
        inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
        id="perspective3315" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient3169"
+       id="linearGradient2412"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="translate(60.312567,681.79066)"
+       x1="248.37836"
+       y1="159.71176"
+       x2="248.37836"
+       y2="110.72863" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient3155"
+       id="linearGradient2415"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="translate(60.31257,681.79067)"
+       x1="251.11343"
+       y1="85.043472"
+       x2="251.11343"
+       y2="-9.9403951e-06" />
   </defs>
   <sodipodi:namedview
      id="base"
@@ -62,9 +83,9 @@
      objecttolerance="10"
      inkscape:pageopacity="0.0"
      inkscape:pageshadow="2"
-     inkscape:zoom="0.41970601"
-     inkscape:cx="644.81282"
-     inkscape:cy="10.147356"
+     inkscape:zoom="1.3330629"
+     inkscape:cx="125"
+     inkscape:cy="41.943272"
      inkscape:document-units="px"
      inkscape:current-layer="layer1"
      showgrid="false"
@@ -87,18 +108,10 @@
      inkscape:label="Layer 1"
      inkscape:groupmode="layer"
      id="layer1"
-     transform="translate(-60.869289,-572.75439)">
-    <rect
-       style="opacity:1;fill:url(#linearGradient2542);fill-opacity:1;stroke:#5d5d5d;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
-       id="rect2540"
-       width="561.97571"
-       height="191.50128"
-       x="61.869289"
-       y="573.75439"
-       rx="20"
-       ry="19.999998"
-       inkscape:export-filename="/home/hortont/seed/examples/lightsoff/bkg.png"
-       inkscape:export-xdpi="47.906658"
-       inkscape:export-ydpi="47.906658" />
+     transform="translate(-60.31257,-681.79066)">
+    <path
+       style="fill:url(#linearGradient2415);fill-opacity:1;stroke:#5d5d5d;stroke-width:1.99999988000000006;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1"
+       d="M 70.1782,682.79066 L 301.56038,682.79066 C 306.47194,682.79066 310.42601,686.65876 310.42601,691.46355 L 310.42601,757.16125 C 310.42601,761.96603 306.47194,765.83414 301.56038,765.83414 L 70.1782,765.83414 C 65.266641,765.83414 61.31257,761.96603 61.31257,757.16125 L 61.31257,691.46355 C 61.31257,686.65876 65.266641,682.79066 70.1782,682.79066 z"
+       id="rect2540" />
   </g>
 </svg>

Modified: trunk/examples/lightsoff/board.js
==============================================================================
--- trunk/examples/lightsoff/board.js	(original)
+++ trunk/examples/lightsoff/board.js	Wed Nov 12 10:45:27 2008
@@ -1,3 +1,59 @@
+var last_direction = 0;
+var last_sign = 0;
+
+function alpha_func(alpha)
+{
+	timeline = alpha.get_timeline();
+	frame = timeline.get_current_frame();
+	n_frames = timeline.num_frames;
+	fps = timeline.fps;
+	duration = n_frames/fps;
+	time = frame/fps;
+
+	if ((time/=duration) < (1/2.75))
+		return Clutter.ALPHA_MAX_ALPHA*(7.5625*time*time);
+	else if (time < (2/2.75))
+		return Clutter.ALPHA_MAX_ALPHA*(7.5625 * (time-=(1.5/2.75))*time+.75);
+	else if (time < (2.5/2.75))
+		return Clutter.ALPHA_MAX_ALPHA*(7.5625 *(time-=(2.25/2.75))*time+.9375);
+	else
+		return Clutter.ALPHA_MAX_ALPHA*(7.5625 * (time-=(2.625/2.75))*time+.984375);
+}
+
+function win_animation()
+{
+	var direction, sign;
+	
+	do
+	{
+		direction = Math.floor(2 * Math.random());
+		sign = Math.floor(2 * Math.random()) ? 1 : -1;
+	}
+	while(last_direction == direction && last_sign != sign);
+	
+	last_direction = direction;
+	last_sign = sign;
+
+	var new_board = new Board();
+	new_board.set_position(sign * direction * board_size, 
+						   sign * (!direction) * board_size);
+	new_board.show();
+	stage.add_actor(new_board);
+	new_board.lower_bottom();
+	
+	var fadeline = new Clutter.Timeline({num_frames:80});
+	var effect = Clutter.EffectTemplate._new(fadeline, alpha_func);
+	
+	Clutter.effect_move(effect, new_board, 0, 0);
+	Clutter.effect_move(effect, board, 
+						-(sign)*(direction * board_size),
+						-(sign)*((!direction) * board_size));
+		
+	fadeline.start();
+	
+	board = new_board;
+}
+
 function check_won (timeline, light)
 {
 	if(light.get_parent().cleared() && !in_setup)
@@ -87,8 +143,8 @@
 				this.lights[x][y] = new Light();
 				this.lights[x][y].light_x = x;
 				this.lights[x][y].light_y = y;
-				this.lights[x][y].set_position(x * tile_size + margin + tile_size/2,
-											   y * tile_size + margin + tile_size/2);
+				this.lights[x][y].set_position(x * (tile_size+margin) + margin + tile_size/2,
+											   y * (tile_size+margin) + margin + tile_size/2);
 				this.add_actor(this.lights[x][y]);
 			}
 		}

Modified: trunk/examples/lightsoff/front.svg
==============================================================================
--- trunk/examples/lightsoff/front.svg	(original)
+++ trunk/examples/lightsoff/front.svg	Wed Nov 12 10:45:27 2008
@@ -9,8 +9,8 @@
    xmlns:xlink="http://www.w3.org/1999/xlink";
    xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd";
    xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape";
-   width="557.08765"
-   height="115.03713"
+   width="250.37199"
+   height="48.383003"
    id="svg3343"
    sodipodi:version="0.32"
    inkscape:version="0.46"
@@ -20,6 +20,16 @@
   <defs
      id="defs3345">
     <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient3169"
+       id="linearGradient2412"
+       gradientUnits="userSpaceOnUse"
+       gradientTransform="translate(112.31402,469.99832)"
+       x1="245.37199"
+       y1="48.383003"
+       x2="245.37199"
+       y2="-5.6843419e-14" />
+    <linearGradient
        id="linearGradient3169">
       <stop
          style="stop-color:#ffffff;stop-opacity:0.024;"
@@ -58,9 +68,9 @@
      objecttolerance="10"
      inkscape:pageopacity="1"
      inkscape:pageshadow="2"
-     inkscape:zoom="2.4035715"
+     inkscape:zoom="1.2017858"
      inkscape:cx="203.23922"
-     inkscape:cy="57.518566"
+     inkscape:cy="51.468405"
      inkscape:document-units="px"
      inkscape:current-layer="layer1"
      showgrid="false"
@@ -90,10 +100,10 @@
      inkscape:label="Layer 1"
      inkscape:groupmode="layer"
      id="layer1"
-     transform="translate(-96.45619,-474.84362)">
+     transform="translate(-112.31402,-469.99832)">
     <path
-       style="opacity:1;fill:url(#linearGradient2534);fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1"
-       d="M 116.28223,474.84362 L 633.71781,474.84362 C 644.70141,474.84362 653.54381,483.60232 653.54381,494.48196 L 653.54381,551.8605 C 600.94401,589.46528 105.72732,609.10031 96.45619,551.8605 L 96.45619,494.48196 C 96.45619,483.60232 105.29861,474.84362 116.28223,474.84362 z"
+       style="fill:url(#linearGradient2412);fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1"
+       d="M 121.22444,469.99832 L 353.77562,469.99832 C 358.71201,469.99832 362.68602,473.74996 362.68602,478.41002 L 362.68602,502.98709 C 339.04606,519.09441 116.48074,527.50468 112.31402,502.98709 L 112.31402,478.41002 C 112.31402,473.74996 116.28808,469.99832 121.22444,469.99832 z"
        id="path2532"
        sodipodi:nodetypes="ccccccc"
        inkscape:export-filename="/home/hortont/seed/examples/lightsoff/bkg_top.png"

Modified: trunk/examples/lightsoff/light.js
==============================================================================
--- trunk/examples/lightsoff/light.js	(original)
+++ trunk/examples/lightsoff/light.js	Wed Nov 12 10:45:27 2008
@@ -1,3 +1,14 @@
+var tile_svg_size = 200;
+
+var on_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size("./tim-on.svg", tile_svg_size, tile_svg_size);
+var off_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size("./tim-off.svg", tile_svg_size, tile_svg_size);
+
+var on_svg = GtkClutter.texture_new_from_pixbuf(on_pixbuf);
+var off_svg = GtkClutter.texture_new_from_pixbuf(off_pixbuf);
+
+on_svg.filter_quality = Clutter.TextureQuality.high;
+off_svg.filter_quality = Clutter.TextureQuality.high;
+
 LightType = {
     parent: Clutter.Group.type,
     name: "Light",
@@ -37,7 +48,10 @@
 											reactive: true});
 		this.off = new Clutter.CloneTexture({parent_texture: off_svg, 
 											 reactive: true});
-							
+		
+		this.on.set_size(tile_size, tile_size);
+		this.off.set_size(tile_size, tile_size);
+		
 		this.on.opacity = 0.0;
 		
 		this.set_anchor_point(tile_size / 2, tile_size / 2);

Modified: trunk/examples/lightsoff/main.js
==============================================================================
--- trunk/examples/lightsoff/main.js	(original)
+++ trunk/examples/lightsoff/main.js	Wed Nov 12 10:45:27 2008
@@ -1,12 +1,16 @@
 #!/usr/bin/env seed
 
-// images are 50x50
-
 var tiles = 5;
 var margin = 5;
 var in_setup = false;
 
+var tile_size = 75;
+var board_size = (tile_size + margin) * tiles + margin;
+
+
 Seed.import_namespace("Clutter");
+Seed.import_namespace("GtkClutter");
+Seed.import_namespace("GdkPixbuf");
 
 Clutter.init(null, null);
 
@@ -14,87 +18,22 @@
 Seed.include("light.js");
 Seed.include("board.js");
 
-var last_direction = 0;
-var last_sign = 0;
-
-function alpha_func(alpha)
-{
-	timeline = alpha.get_timeline();
-	frame = timeline.get_current_frame();
-	n_frames = timeline.num_frames;
-	fps = timeline.fps;
-	duration = n_frames/fps;
-	time = frame/fps;
-
-	if ((time/=duration) < (1/2.75))
-		return Clutter.ALPHA_MAX_ALPHA*(7.5625*time*time);
-	else if (time < (2/2.75))
-		return Clutter.ALPHA_MAX_ALPHA*(7.5625 * (time-=(1.5/2.75))*time+.75);
-	else if (time < (2.5/2.75))
-		return Clutter.ALPHA_MAX_ALPHA*(7.5625 *(time-=(2.25/2.75))*time+.9375);
-	else
-		return Clutter.ALPHA_MAX_ALPHA*(7.5625 * (time-=(2.625/2.75))*time+.984375);
-}
-
-function win_animation()
-{
-	var direction, sign;
-	
-	do
-	{
-		direction = Math.floor(2 * Math.random());
-		sign = Math.floor(2 * Math.random()) ? 1 : -1;
-	}
-	while(last_direction == direction && last_sign != sign);
-	
-	last_direction = direction;
-	last_sign = sign;
-
-	var new_board = new Board();
-	new_board.set_position(sign * direction * board_size, 
-						   sign * (!direction) * board_size);
-	new_board.show();
-	stage.add_actor(new_board);
-	new_board.lower_bottom();
-	
-	var fadeline = new Clutter.Timeline({num_frames:80});
-	var effect = Clutter.EffectTemplate._new(fadeline, alpha_func);
-	
-	Clutter.effect_move(effect, new_board, 0, 0);
-	Clutter.effect_move(effect, board, 
-						-(sign)*(direction * board_size),
-						-(sign)*((!direction) * board_size));
-		
-	fadeline.start();
-	
-	board = new_board;
-}
-
-var on_svg = Clutter.Texture.new_from_file("./tim-on.svg");
-var off_svg = Clutter.Texture.new_from_file("./tim-off.svg");
-
-on_svg.filter_quality = Clutter.TextureQuality.high;
-off_svg.filter_quality = Clutter.TextureQuality.high;
-
-var tile_size = on_svg.width + margin;
-var board_size = tile_size * tiles + margin;
-
 var black = Clutter.Color._new();
 Clutter.color_parse("Black", black);
 
 var stage = new Clutter.Stage({color: black});
 stage.signal.hide.connect(Clutter.main_quit);
-stage.set_size(board_size, board_size + 105);
 
 board = new Board();
 score = new Score();
 rect = new Clutter.Rectangle({color:black});
 
-rect.set_position(0, tile_size*tiles+margin);
+score.set_position((board_size / 2) - (score.width / 2), board_size + margin);
+
+rect.set_position(0, board_size);
 rect.set_size(stage.width, stage.height);
 
-score.set_position(12, tile_size * tiles + 2*margin);
-score.set_scale(0.85,0.85);
+stage.set_size(board_size, board_size + score.height + margin * 3);
 
 stage.add_actor(board);
 stage.add_actor(rect);

Modified: trunk/examples/lightsoff/score.js
==============================================================================
--- trunk/examples/lightsoff/score.js	(original)
+++ trunk/examples/lightsoff/score.js	Wed Nov 12 10:45:27 2008
@@ -9,19 +9,18 @@
     		var max_val = this.value + val;
     		for(var i = this.value; i <= max_val; i += 5)
     		{
-				Seed.setTimeout("score.magic_value("+i+");",5*(i - current_val) + 100);
+				Seed.setTimeout("score.animate_value("+i+");",5*(i - current_val) + 100);
 			}
     	}
     	
-    	prototype.magic_value = function (val)
+    	prototype.animate_value = function (val)
 		{
 			this.value = val;
 			
 			var old_set = this.current_set;
 			
 			this.current_set = new Clutter.Group();
-			//this.current_set.opacity = 0;
-			
+
 			var val_s = Seed.sprintf("% 5d",val);
 		
 			for(var i = 0; i < val_s.length; i++)
@@ -32,54 +31,15 @@
 					texture = null;
 			
 				var num = new Clutter.CloneTexture({parent_texture:texture});
-				num.set_position(56*i-10,3);
-				num.set_size(97,97);
+				num.set_position(this.num_offset * i - 3,5);
+				num.set_size(this.num_size,this.num_size);
 				this.current_set.add_actor(num);
 			}
 			
 			this.add_actor(this.current_set);
-			old_set.destroy();
-			this.bkg_top.raise_top();
-		}
-    	
-		prototype.set_value = function (val)
-		{
-			this.value = val;
-			
-			var old_set = this.current_set;
-			
-			this.current_set = new Clutter.Group();
-			this.current_set.opacity = 0;
-			
-			var val_s = Seed.sprintf("% 5d",val);
-		
-			for(var i = 0; i < val_s.length; i++)
-			{
-				var texture = this.num_textures[val_s[i]];
-		
-				if(val_s[i] == ' ')
-					texture = null;
 			
-				var num = new Clutter.CloneTexture({parent_texture:texture});
-				num.set_position(56*i-10,3);
-				num.set_size(97,97);
-				this.current_set.add_actor(num);
-			}
-			
-			this.add_actor(this.current_set);
-
-			var fadeline = new Clutter.Timeline({num_frames:60});
-			var effect = Clutter.EffectTemplate._new(fadeline, Clutter.sine_inc_func);
-			Clutter.effect_fade(effect, this.current_set, 255);
-
 			if(old_set)
-			{
-				var deleteline = Clutter.effect_fade(effect, old_set, 0);
-				//Clutter.effect_scale(effect, old_set, 2, 2);
-				
-			}
-			
-			fadeline.start();
+				old_set.destroy();
 			
 			this.bkg_top.raise_top();
 		}
@@ -96,16 +56,17 @@
 		bkg.filter_quality = Clutter.TextureQuality.high;
 		off_svg.filter_quality = Clutter.TextureQuality.high;
 		
-		bkg.set_scale(.53,.53);
-		this.bkg_top.set_scale(.535,.535);
+		this.num_margin = 10;
+		this.num_size = bkg.height * 0.9;
+		this.num_offset = (bkg.width - 2*this.num_margin) / 5;
 		
 		this.add_actor(bkg);
 		
 		for(var i = 0; i < 5; i++)
 		{
 			var off_i = new Clutter.CloneTexture({parent_texture:off_svg});
-			off_i.set_position(56*i-10,3);
-			off_i.set_size(97,97);
+			off_i.set_position(this.num_offset * i - 3,5);
+			off_i.set_size(this.num_size,this.num_size);
 			this.add_actor(off_i);
 		}
 		
@@ -117,11 +78,10 @@
 			this.num_textures[i].filter_quality = Clutter.TextureQuality.high;
 		}
 		
-		this.bkg_top.opacity = 200;
-		this.bkg_top.set_position(1,1);
+		this.bkg_top.set_position(1, 1);
 		this.add_actor(this.bkg_top);
 		
-		this.set_value(0);
+		this.animate_value(0);
     }};
 
 Score = new GType(ScoreType);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]