Author Topic: GLBasic Contest 02: 2D Art  (Read 1482 times)

Offline Snoopy

  • Dr. Type
  • ****
  • Posts: 260
    • View Profile
Re: GLBasic Contest 02: 2D Art
« Reply #15 on: 2019-May-07 »
Sorry for the delay, I was busy with my other projects (especially an important one for my job).
I made this little demo, it uses opengl functions and I'm in 3D mode but all calculations and the final display are done in 2D to stay in the rules of the contest.
I hope you will like it  ;)

Ps1: I have to put a .zip because it uses "gl.gbas".
Ps2: Very nice Fire Effect Qedo  :good:

-EDIT-
I just compiled Dreamerman's demo and that's great too.
Decidedly, there is talent here, it will become difficult to choose  :)
« Last Edit: 2019-May-07 by Snoopy »

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
Re: GLBasic Contest 02: 2D Art
« Reply #16 on: 2019-May-08 »
Nice work Snoopy, that high pitch sound though, scared me lol
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10695
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: GLBasic Contest 02: 2D Art
« Reply #17 on: 2019-May-08 »
@Snoopy - ArtDemo.exe triggers my Norton Antivirus - I have to reboot. It seems bad!

Offline Heiko

  • Community Developer
  • Dr. Type
  • ******
  • Posts: 498
    • View Profile
Re: GLBasic Contest 02: 2D Art
« Reply #18 on: 2019-May-08 »
@Kitty: its a false alarm.Bitdefender says nothing.
Ryzen 5 2400G - MSI B450 Tomahawk

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
Re: GLBasic Contest 02: 2D Art
« Reply #19 on: 2019-May-08 »
For my AVG AV program i think it checks each program on first run, after anything is compiled and run.
Only once, and on first run only.
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
Re: GLBasic Contest 02: 2D Art
« Reply #20 on: 2019-May-08 »
ps snoopy needs to be added to the poll.
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Snoopy

  • Dr. Type
  • ****
  • Posts: 260
    • View Profile
Re: GLBasic Contest 02: 2D Art
« Reply #21 on: 2019-May-08 »
@Snoopy - ArtDemo.exe triggers my Norton Antivirus - I have to reboot. It seems bad!

What?? It's a joke?
If so, there is a problem with your GLB compiler.
Moreover, Kaspersky and Comodo don't report anything at all.
Stop using Norton, it's a shit  :puke:

Nice work Snoopy, that high pitch sound though, scared me lol

Thanks Hemlos.
Yes, the pitch of the "beep" is a little too high, I should have lowered the sound a bit  ;)

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1773
    • View Profile
    • Homepage
Re: GLBasic Contest 02: 2D Art
« Reply #22 on: 2019-May-09 »
Agh, I have to stop playing around now  :whip:


Code: GLBasic [Select]
// --------------------------------- //
// Project: Totalistic Cellular Automaton
// Start: Tuesday, May 07, 2019
// IDE Version: 15.004
//
// Simple rules paints a picture. Use arrows to change rules and starting data.

// Idea:
// http://mathworld.wolfram.com/CellularAutomaton.html


GLOBAL color_states% = 3

GLOBAL x_max% = 320
GLOBAL y_max% = 220
GLOBAL zoom = 2

GLOBAL x%,y%

GLOBAL seed% = 380        // The top rule number
GLOBAL rule_number%=1 // decimal representation of rule
GLOBAL rule%[]
DIMDATA rule[],1,0,0,1,2,1,0 // rule converted to array

GLOBAL line_pos%[]       // Positions where to change rules
GLOBAL line_dir%[]   // Moving direction
GLOBAL line_rule%[]  // Rule number to run at this line (index into nice_rule[])
GLOBAL nice_rules%[] // Selection of interesting rules

GLOBAL image_data%[]
DIM image_data%[x_max * y_max]

GLOBAL data_grid%[]
DIM data_grid[x_max][y_max]

GLOBAL palette%[]
DIMDATA palette[], 0xFF000000, 0xFF70D0EC, 0xFF435BD9, 0xFF4229C0, 0xFF372454, 0xFF7A7753, 0xFF78D0EC, 0xFF435BD9, 0xFF4229C0

GLOBAL mx, my, b1, b2

SETSCREEN 640, 480, 0
SMOOTHSHADING FALSE     // Blocky zoom!

init_lines()
GLOBAL intro = 1

WHILE TRUE
        KeyHitUpdate()
        buttons()
        init_screen()
        recreate()
        overlay()
        SHOWSCREEN
        move_lines()
WEND
KEYWAIT
END

FUNCTION buttons:
        MOUSESTATE mx, my, b1, b2
       
        LOCAL step_size = 1

        IF KeyHit(42)>0 OR KeyHit(54)>0
                step_size=10
        ELSE
                step_size=1
        ENDIF
        IF KeyHit(57)=2 // Space
                DEBUG seed + ","
        ENDIF
        IF KeyHit(200)>0 THEN seed=seed+step_size
        IF KeyHit(208)>0 THEN seed=seed-step_size
        IF KeyHit(203)=2 THEN seed=seed-step_size
        IF KeyHit(205)=2 THEN seed=seed+step_size
       
        IF KeyHit(78)=2
                INC line_rule[0], 1
                IF line_rule[0] > LEN(nice_rules[])-1 THEN line_rule[0] = LEN(nice_rules[])-1
        ENDIF
        IF KeyHit(74)=2
                DEC line_rule[0], 1
                IF line_rule[0] < 0 THEN line_rule[0] = 0
        ENDIF

ENDFUNCTION

FUNCTION recreate:
        FOR y = 1 TO y_max-1
                IF y = 1 THEN make_rule(seed)

                FOR i = 0 TO LEN(line_pos[])-1
                        IF y = line_pos[i]
                                make_rule(nice_rules[line_rule[i]])
                        ENDIF
                NEXT
               

                FOR x = 1 TO x_max-2
                        set(x,y,decide_sum(x,y))
                NEXT
        NEXT

        // Convert data to sprite:
        MEM2SPRITE(image_data%[], 1, x_max, y_max)
        //DRAWSPRITE 1, 0, 30
        STRETCHSPRITE 1, 0, 30, x_max*zoom, y_max*zoom
       
ENDFUNCTION

FUNCTION move_lines:
        IF intro = 1
                //380, 38
               
                FOR i = 0 TO LEN(line_pos[])-1
                        IF line_pos[i] >= y_max-1 OR line_pos[i] <= 1
                                line_dir[i] = -line_dir[i]
                                INC line_rule[i], 1
                                IF line_rule[i] > LEN(nice_rules[])-1 THEN line_rule[i] = 0
                        ENDIF
                        INC line_pos[i], line_dir[i]
                NEXT
                IF KeyHit(57) THEN intro = 0
        ELSE
                line_pos[0] = my
        ENDIF
ENDFUNCTION

FUNCTION init_lines:
        DIMDATA line_pos[], 3 // y_max/4 //, y_max/4*3
        DIMDATA line_dir[], 1, -1
        DIMDATA nice_rules[], 38, 3,10,12,21,24,28,30,31,34,38,43,46,48,49,52,57,65,66,75,83,84,86,92,93,95,96,97,100,102,105,106,109,110,111,113,114,115,128,129,136,137,138,140,141,145,146,147,150,164,170,172,173,177,183,186,194,205,210,219,220,221,224,237,302,308,357,384,422,439,443,497,600,646,804,807,843,844,845,858,867,870,885,888,893,924,925,947
        DIMDATA line_rule[], 1, LEN(nice_rules[])/3
ENDFUNCTION

FUNCTION init_screen:
        FOR x = 0 TO x_max-1
                set (x, 0, 0)
        NEXT
        set(x_max/2, 0, 1)
ENDFUNCTION


// Foreground layer / instructions
FUNCTION overlay:
        IF intro = 1
                PRINT "Press SPACE", 50, 10
        ELSE
                LOCAL str$
                PRINT "Change rule with arrowkeys, hold shift for faster change.", 0, 0
                PRINT "Mouse Y move up and down, + and - on numpad changes rule.", 0, 10
       
                PRINT "Rules: " + seed + " and " + nice_rules[line_rule[0]], 0, 20
                str$=""
                FOREACH a IN rule[]
                        str$ = str$ + a
                NEXT
                PRINT str$, 0, 30
        ENDIF
ENDFUNCTION


FUNCTION decide_sum: x, y
        LOCAL sum = 0
        LOCAL result = 0

        y = y - 1
        FOR x1 = x-1 TO x+1
                sum = sum + get(x1,y)
        NEXT

        IF sum >= 0 AND sum < BOUNDS(rule[], 0)
                result = rule[sum]
        ENDIF
       
        RETURN result
ENDFUNCTION

FUNCTION get: x, y
        IF x >= 0 AND x < x_max AND y >= 0 AND y < y_max
                RETURN data_grid[x][y]
        ELSE
                RETURN 0
        ENDIF
ENDFUNCTION

FUNCTION set: x, y, color
        image_data%[x + y*x_max] = palette[color]
        data_grid%[x][y] = color
ENDFUNCTION

FUNCTION make_rule: n%
        rule_number% = n%
        //rule = dec_to_base(n, color_states)
        dec_to_base(n, color_states)
ENDFUNCTION

// ------------------------------------------------------------- //
// ---  dec_to_base  ---
// ------------------------------------------------------------- //
// Convert decimal to any base system
// Returns array with LSB first
//
FUNCTION dec_to_base: num%, base%
        LOCAL a%[]
        DIM a%[0]

        WHILE (num>0)
                DIMPUSH a[], MOD(num, base)
                num = INTEGER(num / base)
        WEND
        rule = a
        //RETURN a
ENDFUNCTION



// ------------------------------------------------------------- //
// ---  KeyHitUpdate  ---
// ------------------------------------------------------------- //
//
// Update keyboard state, call every screen refresh
//
GLOBAL gKeyDown[], gKeyState[]
FUNCTION KeyHitUpdate:
        LOCAL  k, i

    // First Time call, init
    IF BOUNDS(gKeyDown[],0)=0
        DIM gKeyDown[256]
        DIM gKeyState[256]
    ENDIF

    // For each key
    FOR i=0 TO 255
        k = KEY(i)
        // Key is pressed
        IF k
            IF gKeyDown[i]
                gKeyState[i]=1
            ELSE
                gKeyDown[i]=1
                gKeyState[i]=2
            ENDIF
        ELSE
            // Key is not pressed

            // Has key been pressed before?
            IF gKeyDown[i]
                gKeyDown[i] = 0
                gKeyState[i] = -1
            ELSE
                gKeyState[i]=0
            ENDIF
        ENDIF
    NEXT
ENDFUNCTION

// ------------------------------------------------------------- //
// ---  KeyHit  ---
// ------------------------------------------------------------- //
// Returns:
//  0 = not pressed
//  2 = just pressed (only triggers on keydown)
//  1 = pressed
// -1 = release event (only triggers on keyup)
//
// nkey = key scancode to check
FUNCTION KeyHit: nkey
    RETURN gKeyState[nkey]
ENDFUNCTION

 

Fun competition :-)

Offline WPShadow

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1667
    • View Profile
    • http://lostrevenant.blogspot.com
Re: GLBasic Contest 02: 2D Art
« Reply #23 on: 2019-May-09 »
Ok, I have a few questions and I think we all should discuss this:

  • How often should we make a contest? Every month, every 2 months?
  • How long should the breaks be between 2 contests?
  • How long should the contest itself be?

I have many stupid and funny ideas for little contests like this. Some are harder, others are short and easy. And I think it's really funny, also for me...

But I want everyone to be happy with them and not to spam one contest after another
AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est

Offline Snoopy

  • Dr. Type
  • ****
  • Posts: 260
    • View Profile
Re: GLBasic Contest 02: 2D Art
« Reply #24 on: 2019-May-10 »
For the next contest, I run a retro team demo challenge !
Replicants against Bladerunners
The demo must be in console mode ;)
No limit, just your imagination and your talent ! 

Ps1: I choose to be a Replicant, I'm taking Hemlos to my team if he agrees =D
Ps2: You are welcome in this fun contest Kitty :booze:

-EDIT-
No Opengl, no DirectX, just Software.
If you agree WPShadow, put it in place.
« Last Edit: 2019-May-10 by Snoopy »

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 287
    • View Profile
    • my personal website
Re: GLBasic Contest 02: 2D Art
« Reply #25 on: 2019-May-10 »
Looks like that Norton heuristic is highly restrictive as I just checked that original exe file from Snoopy project with Total Virus (Steam uses this for scanning apps) and only 1 warning per 70 AV scanners.

@Snoppy: I really like those particles - due that shading from color to black, simple but very effective. In addition that music, theme from Space Odyssey is always great :)

@Moru: Nice and interesting, with some additional rules to include more colors could give some spectacular result. This could be used as background for some part of larger demo.


About next contest:
It all depends on the contest, something small doesn't long running time, still at least one month so all interested could code their entry on free weekend (as even this topic shows). Breaks could for example take half of time that contest was running, or at least two-three weeks independently of contest duration.

Console/textmode contest sounds cool, yet will force to work harder to code something interesting – should last longer than this. Additional rules could be added here – for example demo running time max 3 minutes.
Check my source code editor for GLBasic - link

Offline WPShadow

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1667
    • View Profile
    • http://lostrevenant.blogspot.com
Re: GLBasic Contest 02: 2D Art
« Reply #26 on: 2019-May-10 »
How about 1,5 month contest running time and two weeks breaks?
AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est

Offline Snoopy

  • Dr. Type
  • ****
  • Posts: 260
    • View Profile
Re: GLBasic Contest 02: 2D Art
« Reply #27 on: 2019-May-11 »
@Dreamerman : Thanks, Yes, it's a simple but always spectacular effect.

@Moru : I always liked the fractals, that always gives interesting effects. The one I prefer is the famous Mandelbrot.

As Dreamerman said it's much more difficult so 3 weeks or 1 month would be a good time for this contest.
On the other hand, I think that we will drop the team work, the idea is pleasant but I think it will be difficult to implement :(

We also can not use the console mode but only have the right to use the SETPIXEL function for display, it may be easier for all.

-EDIT-
I still have not voted, the choice is really difficult.
I look at all the choices (except mine because I don't vote for me) and they are all different, some spectacular and others less but interesting by their simplicity.
It's really very very difficult...
« Last Edit: 2019-May-11 by Snoopy »

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 287
    • View Profile
    • my personal website
Re: GLBasic Contest 02: 2D Art
« Reply #28 on: 2019-May-16 »
@WPShadow - for me sounds ok.

@Snoopy - true console mode sounded original, we can have this earlier or later and another contest with limitations for only SetPixel.
For moment I was thinking that we are limited to standard console colors but:

main file
Code: GLBasic [Select]
// project -> options -> console program
LOCAL i1%, i2%
FOR i2 = 0 TO 15
        FOR i1 = 0 TO 15
                ConsoleSetColor(i1, i2)
                STDOUT "test"
        NEXT
        STDOUT "\n"
NEXT
KEYWAIT
second file
Code: GLBasic [Select]
IMPORT "C" int __stdcall GetStdHandle(int nStdHandle)
IMPORT "C" int __stdcall SetConsoleTextAttribute(int hConsoleOutput, int wAttributes)

FUNCTION ConsoleSetColor: fg_color%, bg_color%
        LOCAL console_handle% = GetStdHandle(-11)
        SetConsoleTextAttribute(console_handle, bg_color% * 16 + fg_color%)
ENDFUNCTION

only question is how fast console window can be refreshed, and some functions to print at selected X,Y position would be also usefully.
Another thing is that you need to have idea for demo that would fit into console/text mode nicely, this may be an issue for me hehe... :D
Check my source code editor for GLBasic - link

Offline WPShadow

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1667
    • View Profile
    • http://lostrevenant.blogspot.com
Re: GLBasic Contest 02: 2D Art
« Reply #29 on: 2019-May-17 »
Quote
only question is how fast console window can be refreshed, and some functions to print at selected X,Y position would be also usefully.

That shouldn't be your problem... every developer have to find a way by himself to fix this issue  :D

I will set everything up for the next contest from 01.06 - 14.07. ?

I think 6 weeks should be enough
AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est