Author Topic: New SdlFern  (Read 5321 times)

0 Members and 1 Guest are viewing this topic.

Aaron

  • Guest
New SdlFern
« on: March 10, 2014, 08:32:11 AM »
Hi,

A Sdl check:

Code: [Select]
include "ss.inc"
OpenWindow 640,500,1

single a, b, c, d, e, f, newx, newy, t1, t2
sys r, w
Dim xy(2) as single

Sub Fern
r = Rnd(0,100)
iF r <= 10
   a = 0
   b = 0
   c = 0
   d = 0.16
   e = 0
   f = 0
ElseiF r > 1 and r <=86
   a = 0.85
   b = 0.04
   c = -.04
   d = 0.85
   e = 0
   f = 1.60
ElseiF r > 86 and r <=93
   a = 0.2
   b = -.26
   c = 0.23
   d = 0.22
   e = 0
   f = 0.16
Else
   a = -.15
   b = 0.28
   c = 0.26
   d = 0.24
   e = 0
   f = 0.44
End iF

newx = ((a * xy(1)) + (b * xy(2)) + e)
newy = ((c * xy(1)) + (d * xy(2)) + f)
xy(1) = newx
xy(2) = newy

Color(0,120,55,200)
SetPixel xy(1)*40+275,-xy(2)*40+450
End Sub

Cls 255,255,255
t1 = ticks

For w=0, 500000
  Fern
Next
Redraw

t2 = ticks
t2 = (t2-t1)/1000
Color 0,0,0,255
DrawString 10,480,"Fern Points: " + str(w-1) + " Time: " + t2 + " secs"

WaitKey
CloseWindow

.

JRS

  • Guest
Re: New SdlFern
« Reply #1 on: March 10, 2014, 03:09:19 PM »
Im happy to report your latest SDL fern example ran fine under Wine.



.

Aaron

  • Guest
Re: New SdlFern
« Reply #2 on: March 11, 2014, 03:06:16 AM »
Hi John,

Take your time and check this function:
Code: [Select]
SDL_Surface *surface
Function GetPixel(int x,y) as sys
    sys pixel
    pixel = surface.pixels
    Return pixel[ (y * surface.w) + x]
End Function

I personally had no success, I only got wrong values here.


Aaron

  • Guest
Re: New SdlFern
« Reply #3 on: March 11, 2014, 05:18:31 AM »
Hi,

A small primitive check.

Code: [Select]
include "ss.inc"
OpenWindow 320,240,1

h = GetHeight()/2
w = GetWidth ()/2

string prv[20] = {"DrawPoint","DrawCircle","FillCircle","DrawEllipse","FillEllipse","DrawRect","FillRect","DrawLine","ThickLine","DrawRoundRect","FillRoundRect"}

Color 255,255,255,255
DrawString 100, 0,"PRIMITIVE TEST"
DrawString 100,12,"  HIT A KEY"
WaitKey

Color 255,235,78,255
DrawString 100,50,prv[1]
DrawPoint w,h,2
WaitKey

Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[2]
DrawCircle w,h,40
WaitKey

Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[3]
FillCircle w,h,40
WaitKey

Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[4]
DrawEllipse w,h,40,20
WaitKey

Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[5]
FillEllipse w,h,40,20
WaitKey

Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[6]
DrawRect w,h,40,40
WaitKey

Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[7]
FillRect w,h,40,40
WaitKey

Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[8]
DrawLine w,h,w+40,h
DrawLine w,h,w-40,h
WaitKey

Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[9]
ThickLine w,h,w+40,h,4
ThickLine w,h,w-40,h,4
WaitKey

Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[10]
DrawRoundRect w,h,40,40,12
WaitKey

Color 0,0,0,255
FillRect 0,50,320,190
Color 255,235,78,255
DrawString 100,50,prv[11]
FillRoundRect w,h,40,40,6
WaitKey

Color 255,0,0,255
DrawString 95,h+60,"ARE YOU SURE?"
WaitKey
CloseWindow

JRS

  • Guest
Re: New SdlFern
« Reply #4 on: March 11, 2014, 08:06:09 AM »
Peter,

I'm only able to return the RRGGBB value from the main surface. To get the alpha value of a pixel, I had to create a new surface first and blit it to the main. Check out the gfx_GetPixel function in the Script BASIC GFX extension module source. Ignore the gfx_GetPixelRGBA function as it was a work in process that didn't pan out and I forgot to remove it before uploading to Bitbucket.

John
« Last Edit: March 11, 2014, 10:20:13 AM by John »

Aaron

  • Guest
Re: New SdlFern
« Reply #5 on: March 11, 2014, 11:20:42 AM »
Hello,

Bounce with Vroby's SdlBasic.
The source code is into the  bounce.exe.

It is slower than RubenDev.   ;D

.
« Last Edit: March 11, 2014, 04:53:55 PM by Peter »

JRS

  • Guest
Re: New SdlFern
« Reply #6 on: March 12, 2014, 08:46:34 AM »
Peter,

I downloaded SDL BASIC but couldn't make much of the source. I couldn't find the source to the bounce demo anywhere. It's done in C++ which I have no interest in at the moment.  I hope I made myself clear that I have no problems creating graphics on the main surface with the alpha attribute, I just can't find a way to retrieve the alpha value from a pixel on the main surface. The trick seems to be to initialize the format mask for alpha channel (seems to have been missed) but there is no SDL call I can find to do that after the surface has already been created.

John

Aaron

  • Guest
Re: New SdlFern
« Reply #7 on: March 12, 2014, 09:17:03 AM »
Quote
I couldn't find the source to the bounce demo anywhere.

LOL!

Open the bounce.exe in an editor, (Notepad ) or another.

Aaron

  • Guest
Re: New SdlFern
« Reply #8 on: March 12, 2014, 09:26:27 AM »
I am depressed,  ;D

GetPixel is a dilemma, still no success with an alpha pixel.
I will  change the strategy. 

JRS

  • Guest
Re: New SdlFern
« Reply #9 on: March 12, 2014, 09:54:20 AM »
I plucked the code out of the EXE as you suggest. (PITA - why didn't you post the code?)

Code: [Select]
autoback(-2)

Function Rand(minZahl,maxZahl)
    Dim result
    maxZahl= (maxZahl-minZahl)+2
    result = rnd(maxZahl)+minZahl
    Return result-1
End Function

common cx[100],cy[100],cd[100],cr[100],cs[100]
common cr[100],cg[100],cb[100],ca[100]

For c=1 to 100
    cx[c]=310
    cy[c]=230
    cd[c]=Rand(1,8)
    cs[c]=Rand(20,30)
    cr[c]=Rand(64,255)
    cg[c]=Rand(64,255)
    cb[c]=Rand(64,255)
    ca[c]=Rand(64,255)
Next

Sub Circles()
For m=1 to 100
    ink(Rgb(cr[m],cg[m],cb[m]))
    FillCircle(cx[m],cy[m],cs[m])
Next
End Sub

Sub Bound()
For x=1 to 100
    if cx[x] <=10 then
       cd[x] = Rand(1,9)
       cx[x] =10
    end if
    if cx[x] >=620 then
       cd[x] = Rand(1,9)
       cx[x] =620
    end if
    if cy[x] >=460 then
       cd[x] = Rand(1,9)
       cy[x] =460
    end if
    if cy[x] <=10 then
       cd[x] = Rand(1,9)
       cy[x] =10
    end if
Next
End Sub

while Key(27)=0
paper(0)
cls()
for c=1 to 100
    if cd[c]=1 then
       cx[c]=cx[c]+1
       Bound()
    elseif cd[c]=2 then
       cx[c]=cx[c]-1
       Bound()
    elseif cd[c]=3 then
       cy[c]=cy[c]-1
       Bound()
    elseif cd[c]=4 then
       cy[c]=cy[c]+1
       Bound()
    elseif cd[c]=5 then
       cy[c]=cy[c]-1
       cx[c]=cx[c]-1
       Bound()
    elseif cd[c]=6 then
       cy[c]=cy[c]-1
       cx[c]=cx[c]+1
       Bound()
    elseif cd[c]=7 then
       cy[c]=cy[c]+1
       cx[c]=cx[c]-1
       Bound()
    elseif cd[c]=8 then
       cy[c]=cy[c]+1
       cx[c]=cx[c]+1
       Bound()
    end if
Next
Circles()
screenswap
wend

Aurel

  • Guest
Re: New SdlFern
« Reply #10 on: March 12, 2014, 09:54:33 AM »
Hi Peter
Where you see source code for bounce  ???
There is just a exe file , i know that is source binded to the runtime but i dont know how to extract
source from this file .
Anyway when you say it is slower than RubenDev ...well it is very slow.
Peter do you have maybe ordinary fern example in SDLBasic that i can see how work?

Aaron

  • Guest
Re: New SdlFern
« Reply #11 on: March 12, 2014, 10:22:50 AM »
Hi Aurel,

Yes,  but I must search.

Aaron

  • Guest
Re: New SdlFern
« Reply #12 on: March 12, 2014, 10:58:40 AM »
Quote
(PITA - why didn't you post the code?)

Too much work.  ;D

JRS

  • Guest
Re: New SdlFern
« Reply #13 on: March 12, 2014, 11:08:43 AM »
I step in that trap often trying to make you look good.  :o  :-*
« Last Edit: March 12, 2014, 03:14:01 PM by John »

Aaron

  • Guest
Re: New SdlFern
« Reply #14 on: March 12, 2014, 11:42:51 AM »
Quote
Peter do you have maybe ordinary fern example in SDLBasic that i can see how work?

Hi Aurel,

here is it,
Code: [Select]
SetDisplay(640, 500, 32, 1)

Function Rand(minZahl,maxZahl)
    Dim result
    maxZahl= (maxZahl-minZahl)+2
    result = rnd(maxZahl)+minZahl
    Return result-1
End Function

common a=0, b=0, c=0, d=0, e=0, f=0, newx=0, newy=0, r=0, wa=0
Dim xy[2]

Sub Fern
r = Rand(0,100)
iF r <= 10 then
   a = 0
   b = 0
   c = 0
   d = 0.16
   e = 0
   f = 0
ElseiF r > 1 and r <=86 then
   a = 0.85
   b = 0.04
   c = -.04
   d = 0.85
   e = 0
   f = 1.60
ElseiF r > 86 and r <=93 then
   a = 0.2
   b = -.26
   c = 0.23
   d = 0.22
   e = 0
   f = 0.16
Else
   a = -.15
   b = 0.28
   c = 0.26
   d = 0.24
   e = 0
   f = 0.44
End iF
newx = ((a * xy[1]) + (b * xy[2]) + e)
newy = ((c * xy[1]) + (d * xy[2]) + f)
xy[1] = newx
xy[2] = newy
ink(0x00D237)
SetPixel(xy[1]*40+275,xy[2]*40+50)
End Sub

ink(0x1C1C1C)
Cls()
for wa=0 to 100000
    Fern
next
screenswap()
SetCaption("Fern Points:  " & str(wa))
WaitKey(27)