Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
USA Flag
#1
Waving and shaded 3D US flag.  Drawn according to official specification

Code: (Select All)
deflng a-z

sw = 640
sh = 480

dim shared pi as double
pi = 4*atn(1)

screen _newimage(sw*2, sh, 32)

h = 300
w = 1.9*h
a = h/7

img = _newimage(w, h, 32)
_dest img
x0 = 0
y0 = 0

line (0, 0)-step(w, h),_rgb(255,255,255),bf
for i=0 to 6
        line (0, i*h*2/13)-step(w, h/13),_rgb(255*0.698,255*0.132,255*0.203),bf
next
line (0, 0)-step(w*2/5, h*7/13),_rgb(255*0.234,255*0.233,255*0.430),bf

for i=0 to 4
for j=0 to 5
        starf (j*2 + 1)*w*2/(5*12), (i*2 + 1)*h*7/130, h*4/(13*5*2), _rgb(255,255,255)
next
next

for i=1 to 4
for j=1 to 5
        starf (j*2)*w*2/(5*12), (i*2)*h*7/130, h*4/(13*5*2), _rgb(255,255,255)
next
next

_dest 0
_putimage (sw/2 - w/2, sh/2 - h/2), img
_source img

x0 = sw/2 - w/2 + sw
y0 = sh/2 - h/2 '+ sh

dim t as double
dim z as double

dim xx as double, yy as double
dim dx as double, dy as double
do
        t = t + 0.2

        line (sw,0)-step(sw, sh),_rgb(0,0,0),bf

        for y=0 to h + a*0.707 step 1
        for x=0 to w + a*0.707 step 1
                z = (0.1 + 0.4*(x/w))*a*sin(x/35 - y/70 - t) + 0.5*a
                dz = 50*a*cos(x/35 - y/70 - t)/35

                xx = x + z*0.707 - a*0.707
                yy = y - z*0.707

                if (int(xx) >=0 and int(xx) < w - 1 and int(yy) >= 0 and int(yy) < h - 1) then
                        tl = point(int(xx), int(yy))
                        tr = point(int(xx) + 1, int(yy))
                        bl = point(int(xx), int(yy) + 1)
                        br = point(int(xx) + 1, int(yy) + 1)

                        dx = xx - int(xx)
                        dy = yy - int(yy)

                        r =_round((1 - dy)*((1 - dx)*  _red(tl) + dx*  _red(tr)) + dy*((1 - dx)*  _red(bl) + dx*  _red(br)))
                        g = _round((1 - dy)*((1 - dx)*_green(tl) + dx*_green(tr)) + dy*((1 - dx)*_green(bl) + dx*_green(br)))
                        b = _round((1 - dy)*((1 - dx)* _blue(tl) + dx* _blue(tr)) + dy*((1 - dx)* _blue(bl) + dx* _blue(br)))

                        r = r + dz
                        g = g + dz
                        b = b + dz

                        if r<0 then r = 0
                        if r>255 then r = 255
                        if g<0 then g = 0
                        if g>255 then g = 255
                        if b<0 then b = 0
                        if b>255 then b = 255

                        pset (x0 + x, y0 - a*0.707 + y), _rgb(r,g,b)
                end if
        next
        next

        _display
        _limit 50
loop until _keyhit = 27

sleep
system

sub starf(x, y, r, c)
        pset (x + r*cos(pi/2), y - r*sin(pi/2)),c
        for i = 0 to 5
                xx = r*cos(i*4*pi/5 + pi/2)
                yy = r*sin(i*4*pi/5 + pi/2)
                line -(x + xx, y - yy),c
        next
        paint (x, y),c
        for i = 0 to 5
                xx = r*cos(i*4*pi/5 + pi/2)/2
                yy = r*sin(i*4*pi/5 + pi/2)/2
                paint (x + xx, y - yy),c
        next
end sub
Reply


Messages In This Thread
USA Flag - by vince - 04-21-2022, 10:35 PM
RE: USA Flag - by Jack - 04-21-2022, 10:40 PM
RE: USA Flag - by Pete - 04-21-2022, 10:54 PM
RE: USA Flag - by Dav - 04-21-2022, 11:23 PM
RE: USA Flag - by Pete - 04-22-2022, 05:57 PM
RE: USA Flag - by Dimster - 04-22-2022, 06:53 PM
RE: USA Flag - by Pete - 04-22-2022, 07:20 PM
RE: USA Flag - by SierraKen - 04-23-2022, 07:14 PM



Users browsing this thread: 1 Guest(s)