Skip to content

Commit

Permalink
fractional loops
Browse files Browse the repository at this point in the history
  • Loading branch information
bobnik committed Nov 3, 2024
1 parent ce1e2a0 commit 5285b08
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/features/effects/Loop.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import Effect from "./Effect"
import Victor from "victor"
import { scale, rotate, centerOnOrigin, cloneVertex } from "@/common/geometry"
import {
scale,
rotate,
centerOnOrigin,
cloneVertex,
subsample,
} from "@/common/geometry"
import { evaluate } from "mathjs"

const options = {
Expand Down Expand Up @@ -144,9 +150,22 @@ export default class Loop extends Effect {
}

const outputVertices = []
let numLoops = effect.numLoops
let fractionalLength = vertices.length
const remainder = numLoops - (numLoops = Math.floor(numLoops))

if (remainder > 0) {
// ensure shapes with fewer vertices like polygon are subsampled to produce an
// accurate fractional loop
vertices = subsample(vertices, 2.0)
fractionalLength = Math.floor(vertices.length * remainder)
numLoops = numLoops + 1
}

for (var i = 0; i < numLoops; i++) {
const length = i == numLoops - 1 ? fractionalLength : vertices.length

for (var i = 0; i < effect.numLoops; i++) {
for (let j = 0; j < vertices.length; j++) {
for (let j = 0; j < length; j++) {
let vertex = cloneVertex(vertices[j])
let amount =
effect.transformMethod === "smear" ? i + j / vertices.length : i
Expand Down

0 comments on commit 5285b08

Please sign in to comment.