Animated Birds

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
Quark
Posts: 474
Joined: May 27, 2011 18:16
Location: Pennsylvania, U.S.
Contact:

Animated Birds

Post by Quark »

.
“Now the New Year reviving old Desires.
The thoughtful Soul to Solitude retires" ...

And out in those New Year solitudes, no doubt there are flocks of birds flying to unknown destinations. An example here courtesy of FB's DRAW command:

And, Happy New Year,

--Quark

Code: Select all

'=======================================================================
' Flying_Birds.bas by Quark - 2015.12.30
' FreeBASIC Compiler - Ver 1.04.0 (10-01-2015), built for linux-x86_64 (64bit)
' Purpose: show relative DRAW_strings generated by the RDS_Editor
' Shows multiple sumultaneous, independent examples of the current sprite-strings
'==============================================================================
#LANG "fb"
#INCLUDE ONCE "fbgfx.bi"
DECLARE FUNCTION RndRange(lo AS INTEGER,hi AS INTEGER) AS INTEGER
DECLARE FUNCTION NextColor() AS UINTEGER
DECLARE SUB StrReplaceAll(s AS STRING, find AS STRING, replace AS STRING)
DECLARE FUNCTION Regulate(BYVAL MyFps AS LONG,BYREF fps AS LONG) AS LONG 'dodicat
'==============================================================================
'DEFINES
CONST AS UINTEGER BLACK = RGB(&H00,&H00,&H00), WHITE = RGB(&HFF,&HFF,&HFF)
CONST AS UINTEGER STANDARDRED = RGB(&HFF,&H30,&H30)
CONST AS UINTEGER BLUE = RGB(&H80,&H80,&HFF)
CONST w = 640, h = 480, centx = w\2, centy = h\2
SCREENRES w,h,32
RANDOMIZE TIMER
COLOR BLACK,WHITE
DIM AS LONG fps
DIM AS STRING back, ts
DIM AS INTEGER cnt
DIM SHARED AS fb.Image PTR snapshot
snapshot = IMAGECREATE(w,h,WHITE,32)

CONST max = 4, numSprites = 10
TYPE fx
  AS STRING sp(1 TO max) 'sprite-strings
  AS UINTEGER bclr(1 TO max) 'sprite boundary color
  x1 AS INTEGER         'x initial
  y1 AS INTEGER         'y initial
  x2 AS INTEGER         'x final
  y2 AS INTEGER         'y final
  incx AS SINGLE
  incy AS SINGLE
  cumx AS SINGLE
  cumy AS SINGLE
  steps AS INTEGER
  cnt AS INTEGER
  cursprite AS INTEGER = 1
  scale AS INTEGER = 3  'size of sprite
  angle AS INTEGER = 0  'angle of sprite
END TYPE
DECLARE SUB CalcPath(d AS fx)

DIM d(1 TO numSprites) AS fx

READ ts
WHILE ts <> "enddata"
  back &= ts
  READ ts
WEND

'LOAD THE SPRITE-PHASES
DIM AS STRING ds(1 TO max)
cnt = 1
READ ts
WHILE ts <> ""
  IF ts = "enddata" THEN
    cnt += 1
    IF cnt > max THEN EXIT WHILE
  ELSE
    ds(cnt) &= ts
  END IF
  READ ts
WEND

'LOAD ALL SPRITES W STRINGS, BOUNDARY-COLORS, BODY-COLOR
FOR i AS INTEGER = 1 TO numsprites
  FOR j AS INTEGER = 1 TO max
    d(i).sp(j) = ds(j)
    d(i).bclr(j) = NextColor()
    StrReplaceAll(d(i).sp(j), STR(BLACK), STR(d(i).bclr(j)))
    StrReplaceAll(d(i).sp(j), STR(STANDARDRED), STR(BLUE))
  NEXT
  d(i).scale = 1 : IF RND < .20 THEN d(i).scale = 2
  d(i).angle = RndRange(3,10)
  d(i).x1 = RndRange(((w\10)*8),((w\10)*8)+(4-d(i).scale)*40) : d(i).y1 = RndRange(76, h-76)
  d(i).x2 = d(i).scale*25 : d(i).y2 = RndRange(d(i).y1-38, d(i).y1+38)
  CalcPath(d(i))
NEXT
DIM num AS INTEGER = 1
cnt = 0
DO
  SCREENLOCK
  CLS
  DRAW back
  GET (0,0)-(639,479), snapshot
  FOR i AS INTEGER = 1 TO num
    PUT (0,0), snapshot, PSET 'screen-image
    DRAW "BM" & d(i).cumx & "," & d(i).cumy
    DRAW "C" & d(i).bclr(d(i).cursprite) & "TA" & d(i).angle & "S" & d(i).scale
    DRAW d(i).sp(d(i).cursprite)
    GET (0,0)-(639,479), snapshot
    d(i).steps -= 1
    d(i).cumx += d(i).incx : d(i).cumy += d(i).incy
    d(i).cnt += 1
    IF d(i).cnt = 4 THEN
      d(i).cnt = 0
      d(i).cursprite += 1 : IF d(i).cursprite > max THEN d(i).cursprite = 1
    END IF
    IF d(i).steps < 2 THEN
      d(i).scale = 1 : IF RND < .20 THEN d(i).scale = 2
      d(i).angle = RndRange(3,10)
      d(i).x1 = RndRange(((w\10)*8),((w\10)*8)+(4-d(i).scale)*40) : d(i).y1 = RndRange(76, h-76)
      d(i).x2 = d(i).scale*25 : d(i).y2 = RndRange(d(i).y1-38, d(i).y1+38)
      CalcPath(d(i))
    END IF
  NEXT
  cnt+= 1
  IF cnt = 24 THEN
    cnt = 0
    IF num < numsprites THEN num += 1
  END IF
  SCREENUNLOCK
  SLEEP Regulate(200,fps),1
LOOP UNTIL LEN(INKEY)
SLEEP
END
'==============================================================================
FUNCTION RndRange(lo AS INTEGER,hi AS INTEGER) AS INTEGER
  'Returns random number in a range, e.g. given range of
  '5 and 10 returns a num in range 5,6,7,8,9,10
  RETURN INT(RND * (hi-lo+1) +lo)
END FUNCTION
'==============================================================================
FUNCTION NextColor() AS UINTEGER
  'each call gives back next color (note: zeros not used)
  'used for providing unique border colors for sprites
  STATIC AS INTEGER r, g, b
  b += 1
  IF b > 15 THEN
    b = 1
    g += 1
    IF g > 15 THEN
      g = 1
      r += 1
      IF r > 15 THEN
        b = 1
        g = 1
        r = 1
      END IF
    END IF
  END IF
  RETURN RGB(r,g,b)
END FUNCTION
'==============================================================================
SUB StrReplaceAll(s AS STRING, find AS STRING, replace AS STRING)
  DIM AS INTEGER locat
  DO
    locat = INSTR(s, find) : IF locat = 0 THEN EXIT DO
    s = LEFT(s,locat-1) & replace & MID(s,locat + LEN(find))
  LOOP
END SUB
'==============================================================================
SUB CalcPath(d AS fx)
  DIM AS INTEGER dx = d.x2 - d.x1, dy = d.y2 - d.y1
  d.steps = ABS(dy)
  IF ABS(dx) > ABS(dy) THEN d.steps = ABS(dx)
  d.incx = dx/d.steps
  d.incy = dy/d.steps
  d.cumx = d.x1 : d.cumy = d.y1
END SUB
'==============================================================================
FUNCTION Regulate(BYVAL MyFps AS LONG,BYREF fps AS LONG) AS LONG 'dodicat
  STATIC AS DOUBLE timervalue,_lastsleeptime,t3,frames
  VAR t=TIMER
  frames+=1
  IF (t-t3)>=1 THEN t3=t:fps=frames:frames=0
  VAR sleeptime=_lastsleeptime+((1/myfps)-T+timervalue)*1000
  IF sleeptime<1 THEN sleeptime=1
  _lastsleeptime=sleeptime
  timervalue=T
  RETURN sleeptime
END FUNCTION
'==============================================================================
DATA "C4278190080BM0,0M639,0M639,479M0,479M0,0BM1,1M638,1M638,478M1,478M1,1BM2,2M637,2M637,477M2,477M2,2BM3,3M636,3M636,476M3,476M3"
DATA ",3BM2,105M5,92M9,79M13,77M20,74M21,58M32,53M38,43M46,52M47,53M56,52M62,64M76,48M77,36M93,27M107,29M108,37M116,39M120,28M132,1"
DATA "5M135,14M142,8M152,5M160,1M217,1M221,21M229,39M249,51M257,73M233,103M220,104M213,83M210,81M200,100M197,106M180,109M168,92M163"
DATA ",81M155,85M143,95M134,112M128,112M115,110M96,90M91,100M77,124M70,117M48,117M51,106M39,99M21,95M23,114M12,128M2,115BM240,46M24"
DATA "6,40M250,31M253,28M257,28M267,38M272,34M274,29M281,22M286,18M291,16M304,21M306,18M309,15M314,11M314,11M322,7M332,2M348,1M373,"
DATA "20M389,39M392,48M410,60M410,71M399,80M387,88M364,77M351,88M350,91M317,81M305,67M291,70M274,84M273,89M263,93M250,89M247,86M251"
DATA ",81BM7,212M9,209M17,209M22,199M27,190M39,177M59,181M60,182M83,165M95,151M110,134M123,135M131,129M138,132M145,121M164,116M171,"
DATA "123M189,136M208,134M228,147M245,163M255,172M260,184M285,157M284,137M287,132M301,109M309,112M319,101M359,103M367,101M395,96M39"
DATA "7,96M423,77M432,69M438,75M489,92M495,90M503,87M516,92M530,112M548,109M591,117M600,103M624,96M634,116M639,132M638,147BM11,417M"
DATA "14,414M14,399M22,392M27,422M33,413M35,399M33,374M39,362M42,364M45,364M61,384M61,395M61,402M62,416M66,436M73,455M83,450M87,438"
DATA "M82,407M84,397M93,382M99,369M110,390M114,386M116,379M115,370M126,371M135,384M134,398M133,404M135,418M135,418M146,415M148,405M"
DATA "152,405M152,414M156,427M164,427M161,417M161,409M167,400M168,400M176,407M179,422M181,429M189,439M193,434M193,430M191,412M199,4"
DATA "07M215,404M241,414M246,421M252,430M252,430M272,429M272,424M285,414M301,427M301,419M301,417M308,402M308,392M310,378M315,371M33"
DATA "7,390M339,394M351,415M359,417M360,417M375,404M376,394M383,385M414,381M418,395M422,403M423,408M437,408M450,393M473,377M482,388"
DATA "M488,397M494,402M518,420M533,408M533,405M552,392M552,386M560,370M581,382M585,374M598,392M609,386M619,372M628,381M633,393M639,"
DATA "399M638,405BM294,69M299,79M305,87M307,93M306,106M306,111M309,112M314,106M316,95M321,92M330,89M336,87M339,88BM301,68M311,84M31"
DATA "2,90M324,83M327,84BM418,1M405,8M399,17M401,31M415,53M423,48M428,38M446,55M448,56M461,61M463,53M472,49M478,58M487,72M488,69M50"
DATA "0,66M500,56M514,53M527,71M528,81M539,99M547,92M558,80M561,62M581,41M595,50M614,67M616,63M624,55M634,51M637,39M638,19BM160,83M"
DATA "157,84M155,119M163,116M165,86M171,96BM38,142M38,142M22,101M21,100BM38,141M36,180M39,177M44,178M47,150M70,142M106,100M103,97M7"
DATA "7,125M67,137M48,142M56,117M52,117M45,136M28,96M26,96BM17,149P4278215790,4278190080BM14,147P4287269514,4278190080BM1,212M2,206"
DATA "BM12,155P4287269514,4278190080BM18,162P4287269514,4278190080BM13,140P4278215790,4278190080BM11,150P4288322202,4278190080BM9,2"
DATA "09M1,215M2,210BM18,152M18,152M18,152BM22,150P4278215790,4278190080BM42,27P4278215790,4278190080BM42,109P4278215790,4278190080"
DATA "BM61,124P4278215790,4278190080BM97,100P4278215790,4278190080BM84,146P4278215790,4278190080BM255,119P4278215790,4278190080BM23"
DATA "6,19P4278215790,4278190080BM381,14P4278215790,4278190080BM316,86P4278215790,4278190080BM2,424M14,413BM164,35P4278230601,42781"
DATA "90080BM523,30P4278230601,4278190080BM337,25P4280196697,4278190080BM163,261P4278218291,4278190080BM293,435P4284063353,42781900"
DATA "80BM42,139P4285422398,4278190080BM159,98P4285422398,4278190080BM311,94P4285422398,4278190080BM341,438P4280196697,4278190080BM"
DATA "252,265P4278230601,4278190080BM242,460P4278218291,4278190080BM46,17P4280193950,4278190080BM255,11P4280193950,4278190080BM391,"
DATA "15P4280193950,4278190080BM269,124P4280193950,4278190080BM146,106P4280193950,4278190080BM16,134P4280193950,4278190080BM39,109P"
DATA "4280193950,4278190080BM59,127P4280193950,4278190080BM95,101P4280193950,4278190080BM315,85P4280193950,4278190080"
DATA "enddata"
'bird03
DATA "BM-19,+3M-8,-4M-5,-10M-13,+0M-1,-9M-9,-2M-4,-2M-1,-8M-9,-4M-7,-2M-9,+1M-"
DATA "4,-5M-9,+3M-9,-6M-16,+22M+10,+10M+10,+9M+10,+10M+7,+1M+10,+4M-6,+6M-7,+7"
DATA "M+1,+10M-4,+14M+16,-2M+19,+3M+16,+2M+23,+15M+17,+6M+9,+3M-2,+9M+6,+7M+7,"
DATA "+2M-1,-7M+9,+0M-3,-3M+0,-5M+16,-3M+9,+0M+6,-2M+2,-4M+13,+2M+15,+15M+11,-"
DATA "3M+23,+10M+13,+1M+5,-7M-12,-13M-38,-23M-25,-13M+4,-3M-2,-11M+18,-6M+1,-4"
DATA "M+11,-4M-1,-7M+11,-10M-6,-7M+7,-11M-1,-2M-5,-5M+1,-10M-4,-6M+6,-8M-5,-4M"
DATA "+1,-9M-6,-5M+1,-11M-15,-3M+0,-16M-7,+0M-10,+10M-6,-11M-10,-6M-8,+15M-15,"
DATA "+0M-4,+14M-6,-15M-7,+10M+3,+27M-13,+31M-7,+17M-4,+11M-2,+2BM+28,+21M+25,"
DATA "+2M+17,+8M+14,+7M+2,+1BM-31,+17M-7,+12M+6,+1M-6,-4M-21,+6M-3,+7M+2,+7BM-"
DATA "96,-50M+4,-1M+4,+1M+4,+2BM+1,-8M+5,+1M+4,+0M+3,-4M-2,-2M-2,-1M-8,+4BM+3,"
DATA "-1M+0,+1M+1,+2BM+56,-18M-16,-1M-12,+0M-13,-5M-13,+3M-10,+3M-3,+4BM+5,-4M"
DATA "-5,-3BM+144,+29M+1,-1M+2,+0BM-85,-35M+5,-3BM+15,+1BM-15,+33P4294914096,4"
DATA "278190080BM+15,-33BM-67,+28P4294914096,4278190080BM+67,-28"
DATA "enddata"
'bird06
DATA "BM-16,-1M-4,+3M-11,-3M-5,-5M-7,+2M-12,-9M-9,-5M-6,+2M-4,-5M-10,+5M-8,-5M"
DATA "-5,+3M-6,+6M-10,-3M-5,+4M-10,+4M-2,+4M+12,+10M+17,+7M+17,-1M+1,+0M-6,+15"
DATA "M+0,+4M+1,+2M-5,+15M+18,-3M+18,+4M+11,+0M+28,+14M+27,+9M-2,+10M+7,+9M+11"
DATA ",-4M-6,-4M+9,+0M-4,-3M-1,-3M+17,-5M+10,+2M+6,-9M+12,+5M+21,+14M+7,+5M+2,"
DATA "-6M+34,+13M+5,-12M-15,-14M-38,-24M-19,-11M+2,-6M-4,-4M+10,-8M-3,-8M+3,-8"
DATA "M+2,-4M-2,-4M+2,-6M-3,-8M+0,-6M-5,-1M-7,-12M-9,+3M-4,-7M-9,+6M-2,-12M-5,"
DATA "-1M-7,+10M-8,-12M-12,+11M-1,+7M-8,+9M-6,+12M-2,+10M-9,+14M-14,-1M-7,-1M-"
DATA "13,-2M-11,-1M-16,+8M-3,+5BM-1,+16M+10,+1M+2,+5BM+0,-12M+9,+2M+5,-4M-5,-4"
DATA "M-6,+3M-5,+3M+8,+1M-2,-3M+0,-2BM+145,+17M-9,-5M-12,-5M-13,-5M-9,-3M-17,+"
DATA "0M-5,+0BM+28,+31M-7,+13M+5,+1M-8,-3M-12,+2M-4,+4M-4,+9BM-23,-81M+3,-1M-1"
DATA ",-1BM+0,+1M-2,+1BM-66,+14M-4,-1M+5,+0BM+131,-51M-2,-5M-8,+5M-1,+0M-3,-11"
DATA "M-5,+0M-7,+8M-7,-10M-2,+0M-10,+10M-19,+40M-7,+2BM+21,-1BM-19,+37P4294914"
DATA "096,4278190080BM+19,-37BM-67,+28P4294914096,4278190080BM+67,-28BM-81,-5P"
DATA "4294914096,4278190080BM+81,+5"
DATA "enddata"
'bird08
DATA "BM-74,+11M-8,+4M-5,+6M-11,+4M-6,+3M-5,+5M-9,+4M-5,+13M+0,+4M+10,+2M+11,-"
DATA "6M+9,-7M+4,-3M-3,+7M+17,-1M+11,+5M+20,-1M+13,+9M+17,+9M+14,+4M+8,+3M-3,+"
DATA "6M+4,+10M+11,+1M+6,-1M+3,-3M-7,-8M+0,-2M+19,-4M+4,+2M+8,-3M+3,-4M+11,+1M"
DATA "+12,+11M+15,+9M+4,-1M+0,-3M+29,+11M+8,+0M+1,-13M-11,-9M-13,-9M-21,-12M-1"
DATA "2,-7M-18,-15M-6,-7M-15,-11M-14,-6M-11,-5M-15,-3M-11,+1M-8,+3M-6,+8M+0,+1"
DATA "1M+1,+9M+3,+0M+1,+4M+5,+3M+6,-1M+6,+5M+4,-2M+4,+2M+9,+6M+6,-7M+15,+5M+0,"
DATA "-4M+14,+3M-1,-5M+9,-2M+3,-5M-4,-8M-31,-20M-22,-7M-17,+3M-5,+1M-8,-2M-9,+"
DATA "1M+6,-1M-21,+0M-9,+5M-5,+2BM-22,+28M+8,-1M+4,+3BM+8,-7M+5,-3M+0,-2M-4,-2"
DATA "M-5,+1M+2,+6M-1,-5BM+108,+28M-6,+11M+3,+4M-4,-2M-9,-1M-12,+6M-3,+5M+0,+6"
DATA "BM-98,-36M+3,-11M-1,-9M+3,-9M+10,-8M+14,-4M+16,+2M+11,+3M+10,+0BM+25,-11"
DATA "BM+9,+22P4294914096,4278190080BM-9,-22BM-43,+32P4294914096,4278190080BM+"
DATA "43,-32BM-100,+36P4294914096,4278190080BM+100,-36BM-32,+9P4294914096,4278"
DATA "190080BM+32,-9"
DATA "enddata"
'bird12
DATA "BM-7,+11M-21,+2M-16,-3M-17,+0M-11,+2M-15,+10M-4,+6M+3,+9M-5,+11M+18,-2M+"
DATA "20,+4M+14,+5M+7,+3M+1,+24M+7,+6M+6,+7M+6,+10M+5,+8M+13,+5M+3,-6M+0,-9M+8"
DATA ",-2M+9,-7M-3,-8M+8,-1M+2,-5M-4,-7M+12,-4M+0,-9M+5,-2M+1,-11M+3,-2M+10,-1"
DATA "0M-5,-6M-12,-5BM-12,+50M+13,+0M+8,-2M+5,-5M+13,+2M+14,+16M+16,+2M-4,-4M+"
DATA "26,+11M+11,+1M+5,-8M-8,-11M-29,-19M-35,-20M-4,-2BM-150,-3M+2,+4M+4,+0M+4"
DATA ",+0M+3,+2BM+1,-8M+10,+1M+5,-5M-4,-2M-4,+0M-6,+6M+7,+2M-3,-2M+1,-1BM+126,"
DATA "+41M+0,-5BM+4,-31M-24,-12M-23,-8M-17,+0M-21,+1M-6,+0M+10,-2M-7,+0M-1,+3M"
DATA "-2,+18M+0,+15M+4,+11M-17,-6BM+36,-43M+9,+1M+10,+1M+10,+3BM-58,+41BM+1,-4"
DATA "5M+9,+2M-2,+4M+0,+0BM-9,+38M+7,+3M-3,-1M+1,+5BM+71,+7M-10,+4M+10,+1BM-76"
DATA ",-19M+4,+2M+0,+6M+0,-6M+6,+1M-3,-9BM+93,-14M-5,-3M+1,+2M-2,+3BM-56,-38BM"
DATA "+22,+44P4294914096,4278190080BM-22,-44BM+66,+57P4294914096,4278190080BM-"
DATA "66,-57BM-44,+27P4294914096,4278190080BM+44,-27BM-67,+29P4294914096,42781"
DATA "90080BM+67,-29BM-10,+13P4294914096,4278190080BM+10,-13"
DATA "enddata"
.
Pim Scheffers
Posts: 54
Joined: Jun 29, 2014 17:15

Re: Animated Birds

Post by Pim Scheffers »

Very nice,

This look and feel is so cartoonish that it would be cool if you would make a whole animated comic book this way.

greets, Pim
integer
Posts: 408
Joined: Feb 01, 2007 16:54
Location: usa

Re: Animated Birds

Post by integer »

Quark, very good!

What did you use to generate the outlines?
It looks as if the data statements would be require an enormous amount of time.

How difficult would it be to have the wings flap at different rates for each bird?

I like that. It's inspiring.
Quark
Posts: 474
Joined: May 27, 2011 18:16
Location: Pennsylvania, U.S.
Contact:

Re: Animated Birds

Post by Quark »

.
Thanks Pim & integer,

Pim, it might be a while before I do a book like that, but shorter works might well be within reach of interested FB coders/story-writers. A collaborative effort would help.

Integer,

The time for the simple background was quite short in my DRAW-string Creator program, but the time for the 4 bird-forms was longish, and the quality is not high due to wanting to get on with the demo. The DRAW-strings for them was done in my RDS_Editor from BMP images.

To get decent quality in animated images, they must be traced from BMP images created in some other program, such as MS Paint, or many other graphics programs. I work in Linux, and I found one program that is optimized to work from a series of movie frames. (I have not used that yet.)

Anyway, by speeding up the process of making the BMP trace-files, everything would be easier and of higher quality.

To get different timings and speeds for the different birds -- I did some of that by having different timings. To get different speeds, one could do it in the code I posted by tying the scale to the flap-rate.

--Quark
.
BasicCoder2
Posts: 3917
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Animated Birds

Post by BasicCoder2 »

Quark,

I think you will find that the draw string editor is still too primitive if you want anyone to use it for tracing or animation.

I notice that Inkscape has an auto trace function and you can then edit the resulting nodes however you like.

One option could be to write a program to convert the vector data generated by Inkscape into the string data used by the embedded DRAW language.

.
Quark
Posts: 474
Joined: May 27, 2011 18:16
Location: Pennsylvania, U.S.
Contact:

Re: Animated Birds

Post by Quark »

.
BasicCoder2,

I bet most readers are, by now, familiar with your views on this. "Too primitive" is of course a relative term, and depends on aspirations, which may reach beyond BASIC. My view is: show you have gone as far as possible in FB first, then go farther in some other way if desired.

Go ahead and do as you suggest, to make tracing into DRAW-strings easier for users. For myself, as regards animation, what is needed is a fast way of generating BMP files for tracing, including the conversion of movie sequences into 320x240 BMP trace-files. Come to think of it, I recall generating BMP files from movie-sequences with some program years ago. Have to look into that.

Another help would be RDS-Editors for different image sizes. Anyone who wishes to do this, with, or without, being based on what I've done, is welcome to do so. I might do something like that myself sometime. But again, there is a lot that one can do with the RDS_Editor as it is. Start small, work up. Do something impressive, top that. As Teddy Roosevelt said: do what you can, with what you have, where you are.

--Quark
.
BasicCoder2
Posts: 3917
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Animated Birds

Post by BasicCoder2 »

Quark wrote:.I bet most readers are, by now, familiar with your views on this.
From integer's questions it seems he isn't familiar with the draw string editors at all.
Go ahead and do as you suggest, to make tracing into DRAW-strings easier for users.
Well it is your project and I am only giving you feedback as to what I think a user would want in any vector tracing program regardless of its data format. At the moment I am working on another project however I just took time off to trace a gif image, using my own crude animator draw string editor, of a bird in flight to add to the draw string art gallery :) Unfortunately the originals were drawn too big and I have no way to edit their initial size so I have kept them at a scale of one in the demo.

Code: Select all

screenres 640,480,32
color rgb(0,0,0),rgb(255,255,255):cls

dim as any ptr background
background = imagecreate(1280,960,rgb(100,100,255))
dim as any ptr display
display = imagecreate(1280,960)

type BIRD
    as integer x
    as integer y
    as integer scale
    as integer frame
end type

dim as BIRD birds(1 to 6)  'six birds

for i as integer = 1 to 6
    birds(i).scale = 1
    birds(i).frame = int(rnd(1)*4)+1
    birds(i).x = int(rnd(1)*1280)
    birds(i).y = int(rnd(1)*480)+120
next i


dim shared as string ds(1 to 4)
ds(1) = ds(1) & "BM-191,+10M+0,-9M+15,-17M+18,-13M+6,-12M+17,-11"
ds(1) = ds(1) & "M+21,-2M+16,+6M+24,-9M+94,-1M+130,+30M+89,+11"
ds(1) = ds(1) & "M+19,+9M+9,+13M-30,-8M+21,+20M+4,+12M-32,-17"
ds(1) = ds(1) & "M+14,+17M+7,+21M-43,-22M+12,+27M-65,-50M-15,+12"
ds(1) = ds(1) & "M+6,+19M-33,-17M+23,+50M-47,-35M+28,+60M-37,-32"
ds(1) = ds(1) & "M+16,+57M-43,-43M+15,+59M-47,-46M+31,+72"
ds(1) = ds(1) & "M-54,-46M+21,+57M-37,-38M+7,+55M-25,-45M+3,+57"
ds(1) = ds(1) & "M-22,-39M+2,+72M-23,-66M-14,+62M-4,-50M-39,+55"
ds(1) = ds(1) & "M+20,-51M-41,+41M+17,-47M+24,-31M+11,-50"
ds(1) = ds(1) & "M+11,-47M+27,-25M+17,-19M-2,-19BM-5,+25M-43,-1"
ds(1) = ds(1) & "M-16,-2M-31,+5M-33,-1M-14,-4BM+31,-37M+19,+13"
ds(1) = ds(1) & "M+25,+5M+0,+7M-26,+16BM+26,-22M+6,+9M-1,+10"
ds(1) = ds(1) & "BM-23,-25M-2,-15M+8,-6M+10,+6M+2,+13M-1,+7"
ds(1) = ds(1) & "M-17,-4BM-1,-18M+9,+4M+4,+7M-2,+10BM+9,+19"
ds(1) = ds(1) & "M-4,+20M-53,+74M-33,+41M-6,+23M+50,-53M-8,+37"
ds(1) = ds(1) & "M+27,-32M-10,+27M+22,-25M-10,+24M+22,-22"
ds(1) = ds(1) & "M-8,+21M+16,-5BM+98,-140M-9,+26M-33,+26M-20,+35"
ds(1) = ds(1) & "M-6,+17M-3,+34BM-13,-93M-57,+56BM+175,-92"
ds(1) = ds(1) & "M+33,+19BM-56,+18M+19,+17BM-147,-84P4281808695,4278190080"
ds(1) = ds(1) & "BM-31,+17P4293294868,4278190080BM+42,+10"
ds(1) = ds(1) & "P4293294868,4278190080BM+34,-30P4282681223,4278190080"
ds(1) = ds(1) & "BM-14,+49P4279514935,4278190080BM-24,-51"
ds(1) = ds(1) & "P4290314168,4278190080"

ds(2) = ds(2) & "BM-187,+15M-2,-8M+14,-18M+17,-13M+11,-19"
ds(2) = ds(2) & "M+14,-9M+15,-2M-15,-30M-4,-22M+9,-7M+20,+4"
ds(2) = ds(2) & "M+35,+14M+5,-17M+28,-4M+46,+1M+66,+25M+64,+54"
ds(2) = ds(2) & "M+10,+24M-18,-7M+2,+35M-7,-14M+6,+47M-17,-33"
ds(2) = ds(2) & "M+7,+93M-24,-88M-13,+102M-24,-99M+2,+58M-21,+69"
ds(2) = ds(2) & "M+5,-66M-41,+121M+15,-97M-64,+119M+35,-149"
ds(2) = ds(2) & "M-4,-118M-31,-54BM+182,+59M+26,-2M+25,-5"
ds(2) = ds(2) & "M+35,+1M+43,+20M-43,-3M+30,+15M+9,+15M-36,-15"
ds(2) = ds(2) & "M+22,+24M-32,-13M+17,+21M-51,-27M-22,-6M-32,+16"
ds(2) = ds(2) & "BM-139,+15M-32,-14M-45,-3M-40,+9M-27,+2M-27,+0"
ds(2) = ds(2) & "M-5,-5BM+28,-35M+23,+9M+24,+3M+1,+8M+5,+5"
ds(2) = ds(2) & "M-1,+9BM-6,-21M-12,+15M-18,+11BM+24,-69M+20,+2"
ds(2) = ds(2) & "M+23,-11M+12,-9BM-58,-21M+19,+10M+14,+15"
ds(2) = ds(2) & "BM-41,+80M-10,+38M-42,+74M-32,+43M+76,-53"
ds(2) = ds(2) & "M-46,+68M+72,-51M-19,+60M+43,-54M-1,+60M+39,-83"
ds(2) = ds(2) & "M+4,+55M+19,-61M+7,+17BM-56,-222M+14,+28"
ds(2) = ds(2) & "M+5,+50BM-81,+7M+4,-20M+9,-4M+6,+7M+4,+14"
ds(2) = ds(2) & "M-4,+5BM-15,-20M+10,+3M+4,+8M-2,+10BM+165,-38"
ds(2) = ds(2) & "P4282681223,4278190081BM+153,+24P4282681223,4278190081"
ds(2) = ds(2) & "BM-273,+82P4280834650,4278190081BM-17,-149"
ds(2) = ds(2) & "P4280834650,4278190081BM-68,+87P4293294868,4278190081"
ds(2) = ds(2) & "BM+47,+5P4293294868,4278190081BM-12,-33P4286770175,4278190081"
ds(2) = ds(2) & "BM+0,+10P4279834905,4278190081"

ds(3) = ds(3) & "BM-195,-4M+0,-8M+39,-22M+17,-17M+29,+0M+1,-16"
ds(3) = ds(3) & "M-27,-11M-3,-14M+66,-66M+76,-36M-37,+42M+69,-23"
ds(3) = ds(3) & "M-63,+47M+70,-13M+70,-42M+43,-41M+3,+16M-26,+40"
ds(3) = ds(3) & "M+32,-6M-30,+29M+29,-5M-15,+18M+33,-18M-23,+31"
ds(3) = ds(3) & "M+28,-5M-46,+44M+55,-16M-44,+33M+50,+2M-54,+22"
ds(3) = ds(3) & "M+21,+19M-51,+3M+9,+11M-41,-11M+20,+18M-49,-11"
ds(3) = ds(3) & "BM+105,-16M+67,-42M+17,-3M-27,+23M+35,-3"
ds(3) = ds(3) & "M-36,+27M+28,+2M-24,+15M+7,+14M-68,-4M-59,+28"
ds(3) = ds(3) & "M-76,+7M-62,-11M-28,-10M-54,-4M-51,-9M-22,-6"
ds(3) = ds(3) & "M-4,-6BM+84,-44M+14,+9M+12,-4M+0,+0M+0,-11"
ds(3) = ds(3) & "M+43,-32M+88,-54BM-131,+98M+10,+9M+1,+18"
ds(3) = ds(3) & "BM-7,-101M-20,+16M-8,+18M+14,+7BM+116,-22"
ds(3) = ds(3) & "M-54,+31BM+189,+43M+14,-2BM-327,-7M+13,+16"
ds(3) = ds(3) & "M+26,+14M+5,+10M-5,+12BM-28,-7M+28,-13BM-17,-10"
ds(3) = ds(3) & "M+0,-14M+9,-8M+9,+5M+1,+12M-3,+15BM-15,-22"
ds(3) = ds(3) & "M+8,-4M+5,+4M+2,+14M-4,+3BM+210,-53P4282681223,4278190082"
ds(3) = ds(3) & "BM-139,-55P4279514935,4278190082BM-111,+104"
ds(3) = ds(3) & "P4293294868,4278190082BM+41,+18P4293294868,4278190082"
ds(3) = ds(3) & "BM+1,-35P4286770175,4278190082BM-6,+10P4279834905,4278190082"

ds(4) = ds(4) & "BM-193,-2M+0,-10M+38,-22M+14,-13M+34,-4M+13,+8"
ds(4) = ds(4) & "M+31,-11M+25,+0M+69,-3M+110,+35M+111,-19"
ds(4) = ds(4) & "M-28,+15M+42,+6M-20,+11M+16,+6M-19,+8M+14,+13"
ds(4) = ds(4) & "M-39,-2M-42,-14M-29,+6M+23,+17M-29,+6M-27,-7"
ds(4) = ds(4) & "M+30,+26M-48,-2M+29,+18M-60,-11M+10,+22M-50,-16"
ds(4) = ds(4) & "M+15,+19M-47,-4M-42,-27M-20,-33M-31,+0M-41,+17"
ds(4) = ds(4) & "M-30,+8M-48,-9M+13,-4M-43,-21M+68,+7M+13,-6"
ds(4) = ds(4) & "M-17,-6M-8,-4BM+32,-29M+12,+4M+14,+13M+19,+6"
ds(4) = ds(4) & "M+2,+14M-4,+9BM+19,+1M-48,-1M-23,-8M+0,+0"
ds(4) = ds(4) & "BM+55,-11M-33,+15BM+11,-25M+1,-14M+10,-5"
ds(4) = ds(4) & "M+8,+2M+2,+10M-3,+15BM-16,-19M+8,-4M+6,+6"
ds(4) = ds(4) & "M-1,+8M-3,+7BM+61,-11M+17,+3M+0,+8M-15,+8"
ds(4) = ds(4) & "M-11,+8M+7,+13BM+52,-35M+1,+11M-4,+10BM-13,+14"
ds(4) = ds(4) & "M+9,+18M+13,+12BM+39,-46P4282681223,4278190083"
ds(4) = ds(4) & "BM-212,+21P4280834650,4278190083BM+25,-35"
ds(4) = ds(4) & "P4293294868,4278190083BM+27,-11P4279834905,4278190083"
ds(4) = ds(4) & "BM+7,-8P4286770175,4278190083"

dim as double frameRate
frameRate = 0.1
dim as double now1
now1 = timer

do
    
    if timer > now1 + frameRate then
        now1 = timer
        'clear display
        put display,(0,0),background,pset
        for i as integer = 1 to 6
            DRAW display,"BM" & birds(i).x & "," & birds(i).y
            DRAW display,"S" & birds(i).scale
            DRAW display,"C" & str(4278190079+birds(i).frame)
            DRAW display, ds(birds(i).frame)
            screenlock
            put (0,0),display,(320,240)-(320+640,240+480),pset
            screenunlock
            'update frame
            birds(i).frame = birds(i).frame + 1
            if birds(i).frame > 4 then
                birds(i).frame = 1
            end if
            'update position
            birds(i).x = birds(i).x - 16
            'new bird position
            if birds(i).x < 0 then
                birds(i).x = 1280-int(rnd(1)*320)
                birds(i).y = int(rnd(1)*480)+120
            end if
        next i
    end if
    sleep 2
loop until multikey(&H01)
Quark
Posts: 474
Joined: May 27, 2011 18:16
Location: Pennsylvania, U.S.
Contact:

Re: Animated Birds

Post by Quark »

.
Thanks for doing the flying birds, BasicCoder2.

As you say, it is a nice addition to the DRAW-string art gallery. Most welcome.

--Quark

.
Post Reply