Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Screensaver
#2
These can be screensavers if they are renamed to scr (I think). I have however not done any fancy stuff with winapi and cli switches (since I'm on linux :p)
They do also not quit on mouse movement, but by pressing the any-key.
I've recently posted them on freebasic.net/forum but i think this is a good reason to repost them (The versions might differ slightly)
Both requires cvs (for "FOR x AS INTEGER = ..." and transparent drawing primitives)
Enjoy Smile
Code:
' Bouncing circles, by red_Marvin/insomninja 061219 - edited 070101
' A number of points randomly bounces around on the screen and if point #n is close enough to point #0 a circle is drawn
' at the center of point #n with the distance as radius. If the point is even closer a filled circle is drawn in the
' same way with a slowly cycling color and the opacity depending on the distance.

type point2d
    x as single
    y as single
    xa as single
    ya as single
end type
dim as point2d p(0 to 199)
dim as single r,a
dim as double t
dim as integer ar,x,y,ox,oy,c,rc,gc,bc
randomize timer
for n as integer=0 to 199
    p(n).x=rnd*1024
    p(n).y=rnd*768
    while abs(p(n).xa)<1 or abs(p(n).ya)<1
        p(n).xa=(rnd-rnd)*2
        p(n).ya=(rnd-rnd)*2
    wend
next
screenres 1024,768,32,1,&h41
setmouse ,,0
a=rnd*360
do
    rc=(sin(a/360*3.141592654*2)+1)*127
    gc=(sin((a+120)/360*3.141592654*2)+1)*127
    bc=(sin((a+240)/360*3.141592654*2)+1)*127
    a+=.1
    if a>360 then a-=360
    screenlock
        cls
        p(0).x+=p(0).xa
        p(0).y+=p(0).ya
        if p(0).x<=0 then p(0).xa=rnd+1
        if p(0).y<=0 then p(0).ya=rnd+1
        if p(0).x>=1023 then p(0).xa=-rnd-1
        if p(0).y>=767 then p(0).ya=-rnd-1
        getmouse x, y
        if x<>ox or y<>oy or (timer<t and c=1) then
                p(0).x=x
                p(0).y=y
                if c=0 then
                    c=1
                    t=timer+3
                end if
        else
            c=0
        end if
        ox=x
        oy=y
        for n as integer = 1 to 199
            p(n).x+=p(n).xa
            p(n).y+=p(n).ya
            if p(n).x<=-100 then p(n).xa=rnd+1
            if p(n).y<=-100 then p(n).ya=rnd+1
            if p(n).x>=1123 then p(n).xa=-rnd-1
            if p(n).y>=867 then p(n).ya=-rnd-1
            r=(p(n).y-p(0).y)^2+(p(n).x-p(0).x)^2
            ar=r\32
            if ar<255 then
                circle(p(n).x,p(n).y),sqr(r),rgba(rc,gc,bc,255-ar),,,,f
            end if
            ar=r\2048
            if ar<32 then
                circle(p(n).x,p(n).y),sqr(r),rgba(255,255,255,32-ar)
            end if
        next
    screenunlock
    sleep 50
loop while inkey=""

Code:
' Bouncing triangles red_Marvin/insomninja 061219 - edited 070101
' A number of points randomly bounces around on the screen and if point the distance between point #n and #0 multiplied
' with the distance between point #0 and #n+60 a triangle is drawn between the three points. If the number is even smaller
' the triangle is filled with a cycling color and opacity depending on said number.

declare sub triangle(x1 as integer, y1 as integer, x2 as integer, y2 as integer, x3 as integer, y3 as integer, clr as integer)
declare sub swapi(a as integer ptr, b as integer ptr)

type point2d
    x as single
    y as single
    xa as single
    ya as single
end type

dim as point2d p(0 to 120)
dim as double t
dim as single a
dim as integer x,y,ox,oy,c,rc,gc,bc,px,py
dim as double s,ms
randomize timer
for n as integer=0 to 120
    p(n).x=rnd*1024
    p(n).y=rnd*768
    while abs(p(n).xa)<1 or abs(p(n).ya)<1
        p(n).xa=(rnd-rnd)*2
        p(n).ya=(rnd-rnd)*2
    wend
next
screenres 1024,768,32,1,&h41
setmouse ,,0
a=rnd*360
do
    rc=(sin(a/360*3.141592654*2)+1)*127
    gc=(sin((a+120)/360*3.141592654*2)+1)*127
    bc=(sin((a+240)/360*3.141592654*2)+1)*127
    a+=.1
    if a>360 then a-=360
    screenlock
        cls
        p(0).x+=p(0).xa
        p(0).y+=p(0).ya
        if p(0).x<=0 then p(0).xa=rnd+1
        if p(0).y<=0 then p(0).ya=rnd+1
        if p(0).x>=1023 then p(0).xa=-rnd-1
        if p(0).y>=767 then p(0).ya=-rnd-1
        getmouse x, y
        if x<>ox or y<>oy or (timer<t and c=1) then
                p(0).x=x
                p(0).y=y
                if c=0 then
                    c=1
                    t=timer+3
                end if
        else
            c=0
        end if
        ox=x
        oy=y
        for n as integer = 1 to 60
            p(n).x+=p(n).xa
            p(n).y+=p(n).ya
            if p(n).x<=-100 then p(n).xa=rnd+1
            if p(n).y<=-100 then p(n).ya=rnd+1
            if p(n).x>=1123 then p(n).xa=-rnd-1
            if p(n).y>=867 then p(n).ya=-rnd-1
            p(n+60).x+=p(n+60).xa
            p(n+60).y+=p(n+60).ya
            if p(n+60).x<=-100 then p(n+60).xa=rnd+1
            if p(n+60).y<=-100 then p(n+60).ya=rnd+1
            if p(n+60).x>=1123 then p(n+60).xa=-rnd-1
            if p(n+60).y>=867 then p(n+60).ya=-rnd-1
            
            s=sqr(  ((p(0).x-p(n).x)^2  +  (p(0).y-p(n).y)^2  )* (  (p(0).x-p(n+60).x)^2  +  (p(0).y-p(n+60).y)^2  ))

            ms=s\512
            if ms<255 then
                triangle p(0).x, p(0).y, p(n).x, p(n).y, p(n+60).x, p(n+60).y, rgba(rc,gc,bc,255-ms)
                px=p(n).x
                py=p(n).y
                draw string (px,py), "("+str(px)+";"+str(py)+")",rgba(255,255,255,31)
                line(px-10,py)-(px+10,py),rgba(255,255,255,31)
                line(px,py-10)-(px,py+10),rgba(255,255,255,31)
                px=p(n+60).x
                py=p(n+60).y
                draw string (px,py), "("+str(px)+";"+str(py)+")",rgba(255,255,255,31)
                line(px-10,py)-(px+10,py),rgba(255,255,255,31)
                line(px,py-10)-(px,py+10),rgba(255,255,255,31)
            end if
            ms=s\32768
            if ms<32 then
                line(p(0).x,p(0).y)-(p(n).x,p(n).y),rgba(255,255,255,32-ms)
                line(p(0).x,p(0).y)-(p(n+60).x,p(n+60).y),rgba(255,255,255,32-ms)
                line(p(n).x,p(n).y)-(p(n+60).x,p(n+60).y),rgba(255,255,255,32-ms)
            end if
        next
        line(p(0).x-10,p(0).y)-(p(0).x+10,p(0).y),rgba(255,255,255,127)
        line(p(0).x,p(0).y-10)-(p(0).x,p(0).y+10),rgba(255,255,255,127)
    draw string (p(0).x,p(0).y), "("+str(cint(p(0).x))+";"+str(cint(p(0).y))+")",rgba(255,255,255,127)
    screenunlock
    sleep 50
loop while inkey=""





sub triangle(x1 as integer, y1 as integer, x2 as integer, y2 as integer, x3 as integer, y3 as integer, clr as integer)
    dim as single xm12, xm13, xm23
    dim as single xa,xb
    if y2<y1 then swapi @x1, @x2 : swapi @y1, @y2
    if y3<y1 then swapi @x1, @x3 : swapi @y1, @y3
    if y3<y2 then swapi @x2, @x3 : swapi @y2, @y3
    if cint(y2)>cint(y1) then
        xm12=(x2-x1)/(y2-y1)
        xm13=(x3-x1)/(y3-y1)
        xa=x1
        xb=x1
        for y as integer = cint(y1) to cint(y2)-1
            line (xa,y)-(xb,y),clr
            xa+=xm12
            xb+=xm13
        next
    else
        xa=x2
        xb=x1    
    end if
    line (xa,y2)-(xb,y2),clr
    if cint(y2)<cint(y3) then
        xm13=(x3-x1)/(y3-y1)
        xm23=(x3-x2)/(y3-y2)
        for y as integer = cint(y2)+1 to cint(y3)
            xa+=xm23
            xb+=xm13
            line (xa,y)-(xb,y),clr
        next
    end if
end sub


sub swapi(a as integer ptr, b as integer ptr)
    dim t as integer
    t=*a
    *a=*b
    *b=t
end sub

EDIt: Come on! More entries!
/post]
Reply


Messages In This Thread
Screensaver - by Skyler - 01-01-2007, 03:06 AM
Screensaver - by red_Marvin - 01-02-2007, 03:25 AM
Screensaver - by Skyler - 01-02-2007, 06:42 AM
Screensaver - by Dr_Davenstein - 01-02-2007, 07:02 AM
Screensaver - by Skyler - 01-02-2007, 07:36 PM
Screensaver - by Skyler - 01-06-2007, 03:02 AM
Screensaver - by red_Marvin - 01-08-2007, 04:27 AM
Screensaver - by Skyler - 01-08-2007, 06:11 AM
Screensaver - by Dr_Davenstein - 01-08-2007, 06:31 AM
Screensaver - by Skyler - 01-08-2007, 07:54 PM
Screensaver - by Skyler - 02-01-2007, 06:59 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)