Skip to content

Commit 7c48fd1

Browse files
committed
Merge pull request #4 from lew-code/p_2_2_4
added P_2_2_4_01 to 02 sketches
2 parents ebeddd7 + fd487b2 commit 7c48fd1

File tree

6 files changed

+231
-0
lines changed

6 files changed

+231
-0
lines changed

01_P/P_2_2_4_01/P_2_2_4_01.png

27.3 KB
Loading

01_P/P_2_2_4_01/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title></title>
6+
<script src="../../libraries/p5/p5.js" type="text/javascript"></script>
7+
8+
<script src="../../libraries/p5/p5.dom.js" type="text/javascript"></script>
9+
<script src="../../libraries/generative-design-library/generative-design-library.js" type="text/javascript"></script>
10+
11+
<script src="sketch.js" type="text/javascript"></script>
12+
13+
<style> body {padding: 0; margin: 0;} canvas {vertical-align: top;} </style>
14+
</head>
15+
<body>
16+
</body>
17+
</html>

01_P/P_2_2_4_01/sketch.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// P_2_2_4_01.pde
2+
//
3+
// Generative Gestaltung, ISBN: 978-3-87439-759-9
4+
// First Edition, Hermann Schmidt, Mainz, 2009
5+
// Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
6+
// Copyright 2009 Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
7+
//
8+
// http://www.generative-gestaltung.de
9+
//
10+
// Licensed under the Apache License, Version 2.0 (the "License");
11+
// you may not use this file except in compliance with the License.
12+
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
19+
/**
20+
* limited diffusion aggregation
21+
*
22+
* KEYS
23+
* s : save png
24+
*/
25+
26+
var maxCount = 5000; //max count of the cirlces
27+
var currentCount = 1;
28+
var x = [maxCount];
29+
var y = [maxCount];
30+
var r = [maxCount]; // radius
31+
32+
function setup() {
33+
createCanvas(600,600);
34+
smooth();
35+
//frameRate(10);
36+
37+
// first circle
38+
x[0] = width/2;
39+
y[0] = height/2;
40+
r[0] = 10;
41+
//r[0] = 400;
42+
}
43+
44+
45+
function draw() {
46+
background(255);
47+
48+
strokeWeight(0.5);
49+
//noFill();
50+
51+
// create a radom set of parameters
52+
var newR = random(1, 7);
53+
var newX = random(0+newR, width-newR);
54+
var newY = random(0+newR, height-newR);
55+
56+
var closestDist = 100000000;
57+
var closestIndex = 0;
58+
// which circle is the closest?
59+
for(var i=0; i < currentCount; i++) {
60+
var newDist = dist(newX,newY, x[i],y[i]);
61+
if (newDist < closestDist) {
62+
closestDist = newDist;
63+
closestIndex = i;
64+
}
65+
}
66+
67+
// show random position and line
68+
// fill(230);
69+
// ellipse(newX,newY,newR*2,newR*2);
70+
// line(newX,newY,x[closestIndex],y[closestIndex]);
71+
72+
// aline it to the closest circle outline
73+
var angle = atan2(newY-y[closestIndex], newX-x[closestIndex]);
74+
75+
x[currentCount] = x[closestIndex] + cos(angle) * (r[closestIndex]+newR);
76+
y[currentCount] = y[closestIndex] + sin(angle) * (r[closestIndex]+newR);
77+
r[currentCount] = newR;
78+
currentCount++;
79+
80+
// draw them
81+
for (var i=0 ; i < currentCount; i++) {
82+
//fill(50,150);
83+
fill(50);
84+
ellipse(x[i],y[i], r[i]*2,r[i]*2);
85+
}
86+
87+
if (currentCount >= maxCount) noLoop();
88+
}
89+
90+
function keyReleased() {
91+
if (key == 's' || key == 'S') saveCanvas(gd.timestamp(), 'png');
92+
}

01_P/P_2_2_4_02/P_2_2_4_02.png

217 KB
Loading

01_P/P_2_2_4_02/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title></title>
6+
<script src="../../libraries/p5/p5.js" type="text/javascript"></script>
7+
8+
<script src="../../libraries/p5/p5.dom.js" type="text/javascript"></script>
9+
<script src="../../libraries/generative-design-library/generative-design-library.js" type="text/javascript"></script>
10+
11+
<script src="sketch.js" type="text/javascript"></script>
12+
13+
<style> body {padding: 0; margin: 0;} canvas {vertical-align: top;} </style>
14+
</head>
15+
<body>
16+
</body>
17+
</html>

01_P/P_2_2_4_02/sketch.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// P_2_2_4_02.pde
2+
//
3+
// Generative Gestaltung, ISBN: 978-3-87439-759-9
4+
// First Edition, Hermann Schmidt, Mainz, 2009
5+
// Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
6+
// Copyright 2009 Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
7+
//
8+
// http://www.generative-gestaltung.de
9+
//
10+
// Licensed under the Apache License, Version 2.0 (the "License");
11+
// you may not use this file except in compliance with the License.
12+
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
19+
/**
20+
* limited diffusion aggregation
21+
*
22+
* KEYS
23+
* 1 : toggle draw original position of circles
24+
* s : save png
25+
*/
26+
27+
var maxCount = 5000; //max count of the cirlces
28+
var currentCount = 1;
29+
var newx = [maxCount];
30+
var newy = [maxCount];
31+
var x = [maxCount];
32+
var y = [maxCount];
33+
var r = [maxCount]; // radius
34+
35+
var drawGhosts = false;
36+
37+
38+
function setup() {
39+
createCanvas(800, 800);
40+
smooth();
41+
42+
// first circle
43+
x[0] = width/2;
44+
y[0] = height/2;
45+
//r[0] = 10;
46+
r[0] = 360;
47+
}
48+
49+
50+
function draw() {
51+
background(255);
52+
53+
strokeWeight(0.5);
54+
//noFill();
55+
56+
// create a random set of parameters
57+
var newR = random(1, 7);
58+
var newX = random(0+newR, width-newR);
59+
var newY = random(0+newR, height-newR);
60+
61+
var closestDist = 100000000;
62+
var closestIndex = 0;
63+
// which circle is the closest?
64+
for(var i=0; i < currentCount; i++) {
65+
var newDist = dist(newX,newY, x[i],y[i]);
66+
if (newDist < closestDist) {
67+
closestDist = newDist;
68+
closestIndex = i;
69+
}
70+
}
71+
72+
// aline it to the closest circle outline
73+
var angle = atan2(newY-y[closestIndex], newX-x[closestIndex]);
74+
75+
newx[currentCount] = newX;
76+
newy[currentCount] = newY;
77+
x[currentCount] = x[closestIndex] + cos(angle) * (r[closestIndex]+newR);
78+
y[currentCount] = y[closestIndex] + sin(angle) * (r[closestIndex]+newR);
79+
r[currentCount] = newR;
80+
currentCount++;
81+
82+
// draw circles at random position and lines
83+
if (drawGhosts) {
84+
for (var i=1 ; i < currentCount; i++) {
85+
fill(230);
86+
ellipse(newx[i],newy[i], r[i]*2,r[i]*2);
87+
line(newx[i],newy[i], x[i],y[i]);
88+
}
89+
}
90+
91+
for (var i=0 ; i < currentCount; i++) {
92+
if (i == 0) noFill();
93+
else fill(50);
94+
ellipse(x[i],y[i], r[i]*2,r[i]*2);
95+
}
96+
97+
if (currentCount >= maxCount) noLoop();
98+
99+
}
100+
101+
function keyReleased() {
102+
if (key == 's' || key == 'S') saveCanvas(gd.timestamp(), 'png');
103+
104+
if (key == '1') drawGhosts = !drawGhosts;
105+
}

0 commit comments

Comments
 (0)