Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 308
» Latest member: Donaldvem
» Forum threads: 1,741
» Forum posts: 17,901

Full Statistics

Latest Threads
The QB64 IDE shell
Forum: Utilities
Last Post: JasonPag
09-16-2024, 05:37 PM
» Replies: 9
» Views: 762
Importance regarding Ches...
Forum: Utilities
Last Post: JasonPag
09-01-2024, 06:34 PM
» Replies: 0
» Views: 31
Chess and Analysis and En...
Forum: Utilities
Last Post: JasonPag
08-28-2024, 02:37 PM
» Replies: 0
» Views: 32
DAY 009:_PutImage
Forum: Keyword of the Day!
Last Post: grymmjack
09-02-2023, 02:57 PM
» Replies: 54
» Views: 2,029
Fall Banner Contest?
Forum: Site Suggestions
Last Post: grymmjack
08-31-2023, 11:50 PM
» Replies: 36
» Views: 1,261
ColorPicker - Function th...
Forum: Dav
Last Post: Dav
08-31-2023, 11:04 PM
» Replies: 3
» Views: 315
Goals(1) = New Tile()
Forum: Works in Progress
Last Post: RhoSigma
08-31-2023, 09:45 PM
» Replies: 3
» Views: 127
micro(A)v11
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 09:14 PM
» Replies: 90
» Views: 3,550
Updating The Single Most ...
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 09:13 PM
» Replies: 7
» Views: 252
QBJS Image Question
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 05:49 PM
» Replies: 5
» Views: 154

 
  Stunt Jumper
Posted by: mnrvovrfc - 07-17-2023, 12:09 AM - Forum: Programs - Replies (4)

Here's yet another silly game that I remembered from one of David L. Heiserman's books. But it's "customized" to my taste and knowledge of BASIC programming LOL. In this game you play a stunt paratrooper jumping out of a plane trying to evade buildings. The game should be straightforward, giving instructions on the screen. Either you jump or you don't, and if you jump don't go "splat" into a building and don't go off a side of the screen! The plane does a "loop" back to the beginning so it could wrap around the screen but the stunt paratrooper can't!

There is a peculiar RANDOMIZE statement, allowing a player to "practice" this program. Smile

I should allocate some time for sound effects for this program. The original program had a quirk about the protagonist but didn't care how he/she was called. In fact I programmed another quirk before deciding to submit this, heh heh.

Code: (Select All)
'by mnrvovrfc 17-July-2023
option _explicit
dim nm$(1 to 7), histogram(1 to 80) as integer
dim as integer i, j, h, v, w, z, numtiles, numthalf, thresh
dim as integer x, y, px, py, fuel, recede, planecolor
dim ke$, handl$, jumped as _bit, die as integer

nm$(1) = "murderflower"
nm$(2) = "jumpdaplain"
nm$(3) = "sinusister"
nm$(4) = "quakefear"
nm$(5) = "adrenald"
nm$(6) = "houston"
nm$(7) = "rebare"

print "Welcome to Stunt Paratrooper!"
print: print "Please choose who do you want to be. Press any number key from [1] to [7]."
for i = 1 to 7
print "("; _trim$(str$(i)); ") "; nm$(i)
next
do
do : ke$ = inkey$ : loop while ke$ = ""
if ke$ = chr$(27) then end
v = val(ke$)
loop until v > 0 and v < 8
handl$ = nm$(v)
v = ubound(nm$) - v + 4

randomize v + 100

numtiles = 200
numthalf = numtiles \ 2
thresh = 5
cls

for i = 1 to numthalf
j = Random1(80)
histogram(j) = histogram(j) + 1
next
h = 0
for i = 1 to 80
if histogram(i) > h then h = histogram(i)
next
for i = 1 to numthalf
do
j = Random1(80)
loop until abs(histogram(j) - h) <= thresh
histogram(j) = histogram(j) + 1
next
h = 0
for i = 1 to 80
if histogram(i) > h then
h = histogram(i)
w = i
end if
if histogram(i) = 0 then histogram(i) = 1
next
if w = 80 then
z = 80
w = 78
else
z = w + 2
end if
histogram(w + 1) = 0

color 6
locate 25, 1 : print string$(79, 46);
locate 24, 1 : print string$(80, 46);
color 8
for i = 1 to 80
y = 24
for j = histogram(i) to 1 step -1
locate y, i
print chr$(177);
y = y - 1
if y < 10 then exit for
next
next

color 4
locate 1, 1 : print handl$;
color 3
print " you have to hit the grass between those buildings! Good luck!"
color 5
locate 2, 1 : print "Press [ESC] to quit. Press spacebar to jump out of plane."

fuel = 6
recede = fuel - 1
jumped = 0
x = 1
y = 5
planecolor = 7

do : ke$ = inkey$ : loop until ke$ = ""

do
color planecolor
locate y, x : print "|_^";
for i = 1 to 10
_delay 0.05
ke$ = inkey$
if ke$ <> "" then
if ke$ = chr$(27) then system
if ke$ = chr$(32) then
jumped = 1
exit for
end if
end if
next
locate y, x : print space$(3);
x = x + 1
if x > 78 then
x = 1
if y < 8 then y = y + 1
fuel = fuel - 1
if fuel < 1 then exit do
if fuel < 3 then
color 4
locate 1, 1 : print space$(80);
locate 1, 1 : print handl$; " you need to jump now, I'm running out of fuel!"
end if
end if
if fuel < 3 then
if planecolor = 7 then planecolor = 8 else planecolor = 7
end if
loop until jumped

if jumped then
color 4
locate 1, 1 : print space$(80);
locate 2, 1 : print space$(80);
locate 1, 1
if fuel = recede then
print "BE CAREFUL "; handl$; "!!!"
else
print handl$; " has jumped!"
end if
px = x + 1
py = y
do while v
py = py + 1
if fuel = recede then
px = px - 1
if px < 1 then
die = 2
exit do
end if
else
px = px + 1
if px > 80 then
die = 2
exit do
end if
end if
color 12
locate py, px : print chr$(2);
x = x + 1
if x > 78 then x = 1
color 7
locate y, x : print "|_^";
v = v - 1
_delay 0.5
locate py, px : print " ";
locate y, x : print space$(3);
loop
if die = 0 then
do
'this should not need screen bounds checking
py = py + 1
h = screen(py, px)
if h = 46 then die = 0 : exit do
if h = 177 then die = 1 : exit do
color 12
locate py, px : print chr$(2);
x = x + 1
if x > 78 then x = 1
color 7
locate y, x : print "|_^";
_delay 0.5
locate py, px : print " ";
locate y, x : print space$(3);
loop
end if
color 5
locate 2, 1
select case die
case 0
print "GOOD JOB "; handl$; "!!! You have landed on the grass."
case 1
print "You crashed into a building! OUCH!!!"
case 2
print "Sorry but you went out of bounds which is not the purpose of this game. Wink"
end select
end
else
color 4
locate 1, 1 : print space$(80);
locate 1, 1 : print "Sorry but you have lost.";
color 7
do until y > 23
locate y, x : print space$(3);
y = y + 1
locate y, x : print "|_^";
_delay 0.25
loop
color 4
for i = 1 to 10
locate y, x : print "#*#";
_delay 0.125
locate y, x
if i > 7 then
print ".+.";
else
print "*#*";
end if
_delay 0.125
next
locate y, x : print space$(3);
_delay 1
end if
system



FUNCTION Random1& (maxvaluu&)
DIM sg AS INTEGER
sg% = SGN(maxvaluu&)
IF sg% = 0 THEN
Random1& = 0
ELSE
IF sg% = -1 THEN maxvaluu& = maxvaluu& * -1
Random1& = INT(RND * maxvaluu& + 1) * sg%
END IF
END FUNCTION

Print this item

  Pointer in Basic
Posted by: Kernelpanic - 07-16-2023, 09:57 PM - Forum: General Discussion - Replies (24)

Has anyone ever dealt with pointers in Basic?

Actually there are no pointers in Basic like in C, but maybe they can be imitated. I've tried this now with VarPtr, Peek and Poke, and I didn't find any error in my exercise to achieve this. I don't see any at the moment either. Access to the memory address is basically like in C, and I can also change the content.

Pointers are a powerful, but also dangerous, tool in C! One could definitely good use them in Basic too. I think so.

I would be grateful to anyone who is interested and takes a look at the program if they could point out whether and if so, where I made a mistake in my thinking.

The explanations/comments are of course in German, so I can understand what's going on. 

Code: (Select All)
'Zeigerbeispiel in Basic - 16. Juli 2023
'Mit VarPtr und Peek und Poke ist es moeglich Zeiger in
'Basic nachzuahmen.

$Console:Only
Option _Explicit

Dim As Long zahl1, zahl2, wert, wert2
Dim As Long speicherAdresse, speicherAdresse2

Locate 2, 3
Input "Zahl 1: ", zahl1

Locate 3, 3
Input "Zahl 2: ", zahl2

Locate 5, 3
Print Using "Zeige Zahl 1: ### -- Zahl 2: ### "; zahl1, zahl2

'Adresse der Zahl im Speicher ermitteln
speicherAdresse = VarPtr(zahl1)

'Speicheradresse anzeigen
Locate 6, 3
Print "Speicheradress Zahl 1: ", speicherAdresse

'wert wird der Inhalt der Speicheradresse zugewiesen
wert = Peek(speicherAdresse)

Locate 8, 3
Print "Inhalt der Speicheradresse: ", wert

'wert erhoehen
wert = wert * 2

'Neuen Wert in die Speicheradresse einfuegen
Poke (speicherAdresse), wert

'Neuen Inhalt anzeigen
Locate 9, 3
Print "Neuer Inhalt in der Speicheradresse (Inhalt * 2): ", wert

'Speicheradresse der 2ten Variablen ermitteln
speicherAdresse2 = VarPtr(zahl2)
wert2 = Peek(speicherAdresse2)

'Inhalt der Speicheradresse
Locate 11, 3
Print "Inhalt der 2ten Speicheradresse: ", wert2

Locate 12, 3
Print "Jetzt auf die Adresse von Zahl 2 zugreifen, um den Inhalt zu aendern."

'Der 2ten Variablen den Wert von wert2 von der
'ersten Speicheradresse zuweisen
Locate 14, 3
wert2 = Peek(speicherAdresse)
Print "2te Variable hat jetzt den selben Wert wie Zahl 1: ", wert2

End
[Image: Zeiger-in-Basic2023-07-16.jpg]

Print this item

  Summer LASER Challenge
Posted by: TerryRitchie - 07-15-2023, 07:32 PM - Forum: Programs - Replies (42)

I'm attempting to recreate the look and feel of the original BattleStar Galactica lasers that the Colonial Vipers (red lasers) and the Cylon Raiders (white/blue lasers) produced. Below you can see a montage of screen shots showing the various lasers in action. There's also a link to a short 4 minute clip of the show showing the two ships shooting at each other.

I've tried to recreate this effect a number of different ways using image files, rotozoom and_PUTIMAGE, shading using alpha blends, and other various things that always look like crap. I'm horrible when it comes to custom graphics.

So here's the challenge if you choose to accept it: Create this laser effect on a 2D screen where the laser can be pointed and shot in any one of 360 degrees. I've posted an early attempt of my code to give you and idea of what to shoot for. I'm working on a game based on the old BG series and I really want to get the lasers looking as authentic as possible.

YouTube clip: https://www.youtube.com/watch?v=E2BJodHVGT8

Code: (Select All)
OPTION _EXPLICIT

CONST SWIDTH = 1280
CONST SHEIGHT = 720

TYPE TYPE_VECTOR
    x AS SINGLE '              x vector/coordinate
    y AS SINGLE '              y vector/coordinate
END TYPE

TYPE TYPE_LINE
    Start AS TYPE_VECTOR '    start coordinate of laser beam line
    Finish AS TYPE_VECTOR '    end coordinate of laser beam line
    'Center AS TYPE_VECTOR '    center coordinate of laser beam line
END TYPE


TYPE TYPE_LASER

    Origin AS TYPE_VECTOR
    Head AS TYPE_LINE ' overall rectangle
    Tail AS TYPE_LINE
    Beam AS TYPE_LINE ' center beam

    HeadSpeed AS SINGLE
    TailSpeed AS SINGLE
    MaxSpeed AS SINGLE

    Vector AS TYPE_VECTOR '    vector direction of laser
    Degree AS INTEGER '        degree direction of laser
    Speed AS SINGLE '          speed of laser
    LaserColor AS _UNSIGNED LONG
    GlowColor AS _UNSIGNED LONG
    Active AS INTEGER '        laser is active (t/f)
END TYPE


REDIM Laser(0) AS TYPE_LASER
DIM Vec(359) AS TYPE_VECTOR
'DIM i AS INTEGER
DIM Degree AS INTEGER

DIM Origin AS TYPE_VECTOR
DIM Colour AS INTEGER
DIM Speed AS SINGLE
DIM RapidFire AS INTEGER
'DIM Size AS SINGLE

Degree = 0 ' precalculate degree vectors
DO
    Vec(Degree).x = SIN(_D2R(Degree))
    Vec(Degree).y = -COS(_D2R(Degree))
    Degree = Degree + 1
LOOP UNTIL Degree = 360


SCREEN _NEWIMAGE(SWIDTH, SHEIGHT, 32)
CLS


Origin.x = 100
Origin.y = 359
Degree = 90
Colour = 4
Speed = 15
'Size = 1


DO
    _LIMIT 60
    CLS
    IF _KEYDOWN(32) AND RapidFire = 0 THEN
        SHOOT_LASER Origin, Degree, Speed, Colour
        Degree = FIX_DEGREE(Degree + 2)
        RapidFire = 10
    ELSE
        IF RapidFire THEN RapidFire = RapidFire - 1
    END IF
    UPDATE_LASER
    _DISPLAY
LOOP UNTIL _KEYDOWN(27)




SUB SHOOT_LASER (Origin AS TYPE_VECTOR, Degree AS INTEGER, Speed AS SINGLE, Colour AS INTEGER)

    SHARED Laser() AS TYPE_LASER
    SHARED Vec() AS TYPE_VECTOR
    DIM Index AS INTEGER

    Index = -1 '                                    reset index counter
    DO '                                            begin free index search
        Index = Index + 1 '                          increment index counter
        IF Laser(Index).Active = 0 THEN EXIT DO '    is this index free?
    LOOP UNTIL Index = UBOUND(Laser) '              leave when all indexes checked
    IF Laser(Index).Active THEN '                    were all indexes checked?
        Index = Index + 1 '                          yes, no free indexes, increment index
        REDIM _PRESERVE Laser(Index) AS TYPE_LASER ' create a new index in array
    END IF
    Degree = FIX_DEGREE(Degree)
    Laser(Index).Active = -1
    Laser(Index).Origin = Origin
    Laser(Index).Vector = Vec(Degree)
    Laser(Index).Degree = Degree


    Laser(Index).HeadSpeed = Speed
    Laser(Index).TailSpeed = Speed * .5

    Laser(Index).Speed = Speed
    Laser(Index).LaserColor = _RGB32((Colour AND 4) * 64, (Colour AND 2) * 128, (Colour AND 1) * 256)

    Laser(Index).Beam.Start = Origin
    Laser(Index).Beam.Finish = Origin


    Laser(Index).Head.Start.x = Origin.x - 2
    Laser(Index).Head.Start.y = Origin.y
    Laser(Index).Head.Finish.x = Origin.x + 2
    Laser(Index).Head.Finish.y = Origin.y

    Rotate Laser(Index).Head.Start, Degree, Origin ' rotate line
    Rotate Laser(Index).Head.Finish, Degree, Origin

    Laser(Index).Tail = Laser(Index).Head

    SELECT CASE Colour

        CASE 4
            Laser(Index).GlowColor = _RGB32(255, 211, 80)

        CASE 7
            Laser(Index).GlowColor = _RGB32(0, 128, 255)




    END SELECT





END SUB



SUB UPDATE_LASER ()

    SHARED Laser() AS TYPE_LASER

    DIM Index AS INTEGER
    DIM NoActive AS INTEGER

    NoActive = -1
    Index = -1
    DO
        Index = Index + 1
        IF Laser(Index).Active THEN
            NoActive = 0

            Laser(Index).Head.Start.x = Laser(Index).Head.Start.x + Laser(Index).Vector.x * Laser(Index).HeadSpeed
            Laser(Index).Head.Start.y = Laser(Index).Head.Start.y + Laser(Index).Vector.y * Laser(Index).HeadSpeed
            Laser(Index).Head.Finish.x = Laser(Index).Head.Finish.x + Laser(Index).Vector.x * Laser(Index).HeadSpeed
            Laser(Index).Head.Finish.y = Laser(Index).Head.Finish.y + Laser(Index).Vector.y * Laser(Index).HeadSpeed
            Laser(Index).Tail.Start.x = Laser(Index).Tail.Start.x + Laser(Index).Vector.x * Laser(Index).TailSpeed
            Laser(Index).Tail.Start.y = Laser(Index).Tail.Start.y + Laser(Index).Vector.y * Laser(Index).TailSpeed
            Laser(Index).Tail.Finish.x = Laser(Index).Tail.Finish.x + Laser(Index).Vector.x * Laser(Index).TailSpeed
            Laser(Index).Tail.Finish.y = Laser(Index).Tail.Finish.y + Laser(Index).Vector.y * Laser(Index).TailSpeed

            Laser(Index).Beam.Start.x = Laser(Index).Beam.Start.x + Laser(Index).Vector.x * Laser(Index).HeadSpeed
            Laser(Index).Beam.Start.y = Laser(Index).Beam.Start.y + Laser(Index).Vector.y * Laser(Index).HeadSpeed
            Laser(Index).Beam.Finish.x = Laser(Index).Beam.Finish.x + Laser(Index).Vector.x * Laser(Index).TailSpeed
            Laser(Index).Beam.Finish.y = Laser(Index).Beam.Finish.y + Laser(Index).Vector.y * Laser(Index).TailSpeed




            Laser(Index).HeadSpeed = Laser(Index).HeadSpeed * 1.04

            Laser(Index).TailSpeed = Laser(Index).TailSpeed * 1.07


            LINE (Laser(Index).Tail.Start.x, Laser(Index).Tail.Start.y)-(Laser(Index).Tail.Finish.x, Laser(Index).Tail.Finish.y), Laser(Index).LaserColor
            LINE -(Laser(Index).Head.Finish.x, Laser(Index).Head.Finish.y), Laser(Index).LaserColor
            LINE -(Laser(Index).Head.Start.x, Laser(Index).Head.Start.y), Laser(Index).LaserColor
            LINE -(Laser(Index).Tail.Start.x, Laser(Index).Tail.Start.y), Laser(Index).LaserColor

            PAINT (Laser(Index).Beam.Finish.x + Laser(Index).Vector.x * 2, Laser(Index).Beam.Finish.y + Laser(Index).Vector.y), Laser(Index).LaserColor, Laser(Index).LaserColor

            LINE (Laser(Index).Tail.Start.x, Laser(Index).Tail.Start.y)-(Laser(Index).Tail.Finish.x, Laser(Index).Tail.Finish.y), Laser(Index).GlowColor
            LINE -(Laser(Index).Head.Finish.x, Laser(Index).Head.Finish.y), Laser(Index).GlowColor
            LINE -(Laser(Index).Head.Start.x, Laser(Index).Head.Start.y), Laser(Index).GlowColor
            LINE -(Laser(Index).Tail.Start.x, Laser(Index).Tail.Start.y), Laser(Index).GlowColor

            'LINE (Laser(Index).Beam.Start.x, Laser(Index).Beam.Start.y)-(Laser(Index).Beam.Finish.x, Laser(Index).Beam.Finish.y), Laser(Index).LaserColor

            IF Laser(Index).Tail.Start.x < 0 OR Laser(Index).Tail.Start.x > SWIDTH THEN Laser(Index).Active = 0
            IF Laser(Index).Tail.Start.y < 0 OR Laser(Index).Tail.Start.y > SHEIGHT THEN Laser(Index).Active = 0


        END IF
    LOOP UNTIL Index = UBOUND(Laser)
    IF NoActive AND UBOUND(Laser) > 0 THEN REDIM Laser(0) AS TYPE_LASER: BEEP

END SUB






SUB Rotate (vec AS TYPE_VECTOR, angleDeg AS SINGLE, origin AS TYPE_VECTOR)

    ' Rotate a point around an origin using linear transformations.

    DIM x AS SINGLE
    DIM y AS SINGLE
    DIM __cos AS SINGLE
    DIM __sin AS SINGLE
    DIM xPrime AS SINGLE
    DIM yPrime AS SINGLE

    x = vec.x - origin.x '                move rotation vector origin to 0
    y = vec.y - origin.y
    __cos = COS(_D2R(angleDeg)) '        get cosine and sine of angle
    __sin = SIN(_D2R(angleDeg))
    xPrime = (x * __cos) - (y * __sin) '  calculate rotated location of vector
    yPrime = (x * __sin) + (y * __cos)
    xPrime = xPrime + origin.x '          move back to original origin
    yPrime = yPrime + origin.y
    vec.x = xPrime '                      pass back rotated vector
    vec.y = yPrime

END SUB






' ______________________________________________________________________________________________________________________________________________
'/                                                                                                                                              \
FUNCTION FIX_DEGREE (Degree AS INTEGER) '                                                                                          __FIX_DEGREE |
    ' __________________________________________________________________________________________________________________________________________|____
    '/                                                                                                                                              \
    '| Normalizes degree to between 0 and 359.                                                                                                      |
    '|                                                                                                                                              |
    '| Degree = FIX_DEGREE(-270)                                                                                                                    |
    '\_______________________________________________________________________________________________________________________________________________/

    DIM Deg AS INTEGER ' degree value passed in

    Deg = Degree '                        get passed in degree value
    IF Deg < 0 OR Degree > 359 THEN '    degree out of range?
        Deg = Deg MOD 360 '              yes, get remainder of modulus 360
        IF Deg < 0 THEN Deg = Deg + 360 ' add 360 if less than 0
    END IF
    FIX_DEGREE = Deg '                    return degree

END FUNCTION



Attached Files Thumbnail(s)
   
Print this item

  BAM: About the "{{Program Version Comment}}" Pre-Processor Directive
Posted by: CharlieJV - 07-15-2023, 04:20 PM - Forum: QBJS, BAM, and Other BASICs - No Replies

https://basicanywheremachine-news.blogsp...r-pre.html

Print this item

  BAM: Very Simple Tile-Sliding Puzzle
Posted by: CharlieJV - 07-14-2023, 04:53 AM - Forum: QBJS, BAM, and Other BASICs - Replies (6)

Print this item

  UnscramblePic.bas - Rotate picture pieces puzzle
Posted by: Dav - 07-14-2023, 03:24 AM - Forum: Dav - Replies (14)

UNSCRAMBLEPIC.BAS is a relaxing picture puzzle for all ages.  A picture is shown, then broken up into pieces which are randomly rotated in different positions.  Your goal is to rotate each piece back into the correct direction so they will show the correct picture again.  This program uses a built-in image, but you could supply your own image instead (look in the code for that place).

Use the mouse and click on the pieces to rotate them.  Left click will turns them clockwise, right click turns them counter clockwise.  If you get stuck, you can press SPACE to briefly show the solved picture.  The included picture is shown below (picture was made in a QB64 program).

- Dav

EDIT: Code fixed!  Re-download please.  (Thanks Steffan-68!)

.bas   unscramblepic.bas (Size: 51.2 KB / Downloads: 65)

   

Print this item

  looking for a simple sprite/tile sheet editor with animation tools
Posted by: madscijr - 07-12-2023, 05:16 PM - Forum: Help Me! - Replies (11)

Hey peeps! 

I'm looking for a sprite/tileset editor with drawing functions similar to Paint or even Paint.net, but also includes tools to help with animation, mockup layouts, etc. 

I'm thinking a single-screen, point-and-click all-in-one tool, that displays the whole tileset, an editing pane, an area to draw a few test tiles for a mockup, a palette color strip, an area to define + test animations, and an area for tools and other info. 

As you edit a tile, if you have drawn a mockup, the changes to the tile would be reflected in the mockup as you edit. 

I'll include a very hastily thrown together mockup to communicate the kind of thing I'm envisioning. 

I'm wondering if anything like this already exists, I wouldn't want to reinvent the wheel unnecessarily. 

Any info appreciated!

[Image: sprite-editor-mockup.png]

Print this item

  Program for editing PDF files
Posted by: Kernelpanic - 07-11-2023, 08:41 PM - Forum: General Discussion - Replies (9)

Something from daily practice. If one need a program to edit PDF files, I recommend this one (free): PDF24 Toolbox

Print this item

  Improved my small Gradient Ball drawing SUB
Posted by: Dav - 07-11-2023, 03:38 AM - Forum: Programs - Replies (22)

I use a small gradient ball SUB in various programs.  It had a flaw however - large balls with dark color values would have think back edges.  Made a new version to fix that.  Just thought I'd share it here.  If you have one too, please share it - I'd love to see what other people are using.  And if you see a way to improve mine please post it.  Thanks!

- Dav

Code: (Select All)

'================
'GRADIENTBALL.BAS
'================
'Simple SUB that draw gradient balls.
'Coded by Dav, JULY/2023


dh = _DESKTOPHEIGHT * .85
SCREEN _NEWIMAGE(dh, dh, 32)

DO
    ball RND * dh, RND * dh, RND * 500 + 25, RND * 255, RND * 255, RND * 255
    _LIMIT 5
LOOP

SUB ball (x, y, size, r, g, b)
    'This SUB draws a gradient ball with given color.

    'see current display status
    displayStatus%% = _AUTODISPLAY

    'turn off screen updates while we draw
    _DISPLAY

    reg = .4

    'if size is larger than value colors given,
    'adjust the reg value to step down at a slower rate.
    'This prevents thick black rim around larger balls
    'that have a too low a given color value.
    IF size > r AND size > g AND size > b THEN
        IF r > g AND r > b THEN reg = r / size * .4
        IF g > r AND g > b THEN reg = g / size * .4
        IF b > r AND b > g THEN reg = b / size * .4
    END IF

    'now draw the ball using CIRCLE.
    'Using smaller STEP value than 1 prevents gaps.
    FOR s = 0 TO size STEP .4
        CIRCLE (x, y), s, _RGB(r, g, b)
        r = r - reg: g = g - reg: b = b - reg
    NEXT

    'show the ball
    _DISPLAY

    'If autodislay was previously on, turn it back on
    IF displayStatus%% = -1 THEN _AUTODISPLAY

END SUB

Print this item

  Code Requests
Posted by: SpriggsySpriggs - 07-10-2023, 06:52 PM - Forum: Spriggsy - Replies (2)

I'm probably not going to reinstate a GitHub for my code but this thread can serve as a place for people to request code that I've written in the past that they are now unable to find. I have an archive of my GitHub on my home PC and will distribute the code as it is requested or, if I feel that the code is good enough, I'll just make a new thread for it and make updates to it there.

Print this item