simple snowflake = 6 sided symmetry

ben dalton is bcd@media.mit.edu

mycetozoa

snowflakes made by pointing a camera at interesting things. code written in proce55ing 074, making use of its video handling. symmetry inspired by the snowflake photography of wilson bentley and the initial six-fold symmetry of the crystal structure of ice.

cross asteridea asteridea clockface ibook owncode thingsthatgo

here is the code:

01 // snowflake - 6 sided symmetry
02 // ben <http:/www.media.mit.edu/~bcd>
03 // Created 17 January 2005
04 
05 import processing.video.*;
06 
07 int cameraSide = 500;
08 float thirdPi=PI/3;
09 float sixthPi=PI/6;
10 float xpt, ypt;
11 int halfWidth, halfHeight;
12 float angle, radius, x, y;
13 int pixelMap[] null;
14 
15 Camera camera;
16 //Movie camera;
17 
18 void setup()
19 {
20   size( (int) (cameraSide*1.2), cameraSide );
21   camera = new Camera(this, cameraSide, cameraSide, 24);
22   //camera = new Movie(this, "ben.mov");
23   //camera.repeat();
24   
25   halfWidth = width / 2;
26   halfHeight = height / 2;
27   pixelMap = new int[width*height];
28   
29   System.out.println("snow *");
30     
31   for(int j=0; j<height; j=j+1) {
32     //shift to centered coordinates and flip
33     xpt= halfHeight-j;
34     for(int i=0; i<width; i=i+1) {
35       //shift to centered coordinates and flip
36       ypt= halfWidth-i;
37       
38       //find the angle by computing an arc tangent of x/y in the range of -pi to pi.
39       angle= (floatMath.atan2(xpt, ypt);
40       radius= (floatMath.sqrt(ypt*ypt+xpt*xpt);
41       
42       angle += PI;  //shift range 0 to pi
43       angle %= thirdPi;  //bring round to one pi/3 (60 degree) sector
44       angle -= sixthPi;  //centre around zero
45       angle= (floatMath.abs(angle);  //flip negative to positive
46       
47       //get pixel source x y coordinates & switch back to top left origin
48       x=(float) (halfWidth-radius*Math.sin(angle));
49       y=(float) (halfHeight-radius*Math.cos(angle));
50       
51       //test if out of video frame
52       if (x < || y < 0){ 
53         pixelMapj*width+i 0;
54       }else
55         pixelMapj*width+i (int) (Math.round(y)*cameraSide + Math.round(x));
56       }
57     }
58   }
59 }
60 
61 //loop when creating flakes from video
62 void draw()
63 {
64   if (camera.available()) {
65     camera.read();
66     for(int i=0; i<width*height; i=i+1) {
67       pixels= camera.pixelspixelMap] ];
68     }
69   }
70 }