Welcome, Guest |
You have to register before you can post on our site.
|
Latest Threads |
astuce pour survivre fina...
Forum: Utilities
Last Post: coletteleger
05-14-2025, 04:47 AM
» Replies: 0
» Views: 9
|
trouver permis de conduir...
Forum: Utilities
Last Post: nicolasrene
05-05-2025, 05:24 AM
» Replies: 0
» Views: 17
|
LIGHTBAR Menu
Forum: Programs
Last Post: nicolasrene
05-05-2025, 05:08 AM
» Replies: 15
» Views: 945
|
Learning Pallet Rack Safe...
Forum: Utilities
Last Post: Sandrapew
04-03-2025, 09:36 AM
» Replies: 0
» Views: 39
|
Choosing New Versus or Pr...
Forum: Utilities
Last Post: Sandrapew
03-18-2025, 01:11 AM
» Replies: 0
» Views: 33
|
The QB64 IDE shell
Forum: Utilities
Last Post: JasonPag
09-16-2024, 05:37 PM
» Replies: 9
» Views: 1,059
|
Importance regarding Ches...
Forum: Utilities
Last Post: JasonPag
09-01-2024, 06:34 PM
» Replies: 0
» Views: 71
|
Chess and Analysis and En...
Forum: Utilities
Last Post: JasonPag
08-28-2024, 02:37 PM
» Replies: 0
» Views: 68
|
DAY 009:_PutImage
Forum: Keyword of the Day!
Last Post: grymmjack
09-02-2023, 02:57 PM
» Replies: 54
» Views: 3,439
|
Fall Banner Contest?
Forum: Site Suggestions
Last Post: grymmjack
08-31-2023, 11:50 PM
» Replies: 36
» Views: 2,169
|
|
|
Calculating Anti-Primes |
Posted by: Space_Ghost - 07-06-2023, 06:56 PM - Forum: Works in Progress
- Replies (17)
|
 |
Can this be sped up? The code below calculates the first 45 anti-primes in ~6.3 seconds on my W11 PC.
Definition of anti-primes: A natural number that has more divisors (factors, not just prime factors) than any number less that it. For example, 6 has 4 factors, including 1 and itself, and this is more than 1,2,3 or 5 which have only the minimum of 2 factors and 4 which has 3 factors.
Code: (Select All)
'Anti-Primes: Calculate first 45 anti-primes
'date of code: 06 JUL 2023
'Space Ghost (modified QBasic 4.5 from Rosetta Code)
'HOUSEKEEPING -----------------------------------
$CONSOLE:ONLY
OPTION _EXPLICIT
CLS
'VARIABLE DECLARATIONS -------------------------
DIM t AS DOUBLE
DIM tmp AS STRING
DIM AS INTEGER MaxAntiPrime, AntiPrimeCount
DIM AS LONG MaxDivisors, Divisors, n
'MAIN BLOCK ------------------------------------
t = TIMER(0.001)
MaxAntiPrime = 45
n = 0
MaxDivisors = 0
AntiPrimeCount = 0
PRINT "The first 45 anti-primes are:"
PRINT
WHILE AntiPrimeCount < MaxAntiPrime
n = n + 1
Divisors = DivisorCount(n)
IF Divisors > MaxDivisors THEN
PRINT n;
MaxDivisors = Divisors
AntiPrimeCount = AntiPrimeCount + 1
END IF
WEND
PRINT: PRINT
tmp = "Execution Time in secs:##.###"
PRINT USING tmp; TIMER(0.001) - t
END
'FUNCTIONS AND SUBROUTINES ----------------------
FUNCTION DivisorCount (v)
DIM AS LONG total, count, n, p
total = 1
n = v
WHILE n MOD 2 = 0
total = total + 1
n = n \ 2
WEND
p = 3
WHILE (p * p) <= n
count = 1
WHILE n MOD p = 0
count = count + 1
n = n \ p
WEND
p = p + 2
total = total * count
WEND
IF n > 1 THEN total = total * 2
DivisorCount = total
END FUNCTION
'END OF PROGRAM --------------------------------
CONSOLE OUTPUT
The first 45 anti-primes are: 1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560 10080 15120 20160 25200 27720 45360 50400 55440 83160 110880 166320 221760 277200 332640 498960 554400 665280 720720 1081080 1441440 2162160 2882880 3603600 4324320 6486480
Execution Time in secs: 6.334
|
|
|
Boring plot of 5000 functions! |
Posted by: mnrvovrfc - 07-05-2023, 10:38 PM - Forum: Works in Progress
- Replies (4)
|
 |
This is another program that would only display graphic silliness. Don't expected colored, fractal stuff; a program such as this might have been attempted with QuickBASIC or Turbo Pascal, trying to burn those weak single-core CPU's to a crisp. Many pictures are just an useless line at the top or at the side of the screen. Others are just near-diagonal lines. Others are "steps" as if trying to plot binary or something else. But there are a few good ones here.
The program tries to plot a function with 500 points of Cartesian coordinates taking part in a polar scheme. If the function is not plottable, it's skipped. The "Illegal function call" had to be trapped for it. The functions were fabricated from another QB64 program I wrote. Don't spend too much time looking at them or it will cause some loss of sanity!
Press [ESC] to quit, or on Linux leave it for long enough and then it seg-faults, I don't know why. (shrugs)
At the terminal command line it's possible to follow the executable file's name with an integer from 1 to 5000, to start from the function indicated by the huge "SELECT CASE... END SELECT" block. This has nothing to do with random numbers. It was already taken care of by my "extreme function maker" LOL.
That is the first parameter. There is a second parameter which is a float-type factor. The default is to just plot a circle with X,Y for 500 points. The circle is always created by this program with a "radius" of 2. The factor in this program can only cause the effect of an open shape. In other words, the chosen factor by the user cannot be smaller than the default value of 1.3888.
The actual program is too big to post into this forum, so I'm posting only a portion of it. Otherwise you will have to download the attachment. 
Code: (Select All)
'by mnrvovrfc 06-Jun-2023
option _explicit
dim v(1 to 500) as double
dim as double n, x, y, z, mult, factdiv, smaller, largger
dim as integer i, j, cn
dim redu$
if command$(1) = "" then
cn = 1
else
cn = val(command$(1))
if cn = 0 then
cn = 1
elseif cn < 1 or cn > 5000 then
cn = 1
end if
end if
if command$(2) = "" then
mult = 1.3888
else
mult = val(command$(1))
if mult < 1.3888 or mult > 5.0 then
mult = 1.3888
end if
end if
screen _newimage(1000, 500, 12)
for i = cn to 5000
on error goto 100
for z = 1 to 500
x = 2 * cos(_d2r(z / mult))
y = 2 * sin(_d2r(z / mult))
select case i
case 1
n = Z10B46#(x, y, z)
case 2
n = Z10B48#(x, y, z)
case 3
n = Z10B4A#(x, y, z)
case 4
n = Z10B4C#(x, y, z)
case 5
n = Z10B4E#(x, y, z)
case 6
n = Z10B50#(x, y, z)
case 7
n = Z10B52#(x, y, z)
case 8
n = Z10B54#(x, y, z)
case 9
n = Z10B56#(x, y, z)
case 10
n = Z10B58#(x, y, z)
' :
' :
case 4990
n = Z13240#(x, y, z)
case 4991
n = Z13242#(x, y, z)
case 4992
n = Z13244#(x, y, z)
case 4993
n = Z13246#(x, y, z)
case 4994
n = Z13248#(x, y, z)
case 4995
n = Z1324A#(x, y, z)
case 4996
n = Z1324C#(x, y, z)
case 4997
n = Z1324E#(x, y, z)
case 4998
n = Z13250#(x, y, z)
case 4999
n = Z13252#(x, y, z)
case 5000
n = Z13254#(x, y, z)
end select
endoflongcase:
v(z) = n
next
on error goto 0
smaller = 0
largger = 0
for z = 1 to 500
if v(z) < smaller then smaller = v(z)
if v(z) > largger then largger = v(z)
next
if int(smaller * 1e+6) = 0 and int(largger * 1e+6) = 0 then
cls
_continue
end if
redu$ = ""
if abs(smaller) > abs(largger) then factdiv = abs(smaller) else factdiv = abs(largger)
do while factdiv > 1e+6
redu$ = "*"
smaller = smaller / 100
largger = largger / 100
if abs(smaller) > abs(largger) then factdiv = abs(smaller) else factdiv = abs(largger)
loop
_title _trim$(str$(i)) + ": " + redu$ + "Smaller =" + str$(smaller) + "| " + redu$ + "Larger =" + str$(largger)
window screen(smaller, 1)-(largger, 500)
doscreen:
pset(v(1), 1), 15
for z = 2 to 500
line -(v(z), z), 15
next
for j = 1 to 30
_delay 0.1
if _keydown(27) then exit for
next
cls
if _keydown(27) then exit for
next
system
100 n = 0
resume endoflongcase
' :
' :
'then what follows are the functions to plot graphs with.
forceq-graph.bas.zip (Size: 125.59 KB / Downloads: 44)
|
|
|
Fireworks! |
Posted by: Dustinian - 07-04-2023, 05:27 PM - Forum: Programs
- Replies (13)
|
 |
This is a fireworks program I've been working on for some time; finally polished it up today in honor of the 4th. Very open to feedback!
Code: (Select All) 'FIREWORK.BAS
'============
'DESCRIPTION
'-----------
' A fireworks screensaver for QBasic.
'AUTHOR
'------
' Dustinian Camburides
'PLATFORM
'--------
' Written in QB64. I hope to make it QBasic-compatible, but no work on that yet.
'VERSION
'-------
'1.0, 2022-09-08: First working version.
'1.1, 2023-07-04: Changed hues by month.
'META
'----
'$DYNAMIC
'USER-DEFINED TYPES
'------------------
TYPE Particle
X0 AS SINGLE 'Current X value of particle (current frame) (used to draw flare point).
Y0 AS SINGLE 'Current Y value of particle (current frame) (used to draw flare point).
X1 AS SINGLE 'Previous X value of particle (last frame) (used to draw bright trail).
Y1 AS SINGLE 'Previous Y value of particle (last frame) (used to draw bright trail).
X2 AS SINGLE 'Previous X value of particle (frame before last) (used to draw dim trail).
Y2 AS SINGLE 'Previous Y value of particle (frame before last) (used to draw dim trail).
Angle AS SINGLE 'Trajectory of particle (degrees).
Velocity AS SINGLE 'Velocity of particle (pixels per frame).
Stage AS INTEGER 'Stage of particle (a particle with one or more stages left will "burst" when the fuse is 0).
Hue AS INTEGER 'The hue of the particle (this the bright color, the program assumes that (Hue MINUS 8) is the dim color).
Fuse AS INTEGER 'The number of frames left before the particle bursts or burns out.
END TYPE
TYPE Hue
Brighter AS INTEGER
Dimmer AS INTEGER
END TYPE
'SUBS
'----
DECLARE SUB Initialize_Hues (Hues() AS Hue)
DECLARE SUB Remove_Particle (Particles() AS Particle, ID AS INTEGER)
DECLARE SUB Append_Particle (Particles() AS Particle, New_Particle AS Particle)
DECLARE SUB Particle_Burst (Current AS Particle, Past AS Particle)
DECLARE SUB Particle_Move (Current AS Particle)
DECLARE SUB Particle_Draw (Current AS Particle, Hues() AS Hue)
DECLARE FUNCTION NewX! (X AS SINGLE, Angle AS SINGLE, Distance AS SINGLE)
DECLARE FUNCTION NewY! (Y AS SINGLE, Angle AS SINGLE, Distance AS SINGLE)
DECLARE FUNCTION RandomBetween% (Minimum AS INTEGER, Maximum AS INTEGER)
'CONSTANTS
'---------
CONST X_MIN = 250 'Minimum X value of firework launch point.
CONST X_MAX = 425 'Maximum X value of firework launch point.
CONST Y_MIN = 350 'Minimum Y value of firework launch point.
CONST Y_MAX = 350 'Maximum Y value of firework launch point.
CONST ANGLE_MIN = 135 'Mimimum angle of firework launch (degrees) (MINUS 180).
CONST ANGLE_MAX = 225 'Maximum angle of firework launch (degrees) (MINUS 180).
CONST VELOCITY_MIN = 5 'Minimum velocity of firework launch (pixels per frame).
CONST VELOCITY_MAX = 12 'Maximum velocity of firework launch (pixels per frame).
CONST STAGE_MIN = 1 'Minimum stages of firework at launch (will burst until 0).
CONST STAGE_MAX = 2 'Maximum stages of firework at launch (will burst until 0).
CONST FUSE_MIN = 20 'Minimum frames the firework will last until the next stage.
CONST FUSE_MAX = 30 'Maximum frames the firework will last until the next stage.
CONST BURST_MIN = 15 'Minimum number of particles that will be produced by a burst.
CONST BURST_MAX = 25 'Maximum number of particles that will be produced by a burst.
CONST DELAY = .04 'The number of seconds between snowflake recalculation / re-draw... QBasic can't detect less than 0.04 seconds...
CONST NEWFIREWORKODDS = 11 'The odds a new firework will be launched.
'VARIABLES
'---------
DIM sngStart AS SINGLE 'The timer at the start of the delay loop.
DIM intParticle AS INTEGER 'The current particle being worked in the loop.
DIM intChildParticles AS INTEGER 'The number of child particles being created after a burst.
DIM intChildParticle AS INTEGER 'The current child particle being worked in the loop.
DIM Fireworks(0) AS Particle 'All of the particles in the fireworks show.
DIM New_Particle AS Particle 'The new particle being created at launch.
DIM Hues(0) AS Hue 'An array of brighter / dimmer firework hues.
'PROCEDURES
'----------
'INITIALIZE SCREEN: Set the screen to mode 9.
'Active page (where the cls, pset, and line commands occur) of 0 and a v
'Visible page (that the user sees) of 1.
'640 X 350
SCREEN 9, , 0, 1: CLS
'INITIALIZE HUES
CALL Initialize_Hues(Hues())
'INITIALIZE TIMER
TIMER ON: RANDOMIZE TIMER
'LOOP EVERY FRAME
WHILE INKEY$ = ""
'Reset current particle...
intParticle = LBOUND(Fireworks)
'Start timer...
sngStart = TIMER
'If we generate a random number within the new firework odds...
IF RandomBetween%(1, 100) <= NEWFIREWORKODDS THEN
'Launch a new firework...
New_Particle.X0 = RandomBetween%(X_MIN, X_MAX)
New_Particle.Y0 = RandomBetween%(Y_MIN, Y_MAX)
New_Particle.X1 = New_Particle.X0
New_Particle.Y1 = New_Particle.Y0
New_Particle.X2 = New_Particle.X0
New_Particle.Y2 = New_Particle.Y0
New_Particle.Angle = RandomBetween%(ANGLE_MIN, ANGLE_MAX) - 180
New_Particle.Velocity = RandomBetween%(VELOCITY_MIN, VELOCITY_MAX)
New_Particle.Stage = RandomBetween(STAGE_MIN, STAGE_MAX)
New_Particle.Hue = RandomBetween(LBOUND(Hues), UBOUND(Hues))
New_Particle.Fuse = RandomBetween(FUSE_MIN, FUSE_MAX)
CALL Append_Particle(Fireworks(), New_Particle)
END IF
'For each particle...
WHILE intParticle <= UBOUND(Fireworks)
'If the fuse is zero...
IF Fireworks(intParticle).Fuse = 0 AND Fireworks(intParticle).Stage > 0 THEN
'Burst the particle...
intChildParticles = RandomBetween%(BURST_MIN, BURST_MAX)
FOR intChildParticle = 0 TO intChildParticles
CALL Particle_Burst(New_Particle, Fireworks(intParticle))
CALL Append_Particle(Fireworks(), New_Particle)
NEXT intChildParticle
END IF
'If the fuse is > -2...
IF Fireworks(intParticle).Fuse > -2 THEN
'Draw the particle...
CALL Particle_Move(Fireworks(intParticle))
CALL Particle_Draw(Fireworks(intParticle), Hues())
'MAYBE ONLY INCREMENT PARTICLES HERE?
intParticle = intParticle + 1 'WE'RE SKIPPING FRAMES SOMETIMES HERE...
ELSE
CALL Remove_Particle(Fireworks(), intParticle)
END IF
WEND
'Wait for the delay to pass before starting over...
WHILE (TIMER < (sngStart + DELAY)) AND (TIMER >= sngStart)
WEND
'Copy the active page (where we just drew the snow) to the visible page...
PCOPY 0, 1
'Clear the active page for the next frame...
CLS
WEND
TIMER OFF
PCOPY 0, 1
END
SUB Initialize_Hues (Hues() AS Hue)
'Sets the hues by month using the default 16-color palette.
SELECT CASE VAL(LEFT$(DATE$, 2))
CASE 2 'February
'Pink and White
REDIM Hues(1) AS Hue
Hues(0).Brighter = 13: Hues(0).Dimmer = 5
Hues(1).Brighter = 15: Hues(1).Dimmer = 7
CASE 3 'March
'Green and White
REDIM Hues(1) AS Hue
Hues(0).Brighter = 10: Hues(0).Dimmer = 2
Hues(1).Brighter = 15: Hues(1).Dimmer = 7
CASE 7 'July
'Red, White, and Blue
REDIM Hues(2) AS Hue
Hues(0).Brighter = 12: Hues(0).Dimmer = 4
Hues(1).Brighter = 15: Hues(1).Dimmer = 7
Hues(2).Brighter = 9: Hues(2).Dimmer = 1
CASE 12 'December
'Red and Green
REDIM Hues(1) AS Hue
Hues(0).Brighter = 12: Hues(0).Dimmer = 4
Hues(1).Brighter = 10: Hues(1).Dimmer = 2
CASE ELSE
'All colors 9-15
REDIM Hues(6) AS Hue
Hues(0).Brighter = 9: Hues(0).Dimmer = 1
Hues(1).Brighter = 10: Hues(1).Dimmer = 2
Hues(2).Brighter = 11: Hues(2).Dimmer = 3
Hues(3).Brighter = 12: Hues(3).Dimmer = 4
Hues(4).Brighter = 13: Hues(4).Dimmer = 5
Hues(5).Brighter = 14: Hues(5).Dimmer = 6
Hues(6).Brighter = 15: Hues(6).Dimmer = 7
END SELECT
END SUB
SUB Remove_Particle (Particles() AS Particle, ID AS INTEGER)
'Note: This would be a lot easier with PRESERVE, but I want to be QB1.1/4.5 compatible... one day.
DIM intMember AS INTEGER
'Create a place to save the data...
DIM Temp(LBOUND(Particles) TO UBOUND(Particles) - 1) AS Particle
'Save the data before the ID...
FOR intMember = LBOUND(Particles) TO ID - 1
Temp(intMember) = Particles(intMember)
NEXT intMember
'Save the data after the ID...
FOR intMember = ID + 1 TO UBOUND(Particles)
Temp(intMember - 1) = Particles(intMember)
NEXT intMember
'Re-create the array with one less row...
REDIM Particles(LBOUND(Temp) TO UBOUND(Temp)) AS Particle
'Re-load the saved data back into the original array...
FOR intMember = LBOUND(TEMP) TO UBOUND(Temp)
Particles(intMember) = Temp(intMember)
NEXT intMember
END SUB
SUB Append_Particle (Particles() AS Particle, New_Particle AS Particle)
'Note: This would be a lot easier with PRESERVE, but I want to be QB1.1/4.5 compatible... one day.
DIM intMember AS INTEGER
'Create a place to save the data...
DIM Temp(LBOUND(Particles) TO UBOUND(Particles)) AS Particle
'Save the data...
FOR intMember = LBOUND(Particles) TO UBOUND(Particles)
Temp(intMember) = Particles(intMember)
NEXT intMember
'Re-create the array with one additional row...
REDIM Particles(LBOUND(Temp) TO UBOUND(Temp) + 1) AS Particle
'Re-load the saved data back into the original array...
FOR intMember = LBOUND(TEMP) TO UBOUND(Temp)
Particles(intMember) = Temp(intMember)
NEXT intMember
'Put the new particle at the end...
Particles(UBOUND(Particles)) = New_Particle
END SUB
SUB Particle_Burst (Current AS Particle, Past AS Particle)
'Basically set the child particle (after the burst) to the properties of its parent.
Current.X0 = Past.X0
Current.Y0 = Past.Y0
Current.X1 = Past.X0
Current.Y1 = Past.Y0
Current.X2 = Past.X0
Current.Y2 = Past.Y0
Current.Angle = RandomBetween%(0, 359)
Current.Velocity = RandomBetween%(2, 4)
Current.Stage = Past.Stage - 1
Current.Hue = Past.Hue
Current.Fuse = RandomBetween(10, 20)
END SUB
SUB Particle_Move (Current AS Particle)
'Move the tail forward.
Current.X2 = Current.X1
Current.X1 = Current.X0
Current.Y2 = Current.Y1
Current.Y1 = Current.Y0
'Move the particle along its current trajectory.
IF Current.Fuse > 0 THEN
Current.X0 = NewX!(Current.X0, Current.Angle, Current.Velocity)
Current.Y0 = NewY!(Current.Y0, Current.Angle, Current.Velocity)
END IF
'Burn Fuse
Current.Fuse = Current.Fuse - 1
END SUB
SUB Particle_Draw (Current AS Particle, Hues() AS Hue)
'Draw oldest segment
LINE (Current.X2, Current.Y2)-(Current.X1, Current.Y1), Hues(Current.Hue).Dimmer
'If the fuse hasn't been burnt out for more than one turn...
IF Current.Fuse > -1 THEN
'Draw newest segment
LINE (Current.X1, Current.Y1)-(Current.X0, Current.Y0), Hues(Current.Hue).Brighter
'If the fuse isn't burnt out...
IF Current.Fuse > 0 THEN
'Draw flare
PSET (Current.X0, Current.Y0), 15
END IF
END IF
END SUB
FUNCTION NewX! (X AS SINGLE, Angle AS SINGLE, Distance AS SINGLE)
NewX! = X + SIN(Angle * 3.141592 / 180) * Distance
END FUNCTION
FUNCTION NewY! (Y AS SINGLE, Angle AS SINGLE, Distance AS SINGLE)
NewY = Y! + ((COS(Angle! * 3.141592 / 180) * Distance!) * -1)
END FUNCTION
FUNCTION RandomBetween% (Minimum AS INTEGER, Maximum AS INTEGER)
RandomBetween% = CINT(Minimum + (RND * (Maximum - Minimum)))
END FUNCTION
|
|
|
Either QB64pe enhancement or IDGI |
Posted by: doppler - 07-03-2023, 02:26 PM - Forum: General Discussion
- Replies (7)
|
 |
After some thought (always bad for me), Either this will become a QB64pe enhancement or I Don't Get It.
I use drop files a lot since implemented a couple releases ago (v1.3). It's easy to use and setup. A couple of commands and your program can take a list of files dropped on a window. I want to take to the next level.
Drop them on the desktop icon link.! And process them. This a hidden feature (or not well known) in Microsoft windows. I read through the program doc's again. Not clear if it is already implemented.
Let the fun begin....
|
|
|
Circles and Ellipses(Tilt and Fill) |
Posted by: SMcNeill - 07-03-2023, 07:30 AM - Forum: SMcNeill
- Replies (1)
|
 |
Code optimized for QB64PE which we came up with several years back as a community. I thought I'd share it here, in case anyone ever needed it or wanted to make use of it again in the future.
Code: (Select All)
Screen _NewImage(800, 600, 32)
Dim TransRed As _Unsigned Long
Dim TransGreen As _Unsigned Long
Dim TransBlue As _Unsigned Long
TransRed = _RGBA(255, 0, 0, 128)
TransGreen = _RGBA(0, 255, 0, 128)
TransBlue = _RGBA(0, 0, 255, 128)
Call CircleFill(100, 100, 75, TransRed)
Call CircleFill(120, 120, 75, TransBlue)
Call EllipseFill(550, 100, 150, 75, TransBlue)
Call EllipseFill(570, 120, 150, 75, TransGreen)
Call EllipseTilt(200, 400, 150, 75, 0, TransGreen)
Call EllipseTilt(220, 420, 150, 75, 3.14 / 4, TransRed)
Call EllipseTiltFill(0, 550, 400, 150, 75, 3.14 / 6, TransRed)
Call EllipseTiltFill(0, 570, 420, 150, 75, 3.14 / 4, TransGreen)
End
Sub CircleFill (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
' CX = center x coordinate
' CY = center y coordinate
' R = radius
' C = fill color
Dim Radius As Integer, RadiusError As Integer
Dim X As Integer, Y As Integer
Radius = Abs(R)
RadiusError = -Radius
X = Radius
Y = 0
If Radius = 0 Then PSet (CX, CY), C: Exit Sub
Line (CX - X, CY)-(CX + X, CY), C, BF
While X > Y
RadiusError = RadiusError + Y * 2 + 1
If RadiusError >= 0 Then
If X <> Y + 1 Then
Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
End If
X = X - 1
RadiusError = RadiusError - X * 2
End If
Y = Y + 1
Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
Wend
End Sub
Sub EllipseFill (CX As Integer, CY As Integer, a As Integer, b As Integer, C As _Unsigned Long)
' CX = center x coordinate
' CY = center y coordinate
' a = semimajor axis
' b = semiminor axis
' C = fill color
If a = 0 Or b = 0 Then Exit Sub
Dim h2 As _Integer64
Dim w2 As _Integer64
Dim h2w2 As _Integer64
Dim x As Integer
Dim y As Integer
w2 = a * a
h2 = b * b
h2w2 = h2 * w2
Line (CX - a, CY)-(CX + a, CY), C, BF
Do While y < b
y = y + 1
x = Sqr((h2w2 - y * y * w2) \ h2)
Line (CX - x, CY + y)-(CX + x, CY + y), C, BF
Line (CX - x, CY - y)-(CX + x, CY - y), C, BF
Loop
End Sub
Sub EllipseTilt (CX, CY, a, b, ang, C As _Unsigned Long)
' CX = center x coordinate
' CY = center y coordinate
' a = semimajor axis
' b = semiminor axis
' ang = clockwise orientation of semimajor axis in radians (0 default)
' C = fill color
For k = 0 To 6.283185307179586 + .025 Step .025
i = a * Cos(k) * Cos(ang) + b * Sin(k) * Sin(ang)
j = -a * Cos(k) * Sin(ang) + b * Sin(k) * Cos(ang)
i = i + CX
j = -j + CY
If k <> 0 Then
Line -(i, j), C
Else
PSet (i, j), C
End If
Next
End Sub
Sub EllipseTiltFill (destHandle&, CX, CY, a, b, ang, C As _Unsigned Long)
' destHandle& = destination handle
' CX = center x coordinate
' CY = center y coordinate
' a = semimajor axis
' b = semiminor axis
' ang = clockwise orientation of semimajor axis in radians (0 default)
' C = fill color
Dim max As Integer, mx2 As Integer, i As Integer, j As Integer
Dim prc As _Unsigned Long
Dim D As Integer, S As Integer
D = _Dest: S = _Source
prc = _RGB32(255, 255, 255, 255)
If a > b Then max = a + 1 Else max = b + 1
mx2 = max + max
tef& = _NewImage(mx2, mx2)
_Dest tef&
_Source tef&
For k = 0 To 6.283185307179586 + .025 Step .025
i = max + a * Cos(k) * Cos(ang) + b * Sin(k) * Sin(ang)
j = max + a * Cos(k) * Sin(ang) - b * Sin(k) * Cos(ang)
If k <> 0 Then
Line (lasti, lastj)-(i, j), prc
Else
PSet (i, j), prc
End If
lasti = i: lastj = j
Next
Dim xleft(mx2) As Integer, xright(mx2) As Integer, x As Integer, y As Integer
For y = 0 To mx2
x = 0
While Point(x, y) <> prc And x < mx2
x = x + 1
Wend
xleft(y) = x
While Point(x, y) = prc And x < mx2
x = x + 1
Wend
While Point(x, y) <> prc And x < mx2
x = x + 1
Wend
If x = mx2 Then xright(y) = xleft(y) Else xright(y) = x
Next
_Dest destHandle&
For y = 0 To mx2
If xleft(y) <> mx2 Then Line (xleft(y) + CX - max, y + CY - max)-(xright(y) + CX - max, y + CY - max), C, BF
Next
_Dest D: _Dest S
_FreeImage tef&
End Sub
|
|
|
|