Liberty BASIC Community Forum
Special Topics and Projects >> Game and Graphic Programming >> Dwawing wipples ( ripples with a lisp..)
http://libertybasic.conforums.com/index.cgi?board=game&action=display&num=1448927696

Dwawing wipples ( ripples with a lisp..)
Post by tenochtitlanuk on Nov 30th, 2015, 5:54pm

Twenty minutes of coding gave me the code that produced lots of 'lovely' screens like this.
User Image
I call them ripples because if you make the radius go up by 4 rather than two they LOOK like ripples In a can of paint. After taking LSD. Perhaps!
Each circle grows outwards.
Each left-mouse-click creates a new one.
Ex-or plotting and serendipity does the rest
Code:
    nomainwin

    WindowWidth  =800
    WindowHeight =800

    button #w.b, "Save", [saveScreen], LR, 50, 640

    open "Growing circles" for graphics_nsb as #w

    #w "trapclose [quit]"
    #w "size 2 ; down ; fill 50 50 50 ; flush"
    #w "when leftButtonUp [newCentre]"
    #w "rule _R2_NOTXORPEN"

    numDrops =0

    N =40
    dim startX( N), startY( N), radius( N), color$( N)

    startX( 0) =400: startY( 0) =400: radius( 0) =2: color$( 0) ="200 200 40"
    timer 500, [growThem]

    wait

  [quit]
    close #w
    end

  [growThem]
    scan
    for i =0 to numDrops
        #w "up; goto "; startX( i); " "; startY( i); " ; down ; color "; color$( i); " ; circle "; radius( i)
        if radius( i) <400 then radius( i) =radius( i) +2
    next i
    wait

  [newCentre]
    if numDrops <N then '   create a new one
        numDrops =( numDrops +1)
        startX( numDrops) =MouseX: startY( numDrops) =MouseY: radius( numDrops) =2: color$( numDrops) =randCol$()
    else    '   kill one and replace by new one
        r =int( N *rnd( 1))
        startX( r) =MouseX: startY( r) =MouseY: radius( r) =2: color$( r) =randCol$()
    end if
    wait

    function randCol$()
        randCol$ =str$( int( 256 *rnd( 1))) +" " +str$( int( 256 *rnd( 1))) +" " +str$( int( 256 *rnd( 1)))
    end function

  [saveScreen]
    #w "getbmp scr 1 1 800 800"
    bmpsave "scr", "wipple-" +str$( time$( "seconds")) +".bmp"
    wait
 

Re: Dwawing wipples ( ripples with a lisp..)
Post by tsh73 on Dec 1st, 2015, 02:00am

It overlap in really nice 3d-ish way.
Still can't understand how drawining circles produce us stright lines?
Re: Dwawing wipples ( ripples with a lisp..)
Post by tenochtitlanuk on Dec 1st, 2015, 02:25am

RR points out that it is a way of specifying XOR that fails. Omit the line! I was playing with what to do when the lines overlap.
BUT the LB Help says...
Code:
print #handle, "rule "; _R2_NOTXORPEN
This command specifies whether drawing overwrites (rulename OVER) graphics already on the screen or uses the exclusive-OR technique (rulename XOR). It is also possible to use Windows constants to select a drawing rule (as shown above). Here are the constants that Windows defines:
_R2_BLACK
_R2_WHITE
_R2_NOP
_R2_NOT
_R2_COPYPEN <- the default LB drawing rule
_R2_NOTCOPYPEN
_R2_MERGEPENNOT
_R2_MASKPENNOT
_R2_MERGENOTPEN
_R2_MASKNOTPEN
_R2_NOTMERGEPEN
_R2_MASKPEN
_R2_NOTMASKPEN
_R2_XORPEN
_R2_NOTXORPEN <- the xor LB drawing rule 

ie the last two lines seem swapped!
Re: Dwawing wipples ( ripples with a lisp..)
Post by tenochtitlanuk on Dec 1st, 2015, 02:54am

Easy to modify to show Moire effects.. or simulate a 'Ripple tank' demo of wave motion...
User Image
Re: Dwawing wipples ( ripples with a lisp..)
Post by tsh73 on Dec 1st, 2015, 04:10am

>> ie the last two lines seem swapped!
I remember XORPEN and NOTXORPEN somehow related to drawing on black or on white... (so LB default is to draw on white)
yes yes
XOPRPEN first time draws un-changed colors on black, on secont draw operation restores black.
While LB default NOTXORPEN first time draws un-changed colors on WHITE, on secont draw operation restores it.
Re: Dwawing wipples ( ripples with a lisp..)
Post by bluatigro on Dec 3rd, 2015, 06:42am

whit 2 rasters of point

also you get somthing nice

Code:
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
nomainwin
open "moiere" for graphics as #m
  #m "trapclose [quit]"
  for x = -100 to 100
    for y = -100 to 100
      sx = x * 3
      sy = y * 3
      call punt winx/2 + sx , winy/2 + sy
      call rotate sx , sy , 0.1
      call punt winx/2 + sx , winy/2 + sy
    next y
  next x
wait
sub rotate byref k , byref l , r
  s = sin( r )
  c = cos( r )
  hk = k * c - l * s
  hl = k * s + l * c
  k = hk
  l = hl
end sub
sub punt x , y
  #m "goto " ; int(x) ; " " ; int(y)
  #m "down"
  #m "set " ; int(x) ; " " ; int(y)
  #m "up"
end sub
[quit]
  close #m
end
 

Re: Dwawing wipples ( ripples with a lisp..)
Post by tenochtitlanuk on Dec 3rd, 2015, 1:46pm

For anyone inspired by Moire patterns, have a look at http://www.herocomm.com/Details/MoireStory.htm
Easy to create in LB, at least as good as the originals. Print some on laser/inkjet transparency sheets and superpose.
I got hooked via CT Stong/Scientfic American way, way back.....
Re: Dwawing wipples ( ripples with a lisp..)
Post by tenochtitlanuk on Dec 4th, 2015, 2:46pm

Just a quick demo of typical Moire sheets- one on transparency film- and the superposition patterns.
User Image