Skip to content
Ecce Signum

Ecce Signum

Immanentize the Empathy

  • Home
  • About Me
  • Published Works and Literary Matters
  • Laboratory

Flash Stuff Here. Move Along…

2004-04-05 John Winkelman

In the middle of a cool project which is right on the cusp of being designered into oblivion, I discovered a nifty way to make things “snap to” a grid. Copy-and-paste into Flash MX/MX2004.

var gridSize = 20; // size of grid
 var nodeSize = 20; // size of individual nodes
 var nodes = 50; // number of nodes
 var radius = Stage.height/3; // radius of drawn circle
 var centerX = Stage.width/2; // center horizontally
 var centerY = Stage.height/2; // center vertically
 var steps = (Math.PI*2) / nodes; // math stuff
 var i=0;
 this.onEnterFrame = function() {
 if(i < nodes) {
 var m = _root.createEmptyMovieClip("node"+i,i);
 m.lineStyle(0,0x000000,100);
 m.beginFill(0x000000,10);
 m.moveTo(0,0);
 m.lineTo(nodeSize,0);
 m.lineTo(nodeSize,nodeSize);
 m.lineTo(0,nodeSize); m.lineTo(0,0);
 m.endFill();
 var mx = centerX + radius*Math.cos(steps*i); // horizontal snap
 if(mx%gridSize != 0) mx += (Math.floor(gridSize/2) - (mx%gridSize));
 var my = centerY + radius*Math.sin(steps*i); // vetical snap
 if(my%gridSize != 0) my += (Math.floor(gridSize/2) - (my%gridSize));
 m._x = mx;
 m._y = my;
 i++;
 radius += .1;
 } else {
 this.onEnterFrame = null;
 }
 }

It’s the modulus (mx % gridSize) which makes it cool. The Math.floor() which follows could also easily be Math.round() or Math.ceil(), depending on the constraints of the project.

Posted in ProgrammingTagged Flash

Post navigation

People Who Spammed Me This Week
njil9uects

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Personal website of
John Winkelman

John Winkelman in a diner in San Francisco

Archives

Categories

Posts By Month

April 2004
S M T W T F S
 123
45678910
11121314151617
18192021222324
252627282930  
« Mar   May »

Twitter Feed

JohnWinkelmanJohn Winkelman@JohnWinkelman·
15 Apr

4 of 5 stars to The Making of the Indebted Man by Maurizio Lazzarato https://www.goodreads.com/review/show?id=3934132499

Reply on Twitter 1382837596775137282Retweet on Twitter 1382837596775137282Like on Twitter 1382837596775137282Twitter 1382837596775137282
JohnWinkelmanJohn Winkelman@JohnWinkelman·
15 Apr

I just backed European Astrobiology Institute presents "Life Beyond Us" on @Kickstarter https://www.kickstarter.com/projects/laksamedia/european-astrobiology-institute-presents-life-beyond-us?ref=android_thanks_twitter_share

Reply on Twitter 1382512100136906753Retweet on Twitter 1382512100136906753Like on Twitter 13825121001369067532Twitter 1382512100136906753
JohnWinkelmanJohn Winkelman@JohnWinkelman·
9 Apr

Yeah, that would have been a totally different movie.

Alex de Campi@alexdecampi

Clockwork Orange, hat test, 1971

Reply on Twitter 1380494051548487681Retweet on Twitter 1380494051548487681Like on Twitter 1380494051548487681Twitter 1380494051548487681
Load More...

Links of Note

Reading, Writing
Tor.com
Locus Online
The Believer
File 770
IWSG

Watching, Listening
WYCE Electric Poetry
Writing Excuses Podcast
Our Opinions Are Correct

News, Politics, Economics
Naked Capitalism
Crooked Timber

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

© 2021 Ecce Signum

Proudly powered by WordPress | Theme: x-blog by wpthemespace.com