Team:OUC-China

From 2013.igem.org

(Difference between revisions)
Line 1: Line 1:
-
<!-- *** What falls between these lines is the Alert Box!  You can remove it from your pages once you have read and understood the alert *** -->
 
-
 
<html>
<html>
-
<div id="box" style="width: 700px; margin-left: 137px; padding: 5px; border: 3px solid #000; background-color: #fe2b33;">
+
<style>
-
<div id="template" style="text-align: center; font-weight: bold; font-size: large; color: #f6f6f6; padding: 5px;">
+
html, body {
-
This is a template page. READ THESE INSTRUCTIONS.
+
width: 100%; height: 100%;
-
</div>
+
background: #333;
-
<div id="instructions" style="text-align: center; font-weight: normal; font-size: small; color: #f6f6f6; padding: 5px;">
+
}
-
You are provided with this team page template with which to start the iGEM season.  You may choose to personalize it to fit your team but keep the same "look." Or you may choose to take your team wiki to a different level and design your own wiki.  You can find some examples <a href="https://2009.igem.org/Help:Template/Examples">HERE</a>.
+
-
</div>
+
-
<div id="warning" style="text-align: center; font-weight: bold; font-size: small; color: #f6f6f6; padding: 5px;">
+
-
You <strong>MUST</strong> have all of the pages listed in the menu below with the names specified. PLEASE keep all of your pages within your teams namespace. 
+
-
</div>
+
-
</div>
+
-
</html>
+
-
<!-- *** End of the alert box *** -->
+
canvas {
 +
display: block;
 +
}
 +
</style>
 +
<body>
 +
<canvas></canvas>
 +
<script>
 +
(function() {
-
 
+
// rAF
-
 
+
window.requestAnimationFrame = function() {
-
{|align="justify"
+
return window.requestAnimationFrame ||
-
|You can write a background of your team here.  Give us a background of your team, the members, etc.  Or tell us more about something of your choosing.
+
window.webkitRequestAnimationFrame ||
-
|[[Image:OUC-China_logo.png|200px|right|frame]]
+
window.mozRequestAnimationFrame ||
-
|-
+
window.msRequestAnimationFrame ||
-
|
+
window.oRequestAnimationFrame ||
-
''Tell us more about your project. Give us background.  Use this as the abstract of your project.  Be descriptive but concise (1-2 paragraphs)''
+
function(f) {
-
|[[Image:OUC-China_team.png|right|frame|Your team picture]]
+
window.setTimeout(f,1e3/60);
-
|-
+
}
-
|
+
}();
-
|align="center"|[[Team:OUC-China | Team OUC-China]]
+
-
|}
+
var canvas = document.querySelector('canvas');
-
 
+
var ctx = canvas.getContext('2d');
-
<!--- The Mission, Experiments --->
+
-
 
+
var W = canvas.width = window.innerWidth;
-
{| style="color:#1b2c8a;background-color:#0c6;" cellpadding="3" cellspacing="1" border="1" bordercolor="#fff" width="62%" align="center"
+
var H = canvas.height = window.innerHeight;
-
!align="center"|[[Team:OUC-China|Home]]
+
-
!align="center"|[[Team:OUC-China/Team|Team]]
+
// Our SpaceShip Constructor
-
!align="center"|[https://igem.org/Team.cgi?year=2013&team_name=OUC-China Official Team Profile]
+
var SpaceShip = function() {
-
!align="center"|[[Team:OUC-China/Project|Project]]
+
-
!align="center"|[[Team:OUC-China/Parts|Parts Submitted to the Registry]]
+
// x/y positions
-
!align="center"|[[Team:OUC-China/Modeling|Modeling]]
+
this.x = 200;
-
!align="center"|[[Team:OUC-China/Notebook|Notebook]]
+
this.y = 100;
-
!align="center"|[[Team:OUC-China/Safety|Safety]]
+
-
!align="center"|[[Team:OUC-China/Attributions|Attributions]]
+
this.radius = 40;
-
|}
+
 +
// How many wings/blades or whatever you want to call it
 +
this.wing_count = 3;
 +
// Math.PI*2 === 360 degrees
 +
// 360 / 3 = 120 degrees
 +
// So every 120 degrees will have 1 hand/blade
 +
// of 60 degrees (half of 120)
 +
this.steps = Math.PI*2 / this.wing_count;
 +
 +
this.color = 'hsl(0,100%,50%)';
 +
// We can try changing color after EVERY rotation
 +
// would be cool!
 +
this.hue = 0; // initial hue
 +
// This is the target hue we'll reach
 +
// during (at start) the first rotation
 +
this.hue_target = parseInt( Math.random()*360 );
 +
 +
// Lets mess with the angle now
 +
this.angle = 0;
 +
// Manipulating speed - seems good!
 +
this.rotation_speed = 0.06;
 +
 +
this.draw = function(ctx) {
 +
 +
// But we want to do this after every rotation
 +
if (this.angle > Math.PI*2) {
 +
// Kind of reset the angle when its more
 +
// than 360 degrees.
 +
this.angle -= Math.PI*2;
 +
 +
// Choose a random hue target now
 +
this.hue_target = parseInt( Math.random()*360 );
 +
 +
// ... and we made it :)
 +
}
 +
 +
// You notice initially there's a color change ?
 +
// Why this (hue_target - hue) * random_numer ?
 +
// Well, we basically measure the distance that we
 +
// have to travel, from initial to target and multiple
 +
// that by an "easing" factor.
 +
// This causes "easing" effect when changing from initial
 +
// to target color, i.e., it starts with high speed
 +
// and as it progresses, the spead decreases until
 +
// it reaches the target.
 +
// We just learnt how to implement Easing in html5 canvas!
 +
this.hue += (this.hue_target - this.hue) * 0.05;
 +
this.color = 'hsl(' + this.hue + ',100%,50%)';
 +
 +
ctx.strokeStyle = this.color;
 +
// Setting a line width
 +
ctx.lineWidth = 15;
 +
 +
// Time to rotate this thing
 +
// Since ctx.rotate() will rotate the entire 2D context
 +
// and not just the arc's, we'll have to save
 +
// our current drawing state into the stack.
 +
ctx.save();
 +
 +
// as you can see entire context was rotated
 +
// we'll fix this by first translating
 +
// The x/y values that we pass to translate()
 +
// is the same as the ones we passed to ctx.arc below
 +
ctx.translate(this.x, this.y);
 +
 +
// The entire thing became a circle :P
 +
// cuz we never cleared after each rendering of frame
 +
this.angle += this.rotation_speed;
 +
ctx.rotate(this.angle);
 +
 +
for (var i = 0; i < this.wing_count; i++) {
 +
ctx.beginPath();
 +
 +
// For arc, the new x/y pos will be 0,0
 +
ctx.arc(
 +
0,
 +
0,
 +
this.radius,
 +
i*this.steps,
 +
i*this.steps + this.steps/2,
 +
false
 +
);
 +
 +
ctx.stroke();
 +
ctx.closePath();
 +
}
 +
 +
// ... and restore here
 +
ctx.restore();
 +
 +
// A rounded body in the center
 +
ctx.beginPath();
 +
ctx.fillStyle = 'black';
 +
ctx.arc(this.x, this.y, 20, 0, Math.PI*2, false);
 +
ctx.fill();
 +
ctx.closePath();
 +
 +
};
 +
};
 +
 +
// Create a spaceship object
 +
var ship = new SpaceShip();
 +
// Setting proper x/y to center it
 +
ship.x = W/2;
 +
ship.y = H/2;
 +
 +
(function renderFrame() {
 +
window.requestAnimationFrame(renderFrame);
 +
 +
// Magik! We dont need so much speed though...
 +
ctx.clearRect(0,0,W,H);
 +
 +
ship.draw(ctx);
 +
}());
 +
}());
 +
</script>
 +
</body>
 +
<html>

Revision as of 16:00, 27 July 2013