mitxela / plotterfun

MIT License
331 stars 63 forks source link

How to get controls to work? #19

Closed graza closed 3 years ago

graza commented 3 years ago

I've been tinkering with a new algorithm. I don't code much any more, so it's taken longer than it should have! It's still a bit of a work in progress.

Thing is, I can't get the controls to have an initial value. It seems to be the value property but mine always have a value of 1. Any ideas?

postMessage(['sliders', defaultControls.concat([
  {label: 'Tile size', value: 60, min: 6, max: 100},
  {label: 'Lines', value: 6, min: 2, max: 50, step: 2},
  {label: 'Sublines', value: 3, min: 1, max: 10}
  ,{label: 'Amplitude', value: 0.1, min: 0.1, max: 5, step: 0.1}
  ,{label: 'Sampling', value: 5, min: 2, max: 10, step: 0.1}
])]);

My repo is adding a Truchet Tile algorithm: https://github.com/graza/plotterfun

mitxela commented 3 years ago

I haven't looked too closely but this is probably to do with the name of the controls.

Plotterfun will use the initial value when it's first loaded, but if you change algorithm and some of the controls are the same, it will keep their values. The idea was to be able to jump between similar algorithms without having to adjust the sliders each time.

If you want the controls to definitely start at their initial value, the only way at the moment is to give the control a unique name, not shared by other algorithms.

graza commented 3 years ago

OK that makes sense. I'm doing something like Subline to thicken the lines so I'll try to make it work like that, and scale the control values according to the other parameters I have.

Cheers!