# Controls several parameters from 0 to 1

I want to achieve this effect

I've tried

With[{n=5},Manipulate[Table[If[0<=i-j<=1,Mod[i,1],1],{j,0,If[i<=n-1,i,n-1]}],{i,0,n}]]


That last one is always wrong, and I feel there must be a neat way to do it. Do you have a better way?

With[{n = 5}
, Manipulate[
ConstantArray[1, IntegerPart[i]]~Join~
{If[i > 0, FractionalPart[i], 0]} /. {a__, 0 | 0.} :> {a}
, {{i, 1}, 0, n}
]
]


Is this what you are after?

With[{n = 5},
Manipulate[
Table[
If[0 <= i - j <= 1, Mod[i, 1], 1],
{j, 0,
If[i <= n - 1, i, n - 1]}
],
{i, 0, n + 0.1}
]
]


# IntegerPartand FractionalPart

After the correction by @cvgmt (Thanks!)

Manipulate[
Append[
ConstantArray[1,IntegerPart[k]],
If[ #>0, #, Nothing ]& @ FractionalPart[k]
]
, {k, 0, 5}
]


My better or slightly wrong original answer, depending on the interpretation. It fails because when k==5, the result should be {1,1,1,1,1} instead of {1, 1, 1, 1, 1, 0.}, as commented by @cvgmt

Manipulate[
Append[
ConstantArray[1,IntegerPart[k]],
FractionalPart[k]
]
, {k, 0, 5}
]


One could argue that the sequence that makes most sense should always end in a float, but that is subject to discussion and the OP's example doesn't behave like that.

• When k==5, the result should be {1,1,1,1,1} instead of {1, 1, 1, 1, 1, 0.} Feb 13, 2023 at 11:11
• @cvgmt Thanks, corrected! Feb 13, 2023 at 11:17
Manipulate[
If[i == 0, {N@i},
If[0 < FractionalPart[i] < 1,
Join[ConstantArray[1, IntegerPart[i]], {FractionalPart[i]}],
ConstantArray[1, IntegerPart[i]]]], {i, 0, 5}]


• Same problem as mine? For k==4 you get {1,1,1,1,0} Feb 13, 2023 at 11:59
• @rhermans Thanks, fixed now. Feb 13, 2023 at 12:06

# Using QuotientRemainder and ReplaceAll

Manipulate[
ReplaceAll[
QuotientRemainder[k, 1],
RuleDelayed[
n_Integer,
Sequence@@ConstantArray[1,n]
]
]
, {k, 0, 5}
]


or the same in compact form

Manipulate[
QuotientRemainder[k, 1] /. n_Integer :> Sequence@@ConstantArray[1,n]
, {k, 0, 5}
]


Notice how n_Integer :> Sequence@@ConstantArray[1,n] removes the zeros too, because it replaces the zero with Sequence@@ConstantArray[1,0] which evaluates to Sequence[] which effectively removes it.

{4,0} /. n_Integer :> Sequence@@ConstantArray[1,n]
(* {1,1,1,1} *)