Skip to content

Commit 6a94dad

Browse files
committed
Passing settings to attractors correctly, fixing Dark attractor color, scaling+centering from-image to screen
1 parent 76f5059 commit 6a94dad

File tree

8 files changed

+85
-28
lines changed

8 files changed

+85
-28
lines changed

core/ColorPresets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const Light = {
1313

1414
export const Dark = {
1515
BackgroundColor: 'rgba(0,0,0,.9)',
16-
AttractorColor: 'rgba(0,0,0,.5)',
16+
AttractorColor: 'rgba(255,255,255,.5)',
1717
BranchColor: 'rgba(255,255,255,1)',
1818
TipColor: 'rgba(0,255,255,1)',
1919
AttractionZoneColor: 'rgba(255,255,255,.002)',

experiments/basic/js/entry.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ let setupNetwork = () => {
3939
let waveAttractors = getWaveOfAttractors(ctx);
4040

4141
network.attractors = gridAttractors;
42+
43+
for(let attractor of network.attractors) {
44+
attractor.settings = network.settings;
45+
}
4246

4347
// Add a set of random root nodes throughout scene
4448
for(let i=0; i<10; i++) {

experiments/bounds/js/entry.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ let resetNetwork = () => {
152152
let gridAttractors = getGridOfAttractors(150, 150, ctx, 10, network.bounds);
153153

154154
network.attractors = gridAttractors;
155+
156+
for(let attractor of network.attractors) {
157+
attractor.settings = network.settings;
158+
}
155159
}
156160

157161
// Create the network with initial conditions

experiments/from-images/js/AttractorPatterns.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7841,4 +7841,27 @@ export let GreekStatue = [
78417841
[1651.9592, 560.744],
78427842
[1650.6536, 555.5017],
78437843
[1647.8226, 559.41113]
7844-
];
7844+
];
7845+
7846+
export function calculateExtents(coordArray) {
7847+
let minX = Infinity, maxX = -Infinity;
7848+
let minY = Infinity, maxY = -Infinity;
7849+
7850+
for(let coords of coordArray) {
7851+
minX = Math.min(minX, coords[0]);
7852+
maxX = Math.max(maxX, coords[0]);
7853+
minY = Math.min(minY, coords[1]);
7854+
maxY = Math.max(maxY, coords[1]);
7855+
}
7856+
7857+
return {
7858+
minX,
7859+
maxX,
7860+
minY,
7861+
maxY,
7862+
width: maxX - minX,
7863+
height: maxY - minY
7864+
};
7865+
}
7866+
7867+
export let GreekStatueExtents = calculateExtents(GreekStatue);

experiments/from-images/js/entry.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Path from '../../../core/Path';
66
import { random } from '../../../core/Utilities';
77
import { setupKeyListeners } from '../../../core/KeyboardInteractions';
88
import Settings from './Settings';
9-
import { GreekStatue } from './AttractorPatterns';
9+
import { GreekStatue, GreekStatueExtents } from './AttractorPatterns';
1010

1111
let canvas, ctx;
1212
let network;
@@ -44,20 +44,34 @@ let resetNetwork = () => {
4444
let addAttractors = () => {
4545
let attractors = [];
4646

47+
// Scale the coordinates to fit within the window
48+
const scale = Math.min(
49+
window.innerWidth / GreekStatueExtents.width,
50+
window.innerHeight / GreekStatueExtents.height
51+
) * 0.8; // 0.8 to leave some margin
52+
53+
// Center the pattern in the middle of the window
54+
const offsetX = (window.innerWidth - (GreekStatueExtents.width * scale)) / 2;
55+
const offsetY = (window.innerHeight - (GreekStatueExtents.height * scale)) / 2;
56+
4757
for(let coords of GreekStatue) {
58+
const x = (coords[0] - GreekStatueExtents.minX) * scale + offsetX;
59+
const y = (coords[1] - GreekStatueExtents.minY) * scale + offsetY;
60+
4861
attractors.push(
4962
new Attractor(
50-
new Vec2(
51-
coords[0]*1.1 - 750,
52-
coords[1]*1.1 - 90
53-
),
63+
new Vec2(x, y),
5464
ctx,
5565
Settings
5666
)
5767
);
5868
}
5969

6070
network.attractors = attractors;
71+
72+
for(let attractor of network.attractors) {
73+
attractor.settings = network.settings;
74+
}
6175
}
6276

6377
// Create the network with initial conditions
@@ -66,7 +80,7 @@ let resetNetwork = () => {
6680
new Node(
6781
null,
6882
new Vec2(
69-
window.innerWidth/2 - 440,
83+
window.innerWidth/2 - 190,
7084
window.innerHeight/2 + 100
7185
),
7286
false,

experiments/marginal-growth/js/entry.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ let resetNetwork = () => {
224224
let generateAttractorsOnPath = () => {
225225
// network.attractors = createEvenlySpacedAttractors();
226226
network.attractors = createSubdividedAttractors();
227+
228+
for(let attractor of network.attractors) {
229+
attractor.settings = network.settings;
230+
}
227231
}
228232

229233
let createEvenlySpacedAttractors = () => {

experiments/obstacles/js/entry.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ let resetNetwork = () => {
180180
let gridAttractors = getGridOfAttractors(200, 200, ctx, 10, network.bounds, network.obstacles);
181181

182182
network.attractors = gridAttractors;
183+
184+
for(let attractor of network.attractors) {
185+
attractor.settings = network.settings;
186+
}
183187
}
184188

185189
// Create the network with initial conditions

experiments/painting/js/entry.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,18 @@ document.addEventListener('mousedown', (e) => {
123123
let radius = random(-attractorRadius, attractorRadius);
124124
let angle = random(360);
125125

126-
network.attractors.push(
127-
new Attractor(
128-
new Vec2(
129-
e.clientX + Math.floor(radius * Math.cos(angle)),
130-
e.clientY + Math.floor(radius * Math.sin(angle))
131-
),
132-
ctx,
133-
Settings
134-
)
135-
);
126+
const newAttractor = new Attractor(
127+
new Vec2(
128+
e.clientX + Math.floor(radius * Math.cos(angle)),
129+
e.clientY + Math.floor(radius * Math.sin(angle))
130+
),
131+
ctx,
132+
Settings
133+
)
134+
135+
newAttractor.settings = network.settings;
136+
137+
network.attractors.push(newAttractor);
136138
}
137139

138140
break;
@@ -173,16 +175,18 @@ document.addEventListener('mousemove', (e) => {
173175
let radius = random(-attractorRadius, attractorRadius);
174176
let angle = random(360);
175177

176-
network.attractors.push(
177-
new Attractor(
178-
new Vec2(
179-
e.clientX + Math.floor(radius * Math.cos(angle)),
180-
e.clientY + Math.floor(radius * Math.sin(angle))
181-
),
182-
ctx,
183-
Settings
184-
)
185-
);
178+
const newAttractor = new Attractor(
179+
new Vec2(
180+
e.clientX + Math.floor(radius * Math.cos(angle)),
181+
e.clientY + Math.floor(radius * Math.sin(angle))
182+
),
183+
ctx,
184+
Settings
185+
)
186+
187+
newAttractor.settings = network.settings;
188+
189+
network.attractors.push(newAttractor);
186190
}
187191
}
188192

0 commit comments

Comments
 (0)