# Monthly Archives: May 2010

## Epicycloid Again

Actionscript:
1. var xp:Number = 0;
2. var yp:Number = 0;
3. var t:Number = 0;
4. var a:Number = 100;
5. var b:Number = 10;
6. x = stage.stageWidth / 2;
7. y = stage.stageHeight / 2;
8.
9. graphics.lineStyle(0,0x000000);
11. function onRun(evt:Event):void {
12.     var p:Number = ((a + b)/b)*t
13.     xp = (a + b) * Math.cos(t) - b * Math.cos(p);
14.     yp = (a + b) * Math.sin(t) - b * Math.sin(p);
15.     if (t == 0){
16.       graphics.moveTo(xp, yp);
17.     }else{
18.       graphics.lineTo(xp, yp);
19.     }
20.     t += 0.05;
21. }

I've messed with Epicycloids in the past - browsing mathworld I decided to create this snippet. It will draw a curve like this:

Posted in Uncategorized | Tagged , , | 1 Comment

## Fish Curve

Actionscript:
1. var xp:Number = 0;
2. var yp:Number = 0;
3. var t:Number = 0;
4. var a:Number = 200;
5. x = stage.stageWidth / 2;
6. y = stage.stageHeight / 2;
7.
8. graphics.lineStyle(0,0x000000);
10. function onRun(evt:Event):void {
11.     xp = a * Math.cos(t) - (a * Math.pow(Math.sin(t),2))/Math.sqrt(2);
12.     yp = a * Math.cos(t) * Math.sin(t);
13.     if (t == 0){
14.       graphics.moveTo(xp, yp);
15.     }else{
16.       graphics.lineTo(xp, yp);
17.     }
18.     t += 0.05;
19. }

While surfing mathworld I stumbled upon the equation for something called the Fish Curve. This snippet will draw something like this:

## Astroid Pedal Curve Variation

Actionscript:
1. var xp:Number = 0;
2. var yp:Number = 0;
3. var t:Number = 0;
4. var r:Number = 200;
5. x = stage.stageWidth / 2;
6. y = stage.stageHeight / 2;
7.
8. graphics.lineStyle(0,0x000000);
10. function onRun(evt:Event):void {
11.     r = 200 * Math.cos(t / 10);
12.     xp = r * Math.pow(Math.cos(t), 3);
13.     yp = r * Math.pow(Math.sin(t), 3);
14.     if (t == 0){
15.       graphics.moveTo(xp, yp);
16.     }else{
17.       graphics.lineTo(xp, yp);
18.     }
19.     t += 0.1;
20. }

While browsing mathworld I decided to do a variation on this curve . The above snippet will draw something like this:

## Color Project

I've been working on a project for the led facade at medialab prado. The project has an online component that allows users to name colors, these names are then searched on twitter and displayed on the led facade. Right now our color database has about 530 colors about 20% of which are in spanish. We're lookiing to get more colors named particularly in spanish. If you feel up to it, you can enter and name colors, simply pick a color, enter your name and name the color... here for spanish
and here for english.

If you did it correctly you'll see your color show up in our list of colors here

Posted in Uncategorized | 1 Comment

## 3D Ring

Actionscript:
1. [SWF(width = 500, height=500)]
2. var ring:MovieClip = createRing();
3. ring.x = stage.stageWidth / 2;
4. ring.y = stage.stageHeight / 2;
6.
7. function createRing(sectionNum:int = 30):MovieClip{
8.     var container:MovieClip = new MovieClip();
9.     container.circles = [];
10.     container.theta = 0;
12.     var step:Number = (Math.PI * 2) / sectionNum;
13.     for (var i:int = 0; i<sectionNum; i++){
14.         var c:MovieClip = new MovieClip();
15.         with (c.graphics){
16.             lineStyle(0,0x000000);
17.             beginFill(0xCCCCCC);
18.             drawCircle(0,0,20);
19.         }
20.         c.thetaOffset = step * i;
22.         container.circles.push(c);
23.     }
25.     return container;
26. }
27. function onRun(evt:Event):void {
28.     var container:MovieClip = MovieClip(evt.currentTarget);
29.     var num:int = container.circles.length;
30.     for (var i:int = 0; i<num; i++){
31.         var c:MovieClip = container.circles[i];
32.         var angle:Number = container.theta + c.thetaOffset;
33.         c.x = 200 * Math.cos(angle);
34.         c.y = 100 * Math.sin(angle);
35.         c.scaleX = (100 + c.y) / 120 + 0.2;
36.         c.scaleY = c.scaleX;
37.     }
38.     container.circles.sortOn("y", Array.NUMERIC);
39.     for (i = 0; i<num; i++){
41.     }
42.     if (container.mouseX <-100){
44.     }
45.     if (container.mouseX> 100){
47.     }
48.     container.theta += (container.thetaDest  - container.theta) / 12;
49.
50. }

This snippet shows how to create a 3D ring navigation using sine and cosine. Have a look:

Posted in 3D, Graphics, MovieClip, UI, arrays, motion, sortOn | Tagged , , | 3 Comments

## Propeller Sketch

Actionscript:
1. makeFlyer();
2.
3. function makeFlyer():void{
4.     var thing:MovieClip = new MovieClip();
5.     thing.x = 200;
6.     thing.y = 200;
7.
9.
10.     var prop:Shape = new Shape();
11.     with (prop.graphics){
12.         lineStyle(0,0x000000);
13.         beginFill(0x000000);
14.         moveTo(-100,0);
15.         curveTo(-100, -30, 0, 0);
16.         curveTo(100, 30, 100, 0);
17.         curveTo(100, -30, 0, 0);
18.         curveTo(-100, 30, -100, 0);
19.     }
20.     prop.scaleX = prop.scaleY = 0.5;
21.     var container:MovieClip = new MovieClip();
22.     //container.x = -50;
24.     container.scaleY = 0.6;
26.
27.     var body:Shape = new Shape();
28.     with (body.graphics){
29.         lineStyle(0, 0x000000);
30.         beginFill(0x000000);
31.         lineTo(0,80);
32.         drawCircle(0,80,10);
33.     }
35.     thing.velX = 0;
36.     thing.velY = 0;
37.     thing.posX = thing.x;
38.     thing.posY = thing.y;
39.     thing.theta = 0;
40.     thing.prop = prop;
42. }
43. function onRun(evt:Event):void{
44.     var t:MovieClip = MovieClip(evt.currentTarget);
45.     t.prop.rotation += 10
46.     t.velY = 3 * Math.cos(t.theta);
47.     t.velX = 3 * Math.sin(t.theta / 2);
48.     t.theta += 0.05
49.     t.posX += t.velX;
50.     t.posY += t.velY;
51.
52.     t.x = t.posX;
53.     t.y = t.posY;
54. }

This snippet creates a small flying object that moves with sine and cosine.

Have a look at the swf...

Posted in motion | Tagged , , | 2 Comments