viewof enemy_ship_template_v4 = {
({
prompt:
"OK I like the latest ship, can we make the center elipse spin around 360 with an SVG animation. Do not add or remove controls, or change values, other than than add spin speed UI",
time: 1700598322777,
comment:
"Add spin speed UI and implement SVG animation for the center ellipse of the enemy ship"
});
const enemyShipSettings = view`<div>
<h2>Enemy Ship Settings</h2>
${["scale", Inputs.range([0.05, 5], { value: 0.75, label: "Scale" })]}
${["width", Inputs.range([0.1, 2], { value: 0.5, label: "Width" })]}
${["height", Inputs.range([0.05, 1], { value: 0.1, label: "Height" })]}
${["color", Inputs.color({ value: "#000000", label: "Color" })]}
${[
"stroke_width",
Inputs.range([0, 0.05], { value: 0.018, label: "Stroke width" })
]}
${[
"stroke_color",
Inputs.color({ value: "#46ff2e", label: "Stroke color" })
]}
${[
"center_ellipse_width",
Inputs.range([0, 1], { value: 0.15, label: "Center ellipse width" })
]}
${[
"center_ellipse_height",
Inputs.range([0, 1], { value: 0.2, label: "Center ellipse height" })
]}
${[
"spin_speed",
Inputs.range([0, 10000], {
value: 400,
step: 100,
label: "Spin speed (ms for full rotation)"
})
]}
</div>`;
const updateEnemyShipTemplate = () => {
const settings = enemyShipSettings.value;
const centerEllipse = htl.svg`<ellipse cx="0" cy="0" stroke="${
settings.stroke_color
}" stroke-width="${settings.stroke_width * settings.scale}" rx="${
(settings.center_ellipse_width / 2) * settings.scale
}" ry="${(settings.center_ellipse_height * settings.scale) / 2}" fill="${
settings.color
}">
<animateTransform attributeName="transform" type="rotate" from="0 0 0" to="360 0 0" dur="${
settings.spin_speed
}ms" repeatCount="indefinite"/>
</ellipse>`;
const enemyShip = htl.svg`<ellipse cx="0" cy="0" rx="${
(settings.width / 2) * settings.scale
}" ry="${(settings.height / 2) * settings.scale}" stroke="${
settings.stroke_color
}" stroke-width="${settings.stroke_width * settings.scale}" />
${centerEllipse}`;
assets.set("enemyShip", enemyShip);
return enemyShip;
};
const preview = htl.svg`<svg width="100" height="100" viewBox="-0.4 -0.4 .8 .8" style="background: black;">${updateEnemyShipTemplate()}</svg>`;
enemyShipSettings.addEventListener("input", () => {
updateEnemyShipTemplate();
preview.replaceChild(assets.get("enemyShip"), preview.firstChild);
});
return htl.html`${enemyShipSettings}${preview}`;
}