Main forum > Competitions

GLBasic Contest 02: 2D Art

(1/7) > >>

Hi,

here we go, it's time for an other contest:

Definition

Write a 2D art program in GLBasic. It should be a little piece of art, not an art creation program.

Rules

* Write the whole program only in GLBasic
* no third party libraries
* Keep the code short and simple
* Make the result look impressive
Goal

Show us your best little art project, with or without movement and impress us.

Submission

Just post your code here in a codeblock, so everybody can study your awesome work.

Closing Date

19.05.2019

Example

Here is my little example. It's an optical illusion.

If you press the space bar, you can start and stop the movement.

--- Code: (glbasic) ---
TYPE tRect
x
y
direction
speed
ENDTYPE

GLOBAL rect[] AS tRect, space

main()

FUNCTION main:

generateRects()

WHILE TRUE

drawLines()
drawBoxes()

IF INKEY\$() = " "
INC space, 1
IF space > 1 THEN space = 0
ENDIF

SHOWSCREEN
WEND

ENDFUNCTION

FUNCTION generateRects:
LOCAL r AS tRect
LOCAL offset

FOR tmpY = 0 TO 15

offset = RND(25)

r.direction =  MOD(tmpY, 2)
r.speed = 100 + RND(200)

FOR tmpX = 0 TO 10
r.x = 0 + (tmpX * 60) + offset
r.y = 5 + (tmpY * 30)

DIMPUSH rect[], r

NEXT
NEXT

ENDFUNCTION

FUNCTION addRect: x, y, direction

ENDFUNCTION

FUNCTION drawLines:
LOCAL tmpY

FOR tmpY = 0 TO 15
DRAWRECT 0, 0 + (tmpY * 30), 640, 5, RGB(128, 128, 128)
NEXT

ENDFUNCTION

FUNCTION drawBoxes:

FOREACH r IN rect[]

IF space = TRUE
IF r.direction = 0
INC r.x, r.speed / 500
ENDIF
IF r.direction = 1
DEC r.x, r.speed / 500
ENDIF
ENDIF

DRAWRECT r.x, r.y, 5, 25, RGB(128, 128, 128)
DRAWRECT r.x + 5, r.y, 25, 25, RGB(255, 255, 255)
DRAWRECT r.x + 30, r.y, 5, 25, RGB(128, 128, 128)

IF r.x < -30
r.x = 640
ENDIF
IF r.x > 640
r.x = -30
ENDIF
NEXT

ENDFUNCTION

--- End code ---

Winner

This is a fun contest and there is nothing to win... Nevertheless, together we can choose a winner...

Good luck and have fun.

=====

Winner of the contest:

:enc:Qedo (50%) & Snoopy (50%) :enc:

I know, this contest looks pointless at first, but it's pretty handy for backgrounds or scenes in games

Hemlos:
This is an experimental piece i tinkered with a few years ago, hardly worth being called art.
It uses a rocking motion of sins and cos. eg. -1 to 1 to -1 to 1 etc

1. compile fullscreen 1920x1080
2. dont forget to grab this background image, or the special effect at the end will not look right.

--- Code: (glbasic) ---// --------------------------------- //
// Project: ColorPalette
// Start: Saturday, August 08, 2015
// IDE Version: 12.312

// compile 1920 x 1080 resolution fullscreen

WHILE TRUE

STATIC a# = 0
a# = a# + 0.1
IF a# > 359.0
a# = 0.0
ENDIF
b# = SIN(a#) * 127.0

// the meters - still experimenting with colors..these are read to go...they have inputs [0.0..1.0] or [-1.0..1.0]
METER_Volume(30,40,20,300,SIN(a/2))
METER_SINE(60,40,20,300,SIN(a) )//, 0x604020, 0x707070)
METER_SINE(90,40,20,300,COS(b) )//, 0x604020, 0x707070)

// stars
DrawStar(200,500, 0xffffff, 5 , -50 , a , 0.5)
DrawStar(300,600, 0xff00ff, 5 , -100 , a , 0.75)
DrawStar(200,640, 0x808080 + RGB(COS(a)*127,128,0), 24 , -128 , 0 , SIN(a) * 1.0)
DrawStar(200,640, 0x808080 + RGB(0,COS(a)*127,128), 24 , -128 , a , 0.2)

// fractal sun
// this one needs HEAVY experimenting!
MakeSun(960,540, 2048, 2048+COS(b)*2048, 1, RGB( (127+COS(b*10)*127), (127+SIN(b*10)*127),COS(b*5)*127+127), 0x000000, b#, 0.1)  //this is the fractal...its a lil messy
IF (GETTIMERALL() >20000)
c=c+0.01
IF c>1.0 THEN c=1.0
DrawStar( 940, 540, 0xffffff, 5, 9999, a, c)
ENDIF
IF (GETTIMERALL() >24000) THEN END

SHOWSCREEN

WEND

//
FUNCTION MakeSun: x1%, y1%, Points2%, Size2%, Wander%, Color#, Color2#, Angle#, Depth#
DrawStar(x1% , y1%+2 , Color#, Points2%, -Size2%  ,  COS(Angle#)*2.0, Depth#)
DrawStar(x1% , y1% , Color2#, Points2% , -Size2% ,  0 , Depth#)
RETURN 0
ENDFUNCTION

FUNCTION METER_SINE: x%, y%, w%, h%, Level#, Color1% = 0x00f0f0, Color2% = 0xf0f000 // Level# = -1.0 to 1.0 eg. [-1.0..1.0]
IF Level# < -1.0 THEN Level# = -1.0
IF Level# > 1.0 THEN Level# = 1.0
PRINT Level,10,10
LOCAL MeterLevel# = (h% - 1 ) * Level#
POLYVECTOR x%,y%,w%,h%,0x0000f0
DRAWRECT x%+2,y%+2,w%-4,h%-4,Color2%
DRAWRECT x%+4,y%+4,w%-8,h%-8,Color2% * 0.4
DRAWRECT x%+4,y%+(h%/2),w%-8,-MeterLevel#/2,Color1%
RETURN 0
ENDFUNCTION

FUNCTION METER_Volume: x%, y%, w%, h%, Level#, Color1% = 0x806040, Color2% = 0xf0f000 //Level# = 0 to 1.0 [0..1]
IF Level# < 0 THEN Level# = 0
IF Level# > 1.0 THEN Level# = 1.0
PRINT Level,10,10
LOCAL MeterLevel# = ( h% - 4 ) * Level#
DRAWRECT x%,y%,w%,h,Color1%
DRAWRECT x%+4,y%+4,w%-8,h%-9,Color1% * 0
DRAWRECT x%+4,y%+h%-4,w%-8,-MeterLevel#, Color2%
RETURN 0
ENDFUNCTION

FUNCTION DrawStar: x%, y%, Color#, NumberOfPoints%, TextureID%, Rotate#, Depth# // make some stars! -TextureID# = SIZE If No Sprites ID is supplied. (-) Negative ID
// Star Creator Code Designed Neil M. Silver,  Aug. 9, 2015
//
// The Algorithm:
// --
//   NumberOfPoints = Number of visually obvious points, eg. An American Star is 5 pointed.
// --
//   Vector Count = The number of actual vectors a polyvector needs, in fan mode, can be calculated:
//
//     ( V = P * 2 + 2 )
//     VectorCount% = ( NumberOfPoints% * 2 ) + 2 )
//     Note: Add Two, one for the center point, one for the last point.
// --
//   VectorAngleSize% = is the turn size for each vector to draw.
//     ( A = 180 / P )
//     VectorAngleSize# = ( 180.0 / NumberOfPoints% )
// --
//   Depth%
//     The inner and outer radius represent the length of the points, and the depth of thier inner corners.
//     The Depth% value is a scalar, a ratio of the outer radius, 0.5 is good for stars...play with this [0.1~~1.0]
//
//                           . ________________
//                                            ^
//                    .   .    .     .        |   Outer Radius
//                                            V
//                       .     ________________
//                                            V  Inner Radius (Depth#)
//                           .   ______________
//                      .          .
//
//
// --
//   Rotate%, 360 degrees
// --
//  A negative value for TextureID% will make the star that size, without an image.
//  eg ( TextureID%  = -5 ) will make the star 10 wide, radius 5...no skin.
// --
//
// Other notes:
// Its midhandled.
// Use a square image, root 2
//
STATIC Phase%
LOCAL iW%, iH%, ViR#, VoR#
LOCAL VectorCount% = ( ( NumberOfPoints% * 2 ) + 2 )
LOCAL VectorAngleSize# = ( 180.0 / NumberOfPoints% ) * 1.0
LOCAL tX#, tY#, vX#, vY#

// Get the outer radius:
IF TextureID% >= 0
GETSPRITESIZE TextureID%, iW%, iH%
ViR# = ( iW% * 0.5 ) * Depth#
VoR# = ( iW% * 0.5 ) * 1.0
ELSE
VoR# = ABS(TextureID%) //use -textureid for a size param
ViR# = ( VoR# * Depth# )
ENDIF
//STAR:

STARTPOLY TextureID%, 0 // FAN Mode only!
POLYVECTOR x%, y%, VoR#, VoR#, Color# // center vector
LOCAL AngleNow#
FOR i% = 0 TO VectorCount% - 1
AngleNow# = ( ( VectorAngleSize# * i% * 1.0 ) + Rotate# ) * 1.0
Phase% = Phase% + 1
IF Phase% > 1
Phase% = 0
ENDIF
IF Phase%
vX# = COS( AngleNow# ) * VoR#
vY# = SIN( AngleNow# ) * VoR#
ELSE
vX# = COS( AngleNow# ) * ViR#
vY# = SIN( AngleNow# ) * ViR#
ENDIF
tX# = vX# + VoR#
tY# = vY# + VoR#
POLYVECTOR x% + vX#, y% + vY#, tX#, tY#, Color#
NEXT
ENDPOLY
RETURN 0
ENDFUNCTION

--- End code ---

This is awesome

bigsofty:

--- Quote from: Hemlos on 2019-Apr-20 ---This is an experimental piece i tinkered with a few years ago, hardly worth being called art.

--- End quote ---

I disagree, very much art!  ;)