brython svg

from browser import document, svg, timer

rect = svg.rect(x=10, y=10, width=100, height=100)

def move_rect():
    # the attributes of the SVG element are strings, they must be explicitely
    # converted into integers
    rect.attrs["y"] = int(rect.attrs["y"]) + 1
    
    # ends animation when the rectangle reaches its target
    if int(rect.attrs["y"] ) > 50:
        timer.clear_interval(loop)

panel = document['panel5']
panel <= rect

# initialise the animation loop
loop = timer.set_interval(move_rect, 30)

4.33
9

                                    &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; 
    width=&quot;140&quot; height=&quot;200&quot; style=&quot;border-style:solid;border-width:1;border-color:#000;&quot;&gt;
  &lt;g id=&quot;panel&quot;&gt;
  &lt;/g&gt;
&lt;/svg&gt;

4.33 (9 Votes)
0
4.2
10

                                    from browser import document, svg

star = svg.polygon(fill=&quot;red&quot;, stroke=&quot;blue&quot;, stroke_width=&quot;10&quot;,
                   points=&quot;&quot;&quot; 75,38  90,80  135,80  98,107
                             111,150 75,125  38,150 51,107
                              15,80  60,80&quot;&quot;&quot;)

panel = document['panel4']
panel &lt;= star

4.2 (10 Votes)
0
4
2
Ltt 115 points

                                    from browser import document, svg

title = svg.text('Title', x=70, y=25, font_size=22,
                 text_anchor=&quot;middle&quot;)
circle = svg.circle(cx=70, cy=120, r=40,
                    stroke=&quot;black&quot;,stroke_width=&quot;2&quot;,fill=&quot;red&quot;)
panel = document['panel']
panel &lt;= title
panel &lt;= circle

4 (2 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source