Author Topic: Recurring Ellipsii  (Read 2393 times)

B+

  • Guest
Recurring Ellipsii
« on: July 14, 2016, 01:45:59 AM »
Code: [Select]
'recurring ellipsii.sdlbas  [B+=MGA] 2016-07-13
'extending Administrator's code example at SdlBasic forum

sw = 800 : sh = 600
setdisplay(sw, sh, 32, 1)
setcaption("Recurring Ellipsii")
autoback(-2)
sub drawEllipsii(x, y, w, h, oset)
ellipse(x, y, w, h)
if(h > 15) then
ink(0x800000)
drawEllipsii(x + w/2*oset, y, w/2*oset, h/2*oset, oset)
ink(0x0000ff)
drawEllipsii(x - w/2*oset, y, w/2*oset, h/2*oset, oset)
ink(0x008000)
drawEllipsii(x, y + h/2*oset, w/2*oset, h/2*oset, oset)
ink(0xffff00)
drawEllipsii(x, y - h/2*oset, w/2*oset, h/2*oset, oset)
end if
end sub

oset = 0 : dr = 1
while 1
cls
ink(0xffffff)
drawEllipsii(sw/2, sh/2, sw/2, sh/2, oset)
screenswap
wait(60)
oset += .01 * dr
if oset >= 1.01 then
dr = dr * -1
elseif oset <= 0 then
dr = dr * -1
end if
wend
« Last Edit: July 14, 2016, 02:14:52 AM by B+ »

B+

  • Guest
Rect gasket yo-yo.bas
« Reply #1 on: July 14, 2016, 01:48:39 AM »
Same principle with rectangles in SmallBASIC:

Code: [Select]
'rect gasket yo-yo.bas for SmallBASIC 0.12.6 [B+=MGA] 2016-07-13

sub drawrect(x, y, w, h, oset)
  rect x,y step w, h
  if h > 10 then
    color 12
    drawrect x - oset * w, y - oset * h, 2 * oset * w, 2 * oset * h, oset
    color rgb(0,128,0)
    drawrect x + w - oset * w, y - oset * h, 2 * oset * w, 2 * oset * h, oset
    color 9
    drawrect x - oset * w, y +  h - oset * h, 2 * oset * w, 2 * oset * h, oset
    color 14
    drawrect x +  w  - oset * w, y +  h - oset * h, 2 * oset * w, 2 * oset * h, oset
  fi
end
oset = 0 : dir = 1
while 1
  cls
  color 15
  drawrect .25 * xmax, .25 * ymax, .5 * xmax, .5 * ymax, oset
  showpage
  delay 60
  oset +=.01 * dir
  if oset = .25 then dir = dir * -1
  if oset = 0 then dir = dir * -1
wend

Peter

  • Guest
Re: Recurring Ellipsii
« Reply #2 on: July 15, 2016, 06:23:38 PM »
Code: [Select]
'recurring ellipsii.sdlbas  [B+=MGA] 2016-07-13
'extending Administrator's code example at SdlBasic forum
'Ported to BaCon by PvE / 2016-07-15

INCLUDE canvas-gd.bac
OPTION VARTYPE double

sw = 600 : sh = 450

WINDOW("Recurring Ellipsii", sw, sh)

SUB drawEllipsii(x, y, w, h, oset)
    CIRCLE(x, y, w, h, 0)
    IF h > 15 THEN
        INK(0x80, 0x00, 0x00, 0xff)
        drawEllipsii(x + w/2*oset, y, w/2*oset, h/2*oset, oset)
        INK(0x00, 0x00, 0xff, 0xff)
        drawEllipsii(x - w/2*oset, y, w/2*oset, h/2*oset, oset)
        INK(0x00, 0x80, 0x00, 0xff)
        drawEllipsii(x, y + h/2*oset, w/2*oset, h/2*oset, oset)
        INK(0xff, 0xff, 0x00, 0xff)
        drawEllipsii(x, y - h/2*oset, w/2*oset, h/2*oset, oset)
    ENDIF
ENDSUB

oset = 0 : dr = 1

SUB Draw
    INK(0x0, 0x0, 0x0, 0xff)
    CLS
    INK(0xff, 0xff, 0xff, 0xff)
    drawEllipsii(sw/2, sh/2, sw/2, sh/2, oset)
    INCR oset, .01 * dr
    IF oset >= 1.01 THEN
        dr = dr * -1
    ELIF oset <= 0 THEN
        dr = dr * -1
    ENDIF
END SUB

CALLBACK(60, Draw)
FRAMES(200)
WAITKEY

« Last Edit: July 15, 2016, 06:32:18 PM by Peter »

B+

  • Guest
Re: Recurring Ellipsii
« Reply #3 on: July 15, 2016, 07:12:31 PM »
 :) hey Peter! that's better than a snapshot!

Peter

  • Guest
Re: Recurring Ellipsii
« Reply #4 on: July 16, 2016, 08:29:25 AM »
Thanks! I have updated the GD canvas a little bit, now the program is almost similar to the original.

Regards
Peter

Code: [Select]
'recurring ellipsii.sdlbas  [B+=MGA] 2016-07-13
'extending Administrator's code example at SdlBasic forum
'Ported to BaCon by PvE / 2016-07-15 - version 2

INCLUDE canvas-gd.bac
OPTION VARTYPE double

sw = 600 : sh = 450

WINDOW("Recurring Ellipsii", sw, sh)

FRAMES(200) : ' How many frames in this GIF
DELAY(60)   : ' Delay in msecs between the frames

SUB drawEllipsii(x, y, w, h, oset)
    CIRCLE(x, y, w, h, 0)
    IF h > 15 THEN
        INK(0x80, 0x00, 0x00, 0xff)
        drawEllipsii(x + w/2*oset, y, w/2*oset, h/2*oset, oset)
        INK(0x00, 0x00, 0xff, 0xff)
        drawEllipsii(x - w/2*oset, y, w/2*oset, h/2*oset, oset)
        INK(0x00, 0x80, 0x00, 0xff)
        drawEllipsii(x, y + h/2*oset, w/2*oset, h/2*oset, oset)
        INK(0xff, 0xff, 0x00, 0xff)
        drawEllipsii(x, y - h/2*oset, w/2*oset, h/2*oset, oset)
    ENDIF
ENDSUB

oset = 0 : dr = 1

WHILE TRUE
    INK(0x0, 0x0, 0x0, 0xff)
    CLS
    INK(0xff, 0xff, 0xff, 0xff)
    drawEllipsii(sw/2, sh/2, sw/2, sh/2, oset)
    IF NOT(SYNC()) THEN QUIT
    INCR oset, .01 * dr
    IF oset >= 1.01 THEN
        dr = dr * -1
    ELIF oset <= 0 THEN
        dr = dr * -1
    ENDIF
WEND