Author Topic: Dotty Patterns  (Read 3326 times)

0 Members and 2 Guests are viewing this topic.

Peter

  • Guest
Dotty Patterns
« on: April 29, 2014, 03:10:14 AM »
Deleted.
« Last Edit: January 28, 2015, 04:26:00 AM by Peter »

Mike Lobanovsky

  • Guest
Re: Dotty Patterns
« Reply #1 on: April 29, 2014, 03:54:58 AM »
Aurel will like them. :)

P.S. Aha! At first I didn't notice they are already attributed. Isn't that a sign of public recognition to see your code being ported to another language. :)

Aurel

  • Guest
Re: Dotty Patterns
« Reply #2 on: April 29, 2014, 06:55:37 AM »
 Thanks Peter  & Mike  :)
Here is my code in Oxygen:

Code: [Select]
'gui-skeleton app
$ Filename "buffered.exe"
Include "RTL32.inc"
Include "awinh.inc"

#lookahead
INT fseed = 0x12345678 ' seed number
INT win
INT w,h
w=800:h=600
INT winstyle
winstyle = WS_MINMAXSIZE or WS_CLIPCHILDREN
'##### GLOBALS  ###############################################
INT hdc, hdcMem, hbmMem,   oldBmp, oldBrush, oldPen, oldFont, fColor
INT textX,textY,hBrush
String tBuffer
'##############################################################
'create window *************************************************
win = SetWindow("Double Buffered Window",0,0,w,h,0,winstyle)
'**************************************************************
InitDrawing()
Int n,count,fc,fb
Float ww,wh,a,b,c,x,y,j,dots,xfocus,yfocus
'set window color - dark blue
WindowColor(win,0,0,0)

xfocus = w * 0.47
yfocus = h * 0.45

again:
   count = count + 1
WindowColor(win,0,0,0)
random = RAND(0,5)

FOR rep=1 TO random
' set up some random starting positions ..
a = RND2(1.0)
b = 0.9998
c = 2 - 2 * a

dots = 2000

x = 0
j = 0
y = RND2(1.0)*12 + 0.1

' calculate and draw the points ..
FOR i=0 TO dots

z = x
x = b * y + j
j = a * x + c * (x*x)/(1 + x*x)
y = j - z
xpos = x*20 + xfocus
ypos = y*20 + yfocus

rr = RAND(0,255)
gg = RAND(0,255)
bb = RAND(0,255)
         fc=RGB(rr,gg,bb):fb=RGB(0,0,0)
TextColor win,fc,fb
Pset win,xpos,ypos
NEXT i

NEXT rep

if count < 5
goto again
end if



'/////////
Wait()
'\\\\\\\\\

Function WndProc (sys hwnd,wmsg,wparam,lparam) as sys callback

SELECT hwnd
'----------------------------------------
CASE win
'----------------------------------------
Select wmsg

CASE WM_CLOSE
DestroyWindow win
'Clean DC objects
CleanUp()
PostQuitMessage 0

CASE WM_SIZE
'get current size of window
GetSize(win,0,0,w,h)
int bColor = RGB(0,0,80)
FillSolidRect(win,0,0,w,h,bColor)

',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
CASE WM_PAINT
' blit the now completed screen view back to the window...
BitBlt(hDC, 0, 0, w, h, hdcMem, 0, 0, SRCCOPY)



END SELECT

END SELECT

RETURN Default

END FUNCTION
'----------------------------------------------------
'##########################################################
SUB TextColor (wID as INT,byval frontColor as sys,byval  backColor as sys )
hdc = GetDC(wID)

fColor=frontColor

SetTextColor( hDC, frontColor)
SetBkColor( hDC, backColor)

BitBlt(hDCmem, 0, 0, w, h, hdc, 0, 0, SRCCOPY)

ReleaseDC( wID, hdc)

END SUB
'########################################################

SUB TextOn(wID as INT,tx as INT,ty as INT,txt as string)

hdc = GetDC(wID)

'draw text to screen DC
TextOut hdc,tx,ty,txt,Len(txt)

'blit screen DC to memDC
BitBlt(hDCmem, 0, 0, w, h, hdc, 0, 0, SRCCOPY)

ReleaseDC( wID, hdc)

END SUB
 
'-------------------------------------------------

SUB Pset (wID as int , px as int ,py as int)
hdc = GetDC(wID)

SetPixel ( hdc, px, py, fColor)

BitBlt(hDCmem, 0, 0, w, h, hdc, 0, 0, SRCCOPY)

ReleaseDC( wID, hdc)

END SUB
'----------------------------------------------------------------

SUB LineXY (wID as INT,Lx as INT,Ly as INT,Lx1 as INT,Ly1 as INT)

hdc = GetDC(wID)
SelectObject(hdc, CreatePen(PS_SOLID,1,fColor))
MoveToEx (hdc,Lx,Ly,ByVal 0)
LineTo (hdc,Lx1,Ly1)

BitBlt(hDCmem, 0, 0, w, h, hdc, 0, 0, SRCCOPY)

ReleaseDC( wID, hdc)


END SUB

'----------------------------------------------------------
' set window color
Sub FillSolidRect(wID as INT, x As Long, Y As Long, cx As Long, cy As Long, bColor as INT)
    Dim hBr As Long ' rc As RECT
    hDC=GetDC(wID)
    rc.Left = x
    rc.Top = Y
    rc.right = x + cx
    rc.bottom = Y + cy
    hBr = CreateSolidBrush(bColor)
    FillRect hDC, rc, hBr

    BitBlt(hDCmem, 0, 0, w, h, hdc, 0, 0, SRCCOPY)

    ReleaseDC( wID, hdc)
End Sub
'----------------------------------------------------------
SUB WindowColor(wID as INT,wr as INT,wg as INT,wb as INT)
INT backColor = RGB (wr,wg,wb)
FillSolidRect(wID,0,0,w,h,backColor)

END SUB

'------------------------------------------------------
SUB InitDrawing
''get current size of window
GetSize(win,0,0,w,h)
'get window DC
hdc=GetDC(win)
hdcMem = CreateCompatibleDC(0)
hbmMem = CreateCompatibleBitmap(hdc, w, h)
oldBmp = SelectObject( hdcMem, hbmMem )
oldBrush = SelectObject(hdcMem, CreateSolidBrush( RGB(231,223,231)) )
oldPen = SelectObject(hdcMem, CreatePen(PS_SOLID,1,RGB(231,223,231)))
'fill rectangle memDC with brush color
FillRect ( hdcMem,rc, oldBrush)
SetTextColor( hDC,RGB(0,0,0))
SetBkColor( hDC, RGB(231,223,231))
'blit to memDC
BitBlt(hDCmem, 0, 0, w, h, hdc, 0, 0, SRCCOPY)

ReleaseDC( win, hdc)
End SUB
'------------------------------------------------------------
Function Rnd(float randMax) as float
rret = Rand(0,randMax)/(randMax + 1.0)
Return rret
End Function

Function Rnd2(float d) as float
d=1/0x7fffffff
fseed=(fseed <<< 7)*13
Return abs(d*fseed)
End Function

'##########################################################
SUB CleanUp

DeleteDC(hdcMem)
DeleteObject(SelectObject(hdcMem, oldBrush))
DeleteObject(SelectObject(hdcMem, oldPen))
DeleteObject(SelectObject(hdcMem, oldBmp))

END SUB


And here is code in ruben interpreter:

Code: [Select]
'original code written in Creative Basic by GWS
defn i ,n ,red ,green ,blue
defn ww ,wh ,dots ,xpos ,ypos
defn repeat ,random
defn a ,b ,c ,x ,y ,z
defn j ,xfocus ,yfocus
defn rr ,gg ,bb , count
set ww = 800
set wh = 600
'open window
wform 0,0,ww,wh,#MMS,0,"CB Fractal Patterns"
wColor 0,0,0
set xfocus = ww * 0.47
set yfocus = wh * 0.45

label repeat
   set count = count + 1
wColor 0,0,0
set random = RAND(5)

FOR repeat,1,random
' set up some random starting positions ..
set a = RND(1.0)
set b = 0.9998
set c = 2 - 2 * a

set dots = 2000

set x = 0
set j = 0
set y = RND(1.0)*12 + 0.1

' calculate and draw the points ..
FOR i,0,dots

set z = x
set x = b * y + j
set j = a * x + c * (x*x)/(1 + x*x)
set y = j - z
set xpos = x*20 + xfocus
set ypos = y*20 + yfocus

set rr = RAND(255)
set gg = RAND(255)
set bb = RAND(255)
txColor rr,gg,bb
pix xpos,ypos
NEXT i

NEXT repeat

if count,<,5
jump repeat
endif

repeat=0
random=0
dots=0

       

It is interesting that almost there is no difference in speed .
It is clear that this way is not fast with classic GDI.

.

Aurel

  • Guest
Re: Dotty Patterns
« Reply #3 on: April 29, 2014, 09:44:23 AM »
Hi Peter!

Yes i agree with you.
Well as you can see i use GDI as best i know .
And as i say i hope that this code will perform faster in real oxygen code than trough
interpreter but differnce in speed is very small. ::)

JRS

  • Guest
Re: Dotty Patterns
« Reply #4 on: April 29, 2014, 10:01:00 AM »
Aurel,

Have tried to compile your O2 RubenDev interpreter as a Windows 64 bit app yet?


Aurel

  • Guest
Re: Dotty Patterns
« Reply #5 on: April 29, 2014, 10:49:37 AM »
No John..
But source code is open and anyone can try.

JRS

  • Guest
Re: Dotty Patterns
« Reply #6 on: April 29, 2014, 12:30:45 PM »
You and BaCon have the same open source project issues. Using free forums don't allow non-members to download attachments. How open is that?


Aurel

  • Guest
Re: Dotty Patterns
« Reply #7 on: April 29, 2014, 12:47:31 PM »
Quote
Using free forums don't allow non-members to download attachments. How open is that?

Ahh i see ...but this option don't have nothing with forum hosting  ::)
My forum is not created by hosting....

anyway if you whish source is here

JRS

  • Guest
Re: Dotty Patterns
« Reply #8 on: April 29, 2014, 12:57:50 PM »
Quote
anyway if you whish source is here

I had to add a REM so O2 had something to compile but other than that, works fine on 64 bit.  ;D

Aurel

  • Guest
Re: Dotty Patterns
« Reply #9 on: April 29, 2014, 01:16:11 PM »
heh yes it is just cca 2500 lines  ;D

JRS

  • Guest
Re: Dotty Patterns
« Reply #10 on: April 29, 2014, 01:27:37 PM »
Hehe

How long is it going to take you to realized you never attached anything or posted a link to any code?  :o