Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to fill-in a diamond without PAINT
#11
"Ahhh, I was wondering what you meant by "step away", and I was thinking you were going to do something with the for..next loop. I forgot about using step in the line command. A very cool solution."

Honestly I though I was going to do something in a For loop too, but then I remembered what you said like CircleFill... so fat and skinny is like Rectilinear Ellipse (axis parallel to x, y axis) or skinny and fat circles.
b = b + ...
Reply
#12
nice mod, B+. you know what is interesting? I think that horizontal lines along with LINE ... ,BF with the BF flag included, is faster than vertical lines with or without the BF flag. maybe someone can benchmark to know for sure
Reply
#13
LOL B+ you are almost reading my mind. In my Explorer game I'm making, with the map scrolling, I've been working on the cave map and the other day I added TONS of diamonds just as decorations and earlier today I made them random colors. I also made a cool looking dragon (a few of the same ones). I'm getting closer to finishing the game. It will probably just have 2 maps and won't be too technical.
Reply
#14
Dragon, now your talking! I made a Gorilla do a little jig way, way, way back at Naalaa, we were going to do a remake of Nibbles in Naalaa. Got into the art of throwing bananas, if I remember, I wonder if I could dig up that old piece of code, it'd be on an SD card before I stopped backing up Naalaa?

Johnno might remember? It'd be buried way way back in the forum.

When you blow up something with a banana, what should it look like?


Update:
   

Now for my next trick, translate it into QB64!
b = b + ...
Reply
#15
looks JBesque but not quite -- is this a variant of JB?
Reply
#16
(08-15-2022, 02:42 AM)vince Wrote: nice mod, B+.  you know what is interesting?  I think that horizontal lines along with LINE ... ,BF with the BF flag included, is faster than vertical lines with or without the BF flag.  maybe someone can benchmark to know for sure

Since I know so little about benchmarking, take this with a grain of salt, but this is just comparing horizontals with and without BF. The length of the line seems to make a big difference too. A 2 long line was something like ten times faster in the following:

Code: (Select All)
SCREEN _NEWIMAGE(1024, 512, 32)
DIM t!(10)
DIM m AS _MEM
m = _MEM(t!())

CLS
FOR it% = 1 TO 5
    _MEMPUT m, m.OFFSET + m.ELEMENTSIZE * it%, TIMER AS SINGLE
    FOR y% = 0 TO 511
        FOR x% = 0 TO 1024
            LINE (x%, y%)-(x% + 200, y%)
    NEXT x%, y%
    _MEMPUT m, m.OFFSET + m.ELEMENTSIZE * (it% + 5), TIMER AS SINGLE
    CLS
NEXT it%
FOR a% = 1 TO 5
    av## = av## + (t!(a% + 5) - t!(a%))
NEXT a%
av## = av## / 5

_MEMFILL m, m.OFFSET, 40, 0 AS _BYTE
FOR it% = 1 TO 5
    _MEMPUT m, m.OFFSET + m.ELEMENTSIZE * it%, TIMER AS SINGLE
    FOR y% = 0 TO 511
        FOR x% = 0 TO 1024
            LINE (x%, y%)-(x% + 200, y%), , BF
    NEXT x%, y%
    _MEMPUT m, m.OFFSET + m.ELEMENTSIZE * (it% + 5), TIMER AS SINGLE
    CLS
NEXT it%
FOR a% = 1 TO 5
    av2## = av2## + (t!(a% + 5) - t!(a%))
NEXT a%
av2## = av2## / 5
CLS
PRINT av##; " without BF"
PRINT av2##; " with BF"
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Reply
#17
LOL awesome B+! Reminds me of the QBasic Microsoft game called Gorillas. QB64 has this game, gor64.bas in the samples/misc folder. Big Grin
Reply
#18
Diamonds

Code: (Select All)
'  *            |             -           /      \
' ***          |||           ---        ///      \\\
'*****        |||||         -----     /////      \\\\\
' ***          |||           ---      ///          \\\
'  *            |             -       /              \

it seems that using LINE you must use the same number  of its high or width...
Reply
#19
And a completely different way to do this:

Code: (Select All)
$Color:32
Screen _NewImage(640, 480, 32)

Diamond = _NewImage(200, 200, 32)
_Dest Diamond
Cls , SkyBlue
_Dest 0

angle = 45
Do
    Cls
    DisplayImage Diamond, 320, 240, 1, 1, angle, 0
    angle = angle + 10
    Sleep
    _Display
Loop Until _KeyDown(27)


Sub DisplayImage (Image As Long, x As Integer, y As Integer, xscale As Single, yscale As Single, angle As Single, mode As _Byte)
    'Image is the image handle which we use to reference our image.
    'x,y is the X/Y coordinates where we want the image to be at on the screen.
    'angle is the angle which we wish to rotate the image.
    'mode determines HOW we place the image at point X,Y.
    'Mode 0 we center the image at point X,Y
    'Mode 1 we place the Top Left corner of oour image at point X,Y
    'Mode 2 is Bottom Left
    'Mode 3 is Top Right
    'Mode 4 is Bottom Right


    Dim px(3) As Integer, py(3) As Integer, w As Integer, h As Integer
    Dim sinr As Single, cosr As Single, i As _Byte
    w = _Width(Image): h = _Height(Image)
    Select Case mode
        Case 0 'center
            px(0) = -w \ 2: py(0) = -h \ 2: px(3) = w \ 2: py(3) = -h \ 2
            px(1) = -w \ 2: py(1) = h \ 2: px(2) = w \ 2: py(2) = h \ 2
        Case 1 'top left
            px(0) = 0: py(0) = 0: px(3) = w: py(3) = 0
            px(1) = 0: py(1) = h: px(2) = w: py(2) = h
        Case 2 'bottom left
            px(0) = 0: py(0) = -h: px(3) = w: py(3) = -h
            px(1) = 0: py(1) = 0: px(2) = w: py(2) = 0
        Case 3 'top right
            px(0) = -w: py(0) = 0: px(3) = 0: py(3) = 0
            px(1) = -w: py(1) = h: px(2) = 0: py(2) = h
        Case 4 'bottom right
            px(0) = -w: py(0) = -h: px(3) = 0: py(3) = -h
            px(1) = -w: py(1) = 0: px(2) = 0: py(2) = 0
    End Select
    sinr = Sin(angle / 57.2957795131): cosr = Cos(angle / 57.2957795131)
    For i = 0 To 3
        x2 = xscale * (px(i) * cosr + sinr * py(i)) + x: y2 = yscale * (py(i) * cosr - px(i) * sinr) + y
        px(i) = x2: py(i) = y2
    Next
    _MapTriangle (0, 0)-(0, h - 1)-(w - 1, h - 1), Image To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
    _MapTriangle (0, 0)-(w - 1, 0)-(w - 1, h - 1), Image To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
End Sub
Reply
#20
Drawing a filled diamond using the draw command.
Two subs each using X,Y, for the top corner, W for width, H for height, ANG for angle from X,Y and color KLR
Draw_diamond can leave gaps at some angles

Code: (Select All)
Screen _NewImage(800, 500, 256)
draw_diamond 300, 100, 60, 100, 45, 6
paint_diamond 450, 100, 60, 100, 25, 6
Input "Enter anything to continue", a$
Cls
For r = 0 To 360 Step 3
    _Limit 100
    Cls
    paint_diamond 450, 100, 60, 200, r, 10
    _Display
Next r

Sub draw_diamond (x, y, w, h, ang, klr)
    Draw "s4 bm" + Str$(x) + "," + Str$(y) + " ta" + Str$(ang)
    y2 = h / 2
    x2 = -(w / 2)
    x3 = (w / 2)
    For n = x2 To x3 Step 0.25
        Draw "bm" + Str$(x) + "," + Str$(y)
        If n < 0 Then
            Draw "m-" + Str$(Abs(n)) + ",+" + Str$(y2) + "m+" + Str$(Abs(n)) + "," + Str$(y2)
        End If
        If n >= 0 Then
            Draw "m+" + Str$(n) + ",+" + Str$(y2) + "m-" + Str$(n) + "," + Str$(y2)
        End If

    Next

    Draw "ta0"
End Sub

Sub paint_diamond (x, y, w, h, ang, klr)
    Draw "s4 bm" + Str$(x) + "," + Str$(y) + " ta" + Str$(ang)
    yc = h / 2
    xc = (w / 2)
    Draw "m-" + Str$(xc) + ",+" + Str$(yc) + " m+" + Str$(xc) + ", +" + Str$(yc) + "m+" + Str$(xc) + ",-" + Str$(yc) + "m-" + Str$(xc) + ",-" + Str$(yc) + "bm +0,+" + Str$(yc) + " P" + Str$(klr) + "," + Str$(klr)
    Draw "ta0"
End Sub
Reply




Users browsing this thread: 1 Guest(s)