ParticleCanvasComponent.vala 985 B

12345678910111213141516171819202122232425
  1. using Spry;
  2. /**
  3. * ParticleCanvasComponent - A single particle in the simulation
  4. *
  5. * Renders as a colored circle at a specific position
  6. */
  7. public class ParticleCanvasComponent : Component {
  8. public double x { set; get; default = 50; }
  9. public double y { set; get; default = 50; }
  10. public string color { set; get; default = "#7c3aed"; }
  11. public int size { set; get; default = 12; }
  12. public override string markup { get {
  13. return """
  14. <div sid="particle" style="position: absolute; border-radius: 50%; box-shadow: 0 0 10px currentColor;"></div>
  15. """;
  16. }}
  17. public override async void prepare() throws Error {
  18. var style = @"position: absolute; left: $(x)%; top: $(y)%; width: $(size)px; height: $(size)px; background: $(color); border-radius: 50%; box-shadow: 0 0 $(size / 2)px $(color); transform: translate(-50%, -50%); transition: all 0.1s ease-out;";
  19. this["particle"].set_attribute("style", style);
  20. }
  21. }