Elektrine lite

← Feed

@lndf@merveilles.town

Post #2303103

2026-03-20 09:40 UTC

Quick idea before work, it's a basic star algo at the core, with some modulations TW : ugly code ```js function star(ctx, centerx, centery, internal_radius, external_radius, divisions, rotation) { divisions = Math.floor(Math.abs(divisions)); if (divisions%2 != 0) {divisions += 1} console.log(division) //interesting found : // freeze i to step_angle on the externals, works welle especially if only one is used // swap some sin and cos, reversing just one will do a diagonal, swapping both will associate opposite internal and externals let step_angle = (2.0 * Math.PI) / divisions; let prev_x = centerx + (internal_radius * Math.sin(0.0+rotation)) let prev_y = centery + (internal_radius * Math.cos(0.0+rotation)) ellipse(ctx, prev_x, prev_y, 10, 10) let first_x = prev_x; let first_y = prev_y; let int_ext = false; for (let i = step_angle; i < (2.0 * Math.PI); i += step_angle) { if (int_ext) { // offset i on internal or external to create wonky forms (james bond barrel) current_x = centerx + (internal_radius * Math.sin(i+rotation)); current_y = centery + (internal_radius * Math.cos(i+rotation)); ellipse(ctx, current_x, current_y, 10, 10) } else { current_x = centerx + (external_radius * Math.cos(i)); current_y = centery + (external_radius * Math.sin(i)); // Toggle this to show the points ellipse(ctx, current_x, current_y, 50, 50) } ctx.beginPath(); ctx.moveTo(prev_x, prev_y); ctx.lineTo(current_x, current_y); ctx.stroke(); prev_x = current_x; prev_y = current_y; int_ext = !int_ext; } ctx.beginPath(); ctx.moveTo(prev_x, prev_y); ctx.lineTo(first_x, first_y); ctx.stroke(); } ```

Replies (0)

No replies.