Author Topic: Rainbow Speed  (Read 4685 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
Rainbow Speed
« on: December 16, 2013, 12:26:54 PM »
 Deleted
« Last Edit: April 25, 2015, 03:27:33 AM by Peter »

JRS

  • Guest
Re: Rainbow Speed
« Reply #1 on: December 16, 2013, 12:32:02 PM »
I'll give it a try with C BASIC & SDL_draw.

Thanks for the screen shot!  ;)

JRS

  • Guest
Re: Rainbow Speed
« Reply #2 on: December 16, 2013, 10:19:25 PM »
Here is the C BASIC - SDL_draw version of rainbow. (Ubuntu 64 bit) I'm unable to set the line width like Simple Window so I changed Peter's O2 example (compiled and running under Wine) to a single width line like the C BASIC version.

Observation:
  • C BASIC / SDL_draw is 3X faster than Simple Window. (SW)
  • C BASIC / SDL_draw produces a more precise line with less distortion.
  • C BASIC / SDL_draw runs on Windows, Linux and Android. (OSX if you care)
  • C BASIC / SDL_draw is open source.



It seems C BASIC is more than a silly idea with the goal of making swishing sounds as described by Curly-16/32. Not all FreeBASIC users are bitter and lost as there are a few members that have turned combined obsolesce into something fun and familiar. Who would of guessed? Using Rapid-Q as way to generate FreeBASIC code. Maybe that is how the C BASIC idea evolved?  :P

   

Code: [Select]
// C BASIC Rainbow
// gcc -o rainbow rainbow.c -g -O2 -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_OPENGL -lSDL -lm -lSDL_draw

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include "SDL.h"
#include "SDL_draw.h"
#include "cbasic.h"

MAIN
BEGIN_FUNCTION
  DIM AS SDL_Surface PTR screen;
  DIM AS int width, height;
  DIM AS Uint8  video_bpp;
  DIM AS Uint32 videoflags;
  DIM AS Uint32 clearColor;
  DIM AS float yacc, yvel, xyel, x, y, r, t1, t2, t3;
  DIM AS float m = -1.57, x1 = 1, y1 = 301, q = 0.00101, gx = 0.15, gy = 0.3;
  DIM AS float x2, x3, x4, x5, x6, x7, x8, y2, y3, y4, y5, y6, y7, y8;
  DIM AS int s;
  DIM AS int done;
  DIM AS SDL_Event event;
  atexit(SDL_Quit);
  videoflags = SDL_SWSURFACE | SDL_ANYFORMAT;
  width = 300;
  height = 300;
  video_bpp = 32;
  screen = SDL_SetVideoMode(width, height, video_bpp, videoflags);
  SDL_WM_SetCaption("C BASIC Rainbow", 0);
  SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 255, 255, 255));
  t1 = SDL_GetTicks();
  FOR (s = 1 TO s <= 3107 STEP INCR s)
  BEGIN_FOR
    m = m + q;
    x1=x1 + gx * cos(m);
    y1=y1 + gy * sin(m);
    x2 = (x1 + 150)/2; y2 = (y1 + 300)/2;
    x3 = (x1 + x2) /2; y3 = (y1 + y2) /2;
    x4 = (x2 + 150)/2; y4 = (y2 + 300)/2;
    x5 = (x1 + x3) /2; y5 = (y1 + y3) /2;
    x6 = (x2 + x3) /2; y6 = (y2 + y3) /2;
    x7 = (x2 + x4) /2; y7 = (y2 + y4) /2;
    x8 = (x4 + 150)/2; y8 = (y4 + 300)/2;
    Draw_Line(screen, x1, y1, x5, y5, SDL_MapRGB(screen->format, 255, 0, 0));
    Draw_Line(screen, x5, y5, x3, y3, SDL_MapRGB(screen->format, 255, 102, 0));
    Draw_Line(screen, x3, y3, x6, y6, SDL_MapRGB(screen->format, 255, 255, 0));
    Draw_Line(screen, x6, y6, x2, y2, SDL_MapRGB(screen->format, 0, 255, 0));
    Draw_Line(screen, x2, y2, x7, y7, SDL_MapRGB(screen->format, 0 ,0, 255));
    Draw_Line(screen, x7, y7, x4, y4, SDL_MapRGB(screen->format, 0, 0, 128));
    Draw_Line(screen, x4, y4, x8, y8, SDL_MapRGB(screen->format, 128, 0, 128));
  NEXT
  SDL_UpdateRect(screen, 0, 0, 0, 0);
  t2 = SDL_GetTicks();
  t3 = (t2 - t1) / 1000;
  PRINT ("Lines: %i\n", s * 7);
  PRINT ("Time:  %.4f seconds.\n", t3);
  done = 0;
  WHILE (NOT done)
  BEGIN_WHILE
    WHILE (SDL_PollEvent(AT event))
    BEGIN_WHILE
      SELECT_CASE (event.type)
      BEGIN_SELECT
        CASE SDL_KEYDOWN:
        CASE SDL_QUIT:
          done = 1;
          END_CASE
        CASE_ELSE
          END_CASE
      END_SELECT
    WEND
  WEND
  RETURN_FUNCTION(0);
END_FUNCTION


jrs@laptop:~/C_BASIC/xlate$ ./rainbow
Lines: 21756
Time:  0.0260 seconds.
jrs@laptop:~/C_BASIC/xlate$
« Last Edit: December 17, 2013, 06:38:48 PM by John »

Aurel

  • Guest
Re: Rainbow Speed
« Reply #3 on: December 17, 2013, 05:12:38 AM »
wait ,wait ...wait
Heh ...John why you use SDL?
Use pure win api then told us how much speed you get..ok ;)

Aurel

  • Guest
Re: Rainbow Speed
« Reply #4 on: December 17, 2013, 06:20:46 AM »
Quote
You are right, Aurel.
He is cheating.

heh...yes , something like this ..
Peter
One thing is strange to me , in your example all colours are fine but in my not ::)
I also look in my old example from ABasic ( yes .... ;D) it is the same in all calculation
with liitlebit different RGB but produce full spectar but this example not... ???

Code: [Select]
'rainbow2
include "awinh.inc"
Declare Function GetTickCount Lib "kernel32.dll" () As Long
#lookahead
INT win
'GLOBALS for drawing to DC -------------------------------------------- 
INT hdc, hdcMem, hbmMem,oldBmp, oldBrush, oldPen, oldFont, fColor,bColor
INT textX,textY,hBrush
INT ww,hh
INT wstyle = WS_MINMAXSIZE Or WS_CLIPCHILDREN
'create main window ****************************************************
win = SetWindow("Rainbow2",40,40,320,374,0,wstyle)
InitDrawing(win)
int t1,t2
float yacc,yvel,xyel,x,y,r
float m = -1.57, x1 =1, y1 =301, q =0.00101, gx =0.15, gy =0.3
int x2,x3,x4,x5,x6,x7,x8,y2,y3,y4,y5,y6,y7,y8
int s

t1 = getTickCount
For s =1 to 3107

m=m+q
x1=x1+gx*cos(m)
y1=y1+gy*sin(m)
x2=(x1+150)/2
y2=(y1+300)/2
x3=(x1+x2)/2
y3=(y1+y2)/2
x4=(x2+150)/2
y4=(y2+300)/2
x5=(x1+x3)/2
y5=(y1+y3)/2
x6=(x2+x3)/2
y6=(y2+y3)/2
x7=(x2+x4)/2
y7=(y2+y4)/2
x8=(x4+150)/2
y8=(y4+300)/2   

TextColor(win,RGB(200,0,0))
  LineXY win,x1,y1,x5,y5
 
TextColor(win, RGB(200,160,80))
      LineXY win,x5,y5,x3,y3

TextColor(win,RGB(220,220,0))
      LineXY win,x3,y3,x6,y6

TextColor(win,RGB(0,150,0))
      LineXY win,x6,y6,x2,y2

TextColor(win,RGB (0,0,200))
      LineXY win,x2,y2,x7,y7

TextColor(win,RGB (0,0,150))
      LineXY win,x7,y7,x4,y4

TextColor(win,RGB (150,0,150))
      LineXY win,x4,y4,x8,y8
Next s

t2 = GetTickCount
t2 = (t2-t1)/1000
TextOn win,0,304,"Lines: " + s*7
TextOn win,0,324,"Time:  " + str(t2) + " seconds"









Wait()
'----------------------------------------------------
Function WndProc (sys hwnd,wmsg,wparam,lparam) as sys callback
Select hwnd
'>>>>>>>>>>>>>>>>>>>>>>>>>

Case win
'>>>>>>>>>>>>>>>>>>>><<<
Select wMsg
'----------------------------
CASE WM_PAINT
BitBlt(hDC, 0, 0, ww, hh, hdcMem, 0, 0, SRCCOPY)
'----------------------------
Case WM_CLOSE
If win <> 0
     CleanUp()
CloseWindow(win)
EndProgram
End If
End Select

End Select

Return Default

End Function

'================================================
SUB InitDrawing(byval wnd as INT)
'INT ww,hh
''get current size of window
GetSize(wnd,0,0,ww,hh)
'get window DC
hdc=GetDC(wnd)
hdcMem = CreateCompatibleDC(0)
hbmMem = CreateCompatibleBitmap(hdc, ww, hh)
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, ww, hh, hdc, 0, 0, SRCCOPY)

ReleaseDC( wnd, hdc)
End SUB

'=================================================
SUB TextColor (wID as INT,byval frontColor as sys)
hdc = GetDC(wID)
sys bColor
fColor=frontColor
bColor = RGB(231,223,231)
SetTextColor( hDC, frontColor)
SetBkColor( hDC, bColor)

BitBlt(hDCmem, 0, 0, ww, hh, hdc, 0, 0, SRCCOPY)

ReleaseDC( wID, hdc)

End SUB
'=================================================
Sub TextOn( int wnd,sys x, y, string txt)
'INT ww,hh
hdc=GetDC(wnd)
GetSize(wnd,0,0,ww,hh)
TextOut sys_hdc,x,y,txt,Len(txt)
BitBlt(hDCmem, 0, 0, ww, hh, hdc, 0, 0, SRCCOPY)
ReleaseDC(wnd,Hdc)
End Sub

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

hdc = GetDC(wID)
GetSize(wID,0,0,ww,hh)
SelectObject(hdc, CreatePen(PS_SOLID,1,fColor))

MoveToEx hdc,Lx,Ly,byval 0
LineTo hdc,Lx1,Ly1

BitBlt(hDCmem, 0, 0, ww, hh, hdc, 0, 0, SRCCOPY)
ReleaseDC( wID, hdc)
End SUB
'=================================================
SUB Pset (wID as int , px as int ,py as int)
hdc = GetDC(wID)
'GetSize(wID,0,0,ww,hh)
SetPixel ( hdc, px, py, fColor)

BitBlt(hDCmem, 0, 0, ww, hh, hdc, 0, 0, SRCCOPY)

ReleaseDC( wID, hdc)

End SUB
'//////////////////////////////////////////////
SUB CleanUp
DeleteDC(hdcMem)
DeleteObject(SelectObject(hdcMem, oldBrush))
DeleteObject(SelectObject(hdcMem, oldPen))
DeleteObject(SelectObject(hdcMem, oldBmp))
End SUB

.

Aurel

  • Guest
Re: Rainbow Speed
« Reply #5 on: December 17, 2013, 08:09:42 AM »
WOW  :o
Peter
Your new code give more speed and proper spectar...
well i don't know what to say... ???

Code: [Select]
include "sw.inc"
Declare Function GetTickCount Lib "kernel32.dll" () As Long
Window 300,344,1

float t1,t2
int color
float yacc,yvel,xyel,x,y,r
float m = -1.57, x1 =1, y1 =301, q =0.00101, gx =0.15, gy =0.3
int x2,x3,x4,x5,x6,x7,x8,y2,y3,y4,y5,y6,y7,y8
int s

t1 = getTickCount
For s =1 to 3107

m=m+q
x1=x1+gx*cos(m)
y1=y1+gy*sin(m)
x2=(x1+150)/2
y2=(y1+300)/2
x3=(x1+x2)/2
y3=(y1+y2)/2
x4=(x2+150)/2
y4=(y2+300)/2
x5=(x1+x3)/2
y5=(y1+y3)/2
x6=(x2+x3)/2
y6=(y2+y3)/2
x7=(x2+x4)/2
y7=(y2+y4)/2
x8=(x4+150)/2
y8=(y4+300)/2   

Color=(RGB(200,0,0))
      Line x1,y1,x5,y5,1,color
 
Color=(RGB(200,160,80))
      Line x5,y5,x3,y3,1,color

Color=(RGB(220,220,0))
      Line x3,y3,x6,y6,1,color

Color=(RGB(0,150,0))
      Line x6,y6,x2,y2,1,color

Color=(RGB (0,0,200))
      Line x2,y2,x7,y7,1,color

Color=(RGB (0,0,150))
      Line x7,y7,x4,y4,1,color

Color=(RGB (150,0,150))
      Line x4,y4,x8,y8,1,color
Next

t2 = GetTickCount
t2 = (t2-t1)/1000
Text 0,300,"Lines: " + s*7,0
Text 0,318,"Time:  " + str(t2,6) + " seconds",0

WaitKey
CloseWindow

.

JRS

  • Guest
Re: Rainbow Speed
« Reply #6 on: December 17, 2013, 11:03:39 AM »
Quote
Why are you unable to write the line with  factor 2 ?
Just use  "DRAWBOX or "DRAWRECT" or something else.
Programming is so easy!

You are not faster with C-BASIC or others dialects,   image below.

Your original post ask the O2 forum members to try your rainbow example in other compilers/interpreters and report the results. I did what you asked. I can't help it if you don't like the results, don't attack me. Join the FreeBASIC forum if that is your intent. Your program said to draw lines (which you are keeping a tally of) not DRAWBOX/DRAWRECT/FILLREC or anything else. How is anyone suppose to know what you call LINE when SW is close source? If you go back to my post, you will see that C BASIC took .02 seconds and SW/O2 took .06 seconds. I think we are getting to the root of the problem, you don't understand simple math.


 
« Last Edit: December 17, 2013, 06:42:48 PM by John »

Aurel

  • Guest
Re: Rainbow Speed
« Reply #7 on: December 17, 2013, 11:37:09 AM »
Quote
How is anyone suppose to know what you call LINE when SW is close source?
what ?

John
are you from outer space or something ..and you don't know what is LINE in Peter
sw ... ???
Line is line if you ever look into any our include file which most of them open source ..right?
i really don't get it why you so upset or insulted when some of our questions are not
by your measures or standards..right?

JRS

  • Guest
Re: Rainbow Speed
« Reply #8 on: December 17, 2013, 11:54:40 AM »
Aurel,

I understand that English isn't your native language and cut you slack for that. Please post your source to sw.dll that Peter has given you. When using 2D graphic primitives which are well defined a LINE is just that. Not a rectangle (filled or not) or any other substitution Peter uses to compensate for artifacts and precision miscalculations.

I was incorrect in my last post. YOU called me a lier and a cheater, not Peter. My warning applies to you as well.

Aurel

  • Guest
Re: Rainbow Speed
« Reply #9 on: December 17, 2013, 01:31:21 PM »
Quote
Please post your source to sw.dll that Peter has given you.

Yes ...my english sucks( everybody knows that  ;D )...
but i really don't get it what is this all about... ???
I don't say that you are liar or cheater....where you see that ?
I say ...use native api and create example then we can see how your
program is fast ...is that ok ?

Or you really want remove me and Peter from this forum?
Almost only two real contributors and real users of Oxygen Basic....
Ok ....
by the way do what you must to do   ;)

PS ...I don't have source of sw.dll and i never ask Peter for source and i don't need that source
that i know what is ordinary win api function...

JRS

  • Guest
Re: Rainbow Speed
« Reply #10 on: December 17, 2013, 02:00:28 PM »
Facts and Fiction



Here is a screen shot of Peter's new rainbow code with a modification to print the actual start and stop tick count and use a separate variable for the total.

13027054 − 13026991 = 63

63 รท 1000 = 0.063 seconds.

Your previous code was faster.

It seems that you have also drop down to a 8 or 16 bit color palette. The C BASIC version is using 32 bit color.



JRS

  • Guest
Re: Rainbow Speed
« Reply #11 on: December 17, 2013, 02:23:25 PM »
Quote
By the way: I can nowhere see LIar, I think is your weird fantasy.
I would like to be in the hell, as a dinner with J.Spikowsky.

Please reread the posts in this thread. I apologized to you for falsely accusing you when it was Aurel foaming at the mouth.

I was initially in question of your math ability but now it has digressed to your spelling. (J. Spikowski)  :D


JRS

  • Guest
Re: Rainbow Speed
« Reply #12 on: December 17, 2013, 03:33:57 PM »
Quote from: Aurel
wait ,wait ...wait
Heh ...John why you use SDL?
Use pure win api then told us how much speed you get..ok

Because I want to be able to run the example on the platform I develop under and others if I so chose. You need to wake up and realize your XP / WinBox32 is dying fast. No one is doing ANY development for 32 bit anymore. Even hobbyists are wise enough and looking for 64 bit alternatives. Please don't make your world and the limitations you're strapped with our responsibility to resolve.


Aurel

  • Guest
Re: Rainbow Speed
« Reply #13 on: December 17, 2013, 11:11:01 PM »
Quote
No one is doing ANY development for 32 bit anymore. Even hobbyists are wise enough and looking for 64 bit alternatives. Please don't make your world and the limitations you're strapped with our responsibility to resolve.

really ..... ;D
As you know my programs work fine on any WINDOWS machine 32/64 bit sooooo
Ahh linux...sorrry....grrr....who care ;D

JRS

  • Guest
Re: Rainbow Speed
« Reply #14 on: December 17, 2013, 11:32:51 PM »
Quote from: Aurel
As you know my programs work fine on any WINDOWS machine 32/64 bit sooooo
Ahh linux...sorrry....grrr....who care

Your programs works on 32 bit Windows XP and in Win32 emulation mode on a Windows 64 bit OS. The longer you ignore Linux the farther you will be behind.

I feel like I'm talking to the deaf. I could care less about BASIC languages that have no 64 bit plans or solutions. When 64 bit ARM is the mainstream, that will be the last of 32 bit as we knew it. Just read the everyday tech news, I'm not saying anything new.