BIT-101 [2003-2017]

Polar Distortion with Flash 10 drawTriangles


I was playing around with some of the new drawing API features for the new book and realized I could redo the Polar distortion class I did a while back.

https://www.bit-101.com/2003/1167
https://www.bit-101.com/2003/1187
https://www.bit-101.com/2003/1194

It was amazingly easy:

And it’s fast! Check it out. This will open full browser, which will slow it down, so you might want to download it and open it in the flash player, or resize your browser.

polar10

Here’s the crappy experimental timeline code, which will only do you any good if you happen to have a copy of Flash CS4 to hand, which not many of you do. But you could probably massage it into a class without too much effort, and compile with the Flex 4 SDK.

[as][SWF(width=800, height=800)]

var pan:BitmapData = new pano(0, 0);

var vertices:Vector. = new Vector.();
var indices:Vector. = new Vector.();
var uv:Vector. = new Vector.();
//graphics.lineStyle(0);

var res:Number = 200;
var inner:Number = 20;
var outer:Number = 300;
for(var i:int = 0; i < res + 1; i++) { var angle:Number = Math.PI * 2 / res * i; vertices.push(400 + Math.cos(angle) * inner); vertices.push(400 + Math.sin(angle) * inner); uv.push(i / res, 1); // graphics.drawCircle(vertices[vertices.length - 2], vertices[vertices.length - 1], 2); vertices.push(400 + Math.cos(angle) * outer); vertices.push(400 + Math.sin(angle) * outer); uv.push(i / res, 0); // graphics.drawCircle(vertices[vertices.length - 2], vertices[vertices.length - 1], 2); } for(i = 0; i < res * 2; i += 2) { indices.push(i, i + 1, i + 2); indices.push(i + 1, i + 3, i + 2); } var a1:Number = 0; var a2:Number = 0; addEventListener(Event.ENTER_FRAME, tick); function tick(event:Event):void { inner = Math.cos(a1 += .1) * 80 + 100; outer = Math.sin(a2 += .07) * 80 + 300; var n:int = 0; for(var i:int = 0; i < res + 1; i++) { var angle:Number = Math.PI * 2 / res * i; vertices[n++] = 400 + Math.cos(angle) * inner; vertices[n++] = 400 + Math.sin(angle) * inner; vertices[n++] = 400 + Math.cos(angle) * outer; vertices[n++] = 400 + Math.sin(angle) * outer; } graphics.clear(); graphics.beginBitmapFill(pan); graphics.drawTriangles(vertices, indices, uv); }[/as]

« Previous Post
Next Post »