Python Forum
Python written in Python, written in Python (warning: somewhat heavy image included)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python written in Python, written in Python (warning: somewhat heavy image included)
#1
All done with four Gimp scripts (all in Python of course)

[Image: aJMshKw.gif]
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#2
Would you like to share the scripts? Python is heavily used in almost all the graphics programs but I never wrote something
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
All there: Ofnuts' Gimp path tools downloads (but using them requires some Gimp skills).
  • The first four waves where created by path-waves
  • Intermediate lines are interpolated with path-inbetweener
  • "PYTHON..." is laid out over each line with ofn-text-along-path (which is the thing I've been working on in the last couple of weeks)
  • the animation frames are then rendered with stroke-or-fill-visible-paths
Added two new tricks to my bag with ofn-text-along-path:
  • Using context managers
  • Making a "factory" (of context managers...) which is incredibly simpler in Python than in Java
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#4
That's cool and inspired me to do the same basic thing in pygame (python 2.7). The next step would be to make a second "animation" that is really just flat and stationary, then "blend" both animations weighted more toward the stationary one on the endcaps (so the head/tail are more still like yours, I also just used blocks not letters, but they rotate to stay in line with snake body as well).
import pygame,random,time,math

class Spot(object):
    def __init__(ss,x,y,ang,leti):
        ss.x=x
        ss.y=y
        ss.ang=ang
        ss.leti=leti

def makesnake(startang,rot,rad,wordreps,w,h):
    step=w/(wordreps*6.0)
    nsteps=wordreps*6
    spots=[]
    ang=startang
    x=0
    leti=0
    for i in range(nsteps):
        y=(h/2)+(math.sin(math.radians(ang))*rad)
        s=Spot(x,y,None,leti)
        spots.append(s)
        x+=step
        ang=(ang+rot)%360
        leti=(leti+1)%6
    return spots

def makesnakeanim(ang,angstep,rot,rotstep,rotmax,rotmin,rad,radstep,radmax,radmin,wordreps,w,h,frames):
    snakeanim=[]
    for i in range(frames):
        spots=makesnake(ang,rot,rad,wordreps,w,h)
        setspotangs(spots)
        snakeanim.append(spots)
        ang+=angstep
        rot+=rotstep
        if rot>rotmax or rot<rotmin:
            rotstep*=-1
            rot+=rotstep*2
        rad+=radstep
        if rad>radmax or rad<radmin:
            radstep*=-1
            rad+=radstep*2
    return snakeanim

def drawsnake(spots):
    for s in spots:
        roted=pygame.transform.rotate(letrs[s.leti],s.ang)
        screen.blit(roted,(s.x,s.y))

def setspotangs(spots):
    for i in range(len(spots)-1):
        x1=spots[i].x
        y1=spots[i].y
        x2=spots[i+1].x
        y2=spots[i+1].y
        spots[i].ang=math.atan2(y2-y1,x2-x1)*-180.0/math.pi
    x1=spots[-1].x
    y1=spots[-1].y
    x2=spots[-2].x
    y2=spots[-2].y
    spots[-1].ang=math.atan2(y2-y1,x2-x1)*-180.0/math.pi
    #spots[-1].ang=0

letrs=[]
for i in range(6):
    s=pygame.Surface((12,12))
    s.set_colorkey((1,1,1))
    s.fill((random.randint(0,255),random.randint(0,255),random.randint(0,255)))
    letrs.append(s)

sw=512
sh=512
screen=pygame.display.set_mode((sw,sh))

#startang=0
#rot=10
#rad=5

#anim1=makesnakeanim(0,8,5,1,20,1,32,3,96,16,6,512,512,100)
ang=0
angstep=8
rot=20
rotstep=1
rotmax=40
rotmin=10
rad=32
radstep=8
radmax=64
radmin=16
wordreps=6
w=512
h=512
frames=500
anim1=makesnakeanim(ang,angstep,rot,rotstep,rotmax,rotmin,rad,radstep,radmax,radmin,wordreps,w,h,frames)

cc=0
running=True
while running:
    for e in pygame.event.get():
        if e.type==pygame.QUIT:
            running=False

    screen.fill((255,255,255))
    #spots=makesnake(startang,rot,rad,6,512,512)
    #setspotangs(spots)
    #drawsnake(spots)
    drawsnake(anim1[cc])
    
    pygame.display.flip()
    time.sleep(0.1)

    #startang+=4
    #rad+=0.1
    cc=(cc+1)%len(anim1)
pygame.quit()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tried a flashcard app written in Python Gribouillis 0 1,593 Oct-28-2019, 10:45 AM
Last Post: Gribouillis
  Python training starting the 5th of April - Formation python le 5 avril jeanMichelBain 1 2,218 Mar-20-2019, 09:37 AM
Last Post: DeaD_EyE
  Liking Snippsat's new python image Larz60+ 4 3,205 Jun-21-2018, 07:10 PM
Last Post: j.crater
  heavy up front web sites Skaperen 2 2,393 Mar-15-2018, 01:56 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020