<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Animation in mojo.Canvas]]></title><description><![CDATA[<p dir="auto">Hi Frederik,</p>
<p dir="auto">I'd like to know if it is possible to generate an animation into a <code>mojo.Canvas</code> instance or into an <code>NSView()</code> (a kind of Processing <code>void draw{}</code>, which refresh itself to a given rate).</p>
<p dir="auto">I'd like to create something similar to the responsive lettering by Erik but keeping the animation into the application environment (no svg, no html).</p>
<p dir="auto">Any idea?</p>
<p dir="auto">All the best</p>
]]></description><link>https://forum.robofont.com/topic/396/animation-in-mojo-canvas</link><generator>RSS for Node</generator><lastBuildDate>Sun, 14 Jun 2026 10:50:26 GMT</lastBuildDate><atom:link href="https://forum.robofont.com/topic/396.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 13 Mar 2016 15:32:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Animation in mojo.Canvas on Wed, 03 Jan 2018 18:00:30 GMT]]></title><description><![CDATA[<p dir="auto">Hi Frederik,</p>
<p dir="auto">I'd like to know if it is possible to generate an animation into a <code>mojo.Canvas</code> instance or into an <code>NSView()</code> (a kind of Processing <code>void draw{}</code>, which refresh itself to a given rate).</p>
<p dir="auto">I'd like to create something similar to the responsive lettering by Erik but keeping the animation into the application environment (no svg, no html).</p>
<p dir="auto">Any idea?</p>
<p dir="auto">All the best</p>
]]></description><link>https://forum.robofont.com/post/395</link><guid isPermaLink="true">https://forum.robofont.com/post/395</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Wed, 03 Jan 2018 18:00:30 GMT</pubDate></item><item><title><![CDATA[Reply to Animation in mojo.Canvas on Wed, 03 Jan 2018 17:58:32 GMT]]></title><description><![CDATA[<p dir="auto">Hi Roberto</p>
<p dir="auto">small example</p>
<p dir="auto">hope this helps :)</p>
<pre><code class="language-python">from AppKit import NSTimer
from random import random

from vanilla import *

from mojo.canvas import Canvas
import mojo.drawingTools as dt

from lib.baseObjects import CallbackWrapper

class Test(object):
    
    def __init__(self):
        self.pos = 0, 0
        self.width = 400
        self.height = 400
        self.size = 100
        self.steps = 5
        self.addHorizontal = True
        self.directionX = 1
        self.directionY = 1
        
        framePerSecond = 30
        
        self.interval = framePerSecond / 1000.
        
        self.w = Window((400, 400))
        
        self.w.canvas = Canvas((0, 0, 400, 400), self, canvasSize=(self.width, self.height))
        self.w.open()
        
        self._callback = CallbackWrapper(self.redraw)
        self.sheduleTimer()
    
    def sheduleTimer(self):
        if self.w.getNSWindow() is not None:
            self.trigger = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(self.interval, self._callback, "action:", None, False)
    
    def redraw(self, timer):
        self.w.canvas.update()
        self.sheduleTimer()
    
    def draw(self):
        x, y = self.pos
        if self.addHorizontal:
            x += self.steps  * self.directionX
        else:
            y += self.steps  * self.directionY
        
        if x &gt; (self.width - self.size):
            self.addHorizontal = False
            x = self.width - self.size
            self.directionX *= -1
        elif x &lt; 0:
            self.addHorizontal = False
            x = 0     
            self.directionX *= -1       
        
        if y &gt; (self.height - self.size):
            self.addHorizontal = True
            y = self.height - self.size
            self.directionY *= -1
        elif y &lt; 0:
            self.addHorizontal = True
            y = 0
            self.directionY *= -1
        
        dt.fill(x/float(self.width), y/float(self.height), 1)
        dt.rect(x, y, self.size, self.size)
        
        self.pos = x, y

Test()
</code></pre>
]]></description><link>https://forum.robofont.com/post/1409</link><guid isPermaLink="true">https://forum.robofont.com/post/1409</guid><dc:creator><![CDATA[frederik]]></dc:creator><pubDate>Wed, 03 Jan 2018 17:58:32 GMT</pubDate></item><item><title><![CDATA[Reply to Animation in mojo.Canvas on Mon, 14 Mar 2016 15:14:25 GMT]]></title><description><![CDATA[<p dir="auto">OMG<br />
you made my day</p>
<p dir="auto">Thanks : )))))</p>
]]></description><link>https://forum.robofont.com/post/1410</link><guid isPermaLink="true">https://forum.robofont.com/post/1410</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Mon, 14 Mar 2016 15:14:25 GMT</pubDate></item></channel></rss>