|
Author |
Topic: snowflake + merry christmas (Read 1797 times) |
|
mr.prufrock
|
snowflake + merry christmas
« on: Dec 18th, 2002, 7:15pm » |
|
I made some fake snowflakes... have a happy christmas people! http://www.metaphorical.net/christmas/
|
I grow old...I grow old I shall wear the bottoms of my trousers rolled.
|
|
|
rlivings
|
Re: snowflake + merry christmas
« Reply #1 on: Dec 18th, 2002, 7:39pm » |
|
hmm, I can't seem to get it to work.
|
|
|
|
REAS
|
Re: snowflake + merry christmas
« Reply #2 on: Dec 18th, 2002, 8:12pm » |
|
it works for me. have you tried again to make it work? very elegant, mr prufrock.
|
|
|
|
gaza
|
Re: snowflake + merry christmas
« Reply #3 on: Dec 18th, 2002, 11:01pm » |
|
NICE!!!
|
|
|
|
michael
|
Re: snowflake + merry christmas
« Reply #4 on: Dec 19th, 2002, 7:13am » |
|
doesn't work for me. i get the following message in ie6, winXP: load, snowflake can't be instantiated.
|
In the beginning, the universe was created. This made a lot of people very angry, and has been widely regarded as a bad idea.
-- Douglas Adams in The Hitchhiker's Guide to the Universe.
|
|
|
mr.prufrock
|
Re: snowflake + merry christmas
« Reply #5 on: Dec 20th, 2002, 8:51am » |
|
It doesn't work?... O woe! Life is futile! I don't know why -- I'm using ie6 on XP too, and it seems to work fine. A suggestion: If I am not mistaken, microsoft is doing something evil to Java. Try get the Java VM for XP from java.sun.com. Anyway, here's the proce55ing code; it should work inside proce55ing environment(0046): //----------------- // fake snowflake by william // proce55ing source code. final int NUM = 16; SnowFlake[] snow = new SnowFlake[NUM]; void setup() { size( 400, 400 ); background( 255 ); stroke(125, 175, 255); for (int i=0; i<NUM; i++) { float x = 55f+60f*(int)(i%4)+35f*(int)(i%4); float y = 55f+ 60f*(int)(i/4f)+35f*(int)(i/4); snow[i] = new SnowFlake( x, y, 0, 30 ); } } void loop() { rect( 0,0, 399, 399 ); for (int i=0; i<NUM; i++) { snow[i].draw(); } } void mouseMoved() { for (int i=0; i<NUM; i++) { snow[i].transform(); } } void mousePressed() { for (int i=0; i<NUM; i++) { snow[i].renew(); } } float[] midPt(float x1, float y1, float x2, float y2 ) { float[] pt = { x1-(x1-x2)/2, y1/2+y2/2 }; return pt; } float[] findPt( float x, float y, float a, float r ) { float[] pt = { x+( cos(a)*r ), y+( sin(a)*r) }; return pt; } //- - - SnowFlake class class SnowFlake { SnowElement[] snow = new SnowElement[6]; SnowFlake( float x, float y, float a, float r) { snow[0] = new SnowElement( x, y, a, r); snow[1] = snow[0].copy(); snow[1].setAngle( PI/3 ); snow[2] = snow[0].copy(); snow[2].setAngle( 2*PI/3 ); snow[3] = snow[0].copy(); snow[3].setAngle( PI ); snow[4] = snow[0].copy(); snow[4].setAngle( 4*PI/3 ); snow[5] = snow[0].copy(); snow[5].setAngle( 5*PI/3 ); } void draw() { for (int i=0; i<snow.length; i++) { snow[i].draw(); } } void transform() { for (int i=0; i<snow.length; i++) { snow[i].transform(); } } void renew() { for (int i=0; i<snow.length; i++) { snow[i].init(); } } } //- - - - SnowElement CLASS class SnowElement { int sMax = 10; float[][] form = new float[sMax][4]; float[][] pos = new float[sMax][2]; float angle, radius; float x1, y1, x2, y2; float gap = 0.07; SnowElement ( float x, float y, float a, float r ) { x1 = x; y1 = y; angle = a; radius = r; init(); update(); } // METHOD: init void init() { int count= 0; gap = sMax/radius; for (int i=0; i<radius; i++) { if (count < sMax && random(1) <gap) { form[count][0] = i; //x form[count][1] = random(0.5) + 0.4; //a form[count][2] = (random(radius/2)+radius/2)/(count/2+1); //r form[count][3] = 0; //r inc count++; } } } // METHOD: clone SnowElement copy() { SnowElement sf = new SnowElement( x1, y1, angle, radius ); sf.form = form; sf.pos = pos; return sf; } // METHOD: update position void update() { float[] p = findPt( x1, y1, angle, radius ); x2 = p[0]; y2 = p[1]; for (int i=0; i<form.length; i++) { pos[i] = findPt( x1, y1, angle, form[i][0] ); } } // METHOD: find flakes' 'tip' position float[] flake( int num, boolean mirror ) { if (num < pos.length) { if (form[num][3]<form[num][2]) form[num][3]+=0.05; float[] p = (mirror) ? findPt( pos[num][0], pos[num][1], form[num][1]+angle, form[num][3] ) : findPt( pos[num][0], pos[num][1], form[num][1]*-1+angle, form[num][3] ); return p; } return null; } // METHOD: transform shape void transform() { for (int i=0; i<sMax; i++) { if (form[i][3]>=form[i][2]) { form[i][1] = form[i][1] + random(form[i][2])/(radius*100) - random(0.01); } } } // METHOD: draw a snow flake. void draw() { update(); // important beginShape(LINE_LOOP); // --> curveVertex( x1, y1 ); curveVertex( pos[0][0], pos[0][1] ); //original for (int i=0; i<pos.length; i++) { float[] tip = flake( i, false ); if (i>0) { float[] mid = midPt( pos[i-1][0], pos[i-1][1], pos[i][0], pos[i][1] ); curveVertex( mid[0], mid[1] ); } else { curveVertex( tip[0], tip[1] ); } curveVertex( tip[0], tip[1] ); } float[] end = midPt( pos[pos.length-1][0], pos[pos.length-1][1], x2, y2 ); curveVertex( pos[pos.length-1][0], pos[pos.length-1][1] ); //mirror for (int i=pos.length-1; i>=0; i--) { float[] tip2 = flake( i, true ); curveVertex( tip2[0], tip2[1] ); if (i>0) { float[] mid = midPt( pos[i-1][0], pos[i-1][1], pos[i][0], pos[i][1] ); curveVertex( mid[0], mid[1] ); } else { curveVertex( tip2[0], tip2[1] ); } } curveVertex( pos[0][0], pos[0][1] ); curveVertex( x1, y1 ); // <-- endShape(); //stroke(255, 0, 0); //line( x1, y1, x2, y2 ); } // METHOD: set angle void setAngle( float a ) { angle = a; } }
|
I grow old...I grow old I shall wear the bottoms of my trousers rolled.
|
|
|
rlivings
|
Re: snowflake + merry christmas
« Reply #6 on: Dec 21st, 2002, 2:04am » |
|
that did it mr.prufrock. Looks marvelous!
|
|
|
|
|