Icon representing a recipe

Recipe: Tvdl Bandmaker 1.0

created by Timo van der Laan

Profile


Name
Tvdl Bandmaker 1.0
ID
38660
Shared with
Public
Parent
None
Children
None
Created on
February 17, 2012 at 10:09 AM UTC
Updated on
February 17, 2012 at 10:09 AM UTC
Description

Creates random bands from each n-th segment. Options to set the strength and to have only 1 band connected to a segment , use only selected segments or exclude selected ones. The bands are distance preserving.

Best for


Code


-- Tvdl 11-02-2012 BandMaker 1.0 -- -- Creates random bands from each n-th segment -- These bands will be distancepreserving -- Option to allow only 1 band each segment -- Option to only band selected segments -- Option to not band selected segments function askOptions(title) local ask = dialog.CreateDialog(title) ask.l1 = dialog.AddLabel("Create one random band each n-th segment") ask.Rate = dialog.AddSlider("n",Rate,2,10,0) ask.l2 = dialog.AddLabel("Strength of the bands") ask.STR = dialog.AddSlider("Bandstrength",STR,0.1,5,2) ask.l3 = dialog.AddLabel("If checked only 1 band allowed each segment") ask.oneband=dialog.AddCheckbox("One band only",oneband) ask.l4 = dialog.AddLabel("Only selected segments are banded") ask.onlysel=dialog.AddCheckbox("Only selected",onlysel) ask.l5 = dialog.AddLabel("Selected segments are not banded") ask.exclsel=dialog.AddCheckbox("No band if selected",exclsel) ask.OK = dialog.AddButton("OK",1) ask.Cancel = dialog.AddButton("Cancel",0) if dialog.Show(ask) > 0 then Rate=ask.Rate.value STR=ask.STR.value oneband=ask.oneband.value onlysel=ask.onlysel.value exclsel=ask.exclsel.value return true else return false end end function MakeRandomBands() local NoBand={} if onlysel then for i=1,segCnt do if selection.IsSelected(i) == false then NoBand[i]=true end end end if exclsel then for i=1,segCnt do if selection.IsSelected(i) then NoBand[i]=true end end end for i=1,segCnt/Rate do if NoBand[Rate*i] ~= true then local k=math.random(segCnt) if k==0 then k=1 end local kstart=k if k>segCnt then k=1 end while NoBand[k]==true or math.abs(k-Rate*i)< 2 or (oneband and k%Rate==0) do k=k+1 if k>segCnt then k=1 end if k==kstart then return end --all available segments are done end if oneband then NoBand[k]=true end band.AddBetweenSegments(i*Rate,k) band.SetGoalLength(band.GetCount(),structure.GetDistance(i*Rate,k)) band.SetStrength(band.GetCount(),STR) end end end segCnt=structure.GetCount() -- Defaults STR=0.3 Rate=2 --Makes a band from each second segment oneband=false --If true only 1 band allowed each segment exclsel=false onlysel=false if askOptions("Tvdl Bandmaker 1.0") then MakeRandomBands() end

Comments