Posted by: Petr - 03-05-2023, 08:47 PM - Forum: Petr
- No Replies
I use this program quite often myself. This is a program that loads a file in ICO format. Its use is easy:
Icon = LOADICO (filename, imagenumber)
or
Number of Images in file = LOADICO (filename, -1)
or
Display all images in file ICO = LOADICO(filename, 0)
It is intended to be used on a 32-bit screen. It's just a small feature, so I didn't make it a library. Attached are some ICO files to try. ICO files can be freely downloaded. The reason I chose ICO is that a single file can contain multiple sizes of the same icon. This is what you need when creating an application. Not every computer has the same screen size, so - it is necessary to place different sizes of the same icons. Yes, this can be solved internally via _PUTIMAGE with a single size, but this is another option.
Code: (Select All)
'Petr Preclik presents:
'LOADICO function. Use ico files as icons in your programs! Use it as: handle = LOADICON (ico_file_name$, number of frame in this ICO file)
' For list all images in ICO file set second parameter to zero (call it in 32 bit screen)
' For returning how much frames ICO contains, set second parameter as < 0.
Total = LOADICO(file$, -1) 'TOTAL now contains number all frames in ICO file
_PrintMode _KeepBackground
Print "File contains"; Total; "frames."
For all = 1 To Total
i& = LOADICO(file$, all)
If i& < -1 Then _PutImage (X, 100), i&, 0
X = X + _Width(i&)
_FreeImage i&
Next
Function LOADICO& (file As String, fram As Integer)
'file identity header
PD = _Dest
Type File_Head
reserved As Integer '0
id_Type As Integer '1
id_Count As Integer 'number of frames in file
End Type
Type ICO_Head
bWidth As _Unsigned _Byte
bHeight As _Unsigned _Byte
color_count As _Unsigned _Byte '0 = >256 colors
bReserved As _Unsigned _Byte '0
wPlanes As _Unsigned Integer 'number of bit layers
wBitCount As _Unsigned Integer 'bites per pixel
dwBytesInRes As Long 'image lenght included palette
dwImageOffset As Long 'icon begin from file begin (driving record)
End Type
Type Ico_Image
ThisSize As Long '40
width As Long
height As Long
biPlanes As Integer '1
BitCount As Integer 'bites per pixel, tj 1, 4 , 8, 24
Compression As Long '0 = BI_RGB, 1 = BI_RLE8, 2 = BI_RLE4
SizeImage As Long 'image size
XPelsPerMeter As Long '0
YPelsPerMeter As Long '0
nic As Long '0 'nothing :)
taky_nic As Long '0 'also nothing :) i have none informations and none sources - for what is this!
End Type
Type IcIm 'help array (maybe? - this is wroted long time ago... :-/ )
W As Integer
H As Integer
colors As _Unsigned _Byte
BPP As _Unsigned _Byte
L As Long
Offset As Long
WP As _Unsigned Integer
End Type
Dim FH As File_Head, IH As ICO_Head, II As Ico_Image
ch = FreeFile
If _FileExists(file$) Then Open file$ For Binary As #ch Else Print "ICO loader error: file "; file$; " not exist.": Sleep 2: System
Get #ch, , FH
If FH.reserved = 0 And FH.id_Type = 1 Then Else Print "unknown format!": System
frames = FH.id_Count 'frames number (total frames) in file
If fram < 0 Then LOADICO& = frames: Exit Function ' -1 is for returning number frames in file
If fram > frames Then Print "This file contains not so much images. File "; file$; " contains "; frames; "frames. Can not using frame"; fram: Sleep 2: Exit Function
' PRINT "Frames in file: "; frames
ReDim Ico(frames) As IcIm
For al_fr = 1 To frames
Get #ch, , IH
Ico(al_fr).W = IH.bWidth
Ico(al_fr).H = IH.bHeight
Ico(al_fr).colors = IH.color_count '0 = >256 colors
Ico(al_fr).BPP = IH.wBitCount 'bites per pixel
Ico(al_fr).L = IH.dwBytesInRes 'image lenght included palette
Ico(al_fr).Offset = IH.dwImageOffset + 1 'icon record byte start position from file begin
If IH.color_count = 0 Then IHcolor_count = 256 Else IHcolor_count = IH.color_count
Ico(al_fr).WP = IHcolor_count
Next al_fr
'vsechny hlavy ke vsem snimkum jsou nacteny. Tato hlava je ridici pro kazdy snimek.
'all heads for all frames are ready. This is head for every head
If fram = 0 Then vs = 1: ve = frames Else vs = fram: ve = fram
For all = vs To ve
Seek #ch, Ico(all).Offset 'posun na spravnou pozici skip to correct position
If Ico(all).BPP = 32 Then ' nejprve otestuju pritomnost PNG pokud je hloubka 32 bit: 'first testing, if PNG is contained in file, when bites per pixel is 32
current_position = Seek(ch)
Dim start_test As String * 8
' DIM end_test AS STRING * 12
start$ = Chr$(137) + Chr$(80) + Chr$(78) + Chr$(71) + Chr$(13) + Chr$(10) + Chr$(26) + Chr$(10)
Get #ch, , start_test$
If start_test$ = start$ Then
Ico(all).BPP = 32
Ico(all).W = 256
Ico(all).H = 256
icon& = _CopyImage(extract_png&(ch), 32): GoTo ______skip
Else
Seek #ch, current_position
End If
End If
Get #ch, , II ' nactu hlavu obrazku. Tato hlava je navic a nepouziva se, aspon mysim.... ' really i dont know for what is this, just some records
If Ico(all).BPP > 0 And Ico(all).BPP <= 8 Then depth = 256 Else depth = 32
If Ico(all).W = 0 Then Ico(all).W = 256
If Ico(all).H = 0 Then Ico(all).H = 256
Select Case Ico(all).BPP ' za havou bitmapy nasleduje paleta After bitmap header is palette
Case 1
PalLenght = 1
Case 4
PalLenght = 15 'ok pro 4 barvy OK for 4 colors
Case 8
PalLenght = 255
Case 0, 32
GoTo _______noPalete
End Select
ReDim pal As _Unsigned Long 'vypoctem potvrzeno long LONG confirmed :)
For palete = 0 To PalLenght
Get #ch, , pal
_PaletteColor palete, pal, icon&
Next palete
_______noPalete:
Select Case Ico(all).BPP 'podle bitove hloubky probehne vykresleni drawing starts by bit depth
Case 1 ' testovano na jednom jedinem pripade... this is tested just on ONE file
ReDim bwi As String, valuee As _Unsigned _Byte
For draw1 = 1 To Ico(all).W * Ico(all).H
Get #ch, , valuee
bwi = bwi + DECtoBIN$(valuee)
Next
drawX = 0
drawY = Ico(all).H
For DrawXOR = 1 To Ico(all).W * Ico(all).H
If (Mid$(bwi$, DrawXOR, 1)) = "1" Then PSet (drawX, drawY)
drawX = drawX + 1: If drawX >= Ico(all).W And Ico(all).H Mod 4 = 0 Then drawX = 0: drawY = drawY - 1
Next
Case 4 ' pro soubory o jednom snimku naprosto v poradku (neni podpora PNG ale to asi v 16ti barvach nebude potreba)
' for files contins one frame is this all right (is not PNG support in 16 colors, i think this is not need)
Dim R4 As _Unsigned _Byte
binary$ = ""
For READ_XOR_DATA = 1 To (Ico(all).W * Ico(all).H) / 2
Get #ch, , R4
binary$ = binary$ + DECtoBIN$(R4)
Next READ_XOR_DATA
Dim colors4(Len(binary$)) As _Byte
calc_color = 0
For calc_colors = 1 To Len(binary$) Step 4
colors4(calc_color) = BINtoDEC(Mid$(binary$, calc_colors, 4))
calc_color = calc_color + 1
Next calc_colors
binary$ = ""
clc = 0
drawX = -1
drawY = Ico(all).H - 1
For DrawXOR = 0 To Ico(all).W * Ico(all).H
drawX = drawX + 1: If drawX >= Ico(all).W And Ico(all).H Mod 8 = 0 Then drawX = 0: drawY = drawY - 1
If drawX < Ico(all).W Then PSet (drawX, drawY), colors4(clc): clc = clc + 1
Next
'Pak je AND maska (sirka * vyska) / 8 a nakonec data obrazku
'Then is AND mask (widht * height) / 8 and in end are image data
Erase colors4: binary$ = ""
AndMaskLen = (Ico(all).H * Ico(all).W) / 8
For AM = 1 To AndMaskLen
Get #ch, , R4
binary$ = binary$ + DECtoBIN$(R4)
Next AM
clc = 0
For DrawAND = 0 To Ico(all).W * Ico(all).H
drawX = drawX + 1: If drawX >= Ico(all).W And Ico(all).H Mod 8 = 0 Then drawX = 0: drawY = drawY - 1
If drawX <= Ico(all).W And Mid$(binary$, clc, 1) = "1" Then
_Source icon&
cur = Point(drawX, drawY)
PSet (drawX, drawY), 255 And cur: clc = clc + 1
End If
Next
_Source 0
Case 8
ReDim colors8(Ico(all).H * Ico(all).W) As _Unsigned _Byte
For calc_colors = 1 To Ico(all).H * Ico(all).W
Get #ch, , colors8(calc_colors)
Next calc_colors
binary$ = ""
AndMaskLen = (Ico(all).H * Ico(all).W) / 8 'predelavano
ReDim r5 As _Unsigned _Byte
For AM = 1 To AndMaskLen
Get #ch, , r5
binary$ = binary$ + DECtoBIN$(r5)
Next AM
clc = 0
For draw_itY = 1 To Ico(all).H
For draw_itX = 0 To Ico(all).W - 1
clc = clc + 1
_Source icon&
cur = Point(draw_itX + 1, draw_itY)
PSet (draw_itX, Ico(all).H - draw_itY), colors8(clc) ' XOR cur
Next: Next
drawY = Ico(all).H - 1
clc = 0
For DrawAND = 1 To Ico(all).W * Ico(all).H
drawX = drawX + 1: If drawX >= Ico(all).W And Ico(all).H Mod 4 = 0 Then drawX = 0: drawY = drawY - 1
clrr = Point(drawX, drawY)
clc = clc + 1
If Mid$(binary$, clc, 1) = "1" Then PSet (drawX, drawY), 255 And clrr
Next
_Source 0
Case 0, 32 'overeno, v tomto pripade se opravdu ctou 4 byty 'confirmed, in this case are really 4 bytes read
ReDim cache(1 To Ico(all).W, 1 To Ico(all).H) As _Unsigned Long
For draw_itY = 1 To Ico(all).H
For draw_itX = 1 To Ico(all).W
Get #ch, , cache(draw_itX, draw_itY)
Next: Next
For draw_itY = 1 To Ico(all).H
For draw_itX = 1 To Ico(all).W
PSet (draw_itX - 1, Ico(all).H - draw_itY), cache(draw_itX, draw_itY)
Next: Next
Erase cache
End Select
______skip:
_Dest PD
If fram = 0 Then 'function paramter 0 as fram is for view all images in ico file (my loop muss be in 32 bit graphic mode)
'vypis pokud bude paramter nula
If _PixelSize(_Dest) < 4 Then Print "LOADICO parameter is set as 0. This option is for view all frames in ICO and muss be used with 32 bit screen.": Sleep 2: Exit Function
______resetview:
If listed = 0 Then listed = 1: Cls: _PrintString (300, 20), " Image nr. Width Height BPP Color count": row = 40
If _Height - (row + 10) < 256 Then _PrintString (50, row + 100), "Press key for view next...": Sleep: Cls: listed = 0: GoTo ______resetview
_PutImage (50, row), icon&, 0
_FreeImage icon&
row = row + Ico(all).H + 10
info$ = " " + Str$(all) + " " + Str$(Ico(all).W) + " " + Str$(Ico(all).H) + " " + Str$(Ico(all).BPP) + " " + Str$(Ico(all).WP)
_PrintString (350, row - (Ico(all).H + 10 / 2)), info$
Else
If all = fram Then LOADICO& = icon&: _Dest PD: Exit Function Else _FreeImage icon&
End If
Next all
End Function
Function DECtoBIN$ (vstup)
For rj = 7 To 0 Step -1
If vstup And 2 ^ rj Then DECtoBI$ = DECtoBI$ + "1" Else DECtoBI$ = DECtoBI$ + "0"
Next rj
DECtoBIN$ = DECtoBI$
End Function
Function BINtoDEC (b As String)
For Si = 1 To Len(b)
e$ = Mid$(b$, Si, 1)
c = Val(e$) '
Sj = Len(b) - Si
BINtoDE = BINtoDE + (c * 2 ^ Sj)
Next Si
BINtoDEC = BINtoDE
End Function
Function extract_png& (ch) 'Warning. This function can be very easy used for extraction PNG files from all (also binary) files!
'BEEP
start$ = Chr$(137) + Chr$(80) + Chr$(78) + Chr$(71) + Chr$(13) + Chr$(10) + Chr$(26) + Chr$(10) 'PNG start ID string
eend$ = Chr$(0) + Chr$(0) + Chr$(0) + Chr$(0) + Chr$(73) + Chr$(69) + Chr$(78) + Chr$(68) + Chr$(174) + Chr$(66) + Chr$(96) + Chr$(130) 'PNG end ID string
Seek #ch, Seek(ch) - 8
Z = Seek(ch)
Dim scan As String * 12
Do
Get #ch, , scan$
If scan$ = eend$ Then Exit Do
Seek #ch, Seek(ch) - 11
Loop
K = Seek(ch)
png$ = Space$(K - Z)
Seek #ch, Z
Get #ch, , png$
swp = FreeFile
Open "---png_extr_" For Output As #swp
Close #swp: Open "---png_extr_" For Binary As #swp
Put #swp, , png$
Close #swp
extract_png& = _LoadImage("---png_extr_", 32)
Kill "---png_extr_"
png$ = ""
End Function
Posted by: Petr - 03-05-2023, 07:06 PM - Forum: Petr
- Replies (1)
Hey guys.
I found in the depths of the hard disk my older thing, which has only one task - to allow you to use mouse cursors in a way other than the built-in function such as _MOUSESHOW "LINK" and the like. The ANI files have the same format (or very similar), so I included them in the library as well, under the same command.
command:
handle = LOADCURSOR (path\file.cur) or
handle = LOADCURSOR (path\file.ani)
Function to the variable handle returns a positive number of the cursor or animation in the case of ani file.
Then there is the command PUTCURSOR (handle, positionX, positionY) - this command, like the _PUTIMAGE command, places the cursor image on the screen. It is intended for the graphics screen loop when the screen background is refreshed on each cycle. I could, if there was interest, make the modification to a hardware image, then you won't have to monitor the screen refresh, but the _Display command will be necessary.
_Putimage will never work with the handle returned by the LOADCURSOR function!
PUTCURSOR is also a common command and places animations loaded from ANI files in the same way.
Then we have the FREECURSOR command, it releases the loaded images of cursors or animations from memory. Usage: FREECURSOR (handle)
I've gone so far as to allow the decomposition of animation from ANI files into individual frames. For this you need the following 2 functions:
LENCURSOR - works only with ANI files - returns the number of ANI animation frames. Usage:
Frames = LENCURSOR (handle)
And the second function - it will allow you to get a handle from the animation compatible with the _PUTIMAGE command of each frame in the animation. Example for getting the third image in the animation:
Pic3 = DECOMPOSECURSOR (handle, 3)
This is an older program (I had to patch it a lot to get it to work in PE) and I have a feeling that someone on Linux once reported something to me about display issues. If this happens, please go to the cursor.bm file, subroutine PUTCUR, disable all the lines related to the mouse (110, 111, 112), I have a note that this should be the source of the problem at the time.
Finally, I would like to mention the so-called field within a field, I see on the forum that you deal with something like that. I use something like this in this program. So let's break down the cursor.bi file:
TYPE Cursors_internal
StartOffset AS LONG 'use ANI
EndOffset AS LONG
X_reduction AS INTEGER ' CUR X coordinate reduction read from file
Y_reduction AS INTEGER ' CUR Y coordinate reduction read from file
Image AS LONG ' own CUR image is saved here
Flag AS LONG '1 for ANI, 2 for CUR
END TYPE
DIM SHARED ACTIVE_MOUSE_CURSOR ' variable, which memorize new mouse cursor usage. Used in PutCur SUB
REDIM SHARED Internal_Recorded(0) AS Cursors_internal
REDIM SHARED Internal_Recorded_ANIs(0) AS LONG 'frames array
StartOffset.
What is it? That's exactly it. A field within a field. This value indicates the starting index number in the Internal_Recorded_ANIs field. This is because an animation in an ANI file can have many frames. So how to write them in one field? You just add an auxiliary field and that is the Internal_Recorded_ANIs field.
EndOffset
This is the index value of the Internal_Recorded_ANIs field, it indicates the last index value that belongs to that one particular ANI file.
See how easy it is now to add more and more ANI images?
X_reduction AS INTEGER ' CUR X coordinate reduction read from file
Y_reduction AS INTEGER ' CUR Y coordinate reduction read from file
these values are contained in the CUR and ANI files and specify the number of pixels to shift the display so that the mouse points where the image
Image AS LONG 'own CUR image is saved here
exactly as the comment says. When you load a CUR file, you get them as one image. This can be added directly to the main field, it's one record for one item, no problem with that.
Flag AS LONG '1 for ANI, 2 for CUR
this is just a note that is written here by LOADCURSOR, according to which the program knows whether it should take the image from the main or from the auxiliary field
Finally own field
REDIM SHARED Internal_Recorded(0) AS Cursors_internal
As you can see above: You call the file via its handle, which is the index number of the Internal_Recorder field. From this you will immediately know if it is a CUR or ANI file. For ANI, the first two records will tell you about the images that belong to that particular ANI. Next, learn about display corrections. So you have everything you need
BI, BM, ANI and CUR files in attachment (zip format)
Code: (Select All)
'$include:'cursors.bi'
'2023 easyest at first: Program need folders CUR and ANI contains *.cur filer in CUR directory and *.ani files in ANI directory (or rewrite paths)
'Easy - how use it:
'example how load cursor with yellow arrow (in file CUR\3dgarro.cur)
'You need 32 graphic screen for use:
Screen _NewImage(1024, 768, 32)
'Load cursor to memory:
YellowCursor = LOADCURSOR(".\CUR\3dgarro.cur")
'test if load is correct, value must be higher than zero:
If YellowCursor > 0 Then Print "Cursor load correct" Else Print "Cursor load failed": End
'show this cursor as mouse cursor:
Print _Dest
Do Until RB = -1
While _MouseInput: Wend
RB = _MouseButton(2)
Mx = _MouseX
MY = _MouseY
Cls 'reset screen
Print "Press right mouse button for quit", _Dest
PUTCURSOR YellowCursor, Mx, MY
' _Display
_Limit 20
Loop
_AutoDisplay
Print "Now freeing your cursor from memory..."
FREECURSOR YellowCursor
Sleep 3
Print "Loading file mentronom.ani"
M = LOADCURSOR("ANI\metronom.ani")
If M > 0 Then Print "Metronom.ani loaded correctly" Else Print "Loading failed"
Sleep 3
RB = 0
Do Until RB = -1
While _MouseInput: Wend
RB = _MouseButton(2)
Mx = _MouseX
MY = _MouseY
Cls 'reset screen
Print "Press right mouse button for quit"
PUTCURSOR M, Mx, MY
_Display
_Limit 20
Loop
_AutoDisplay
ImgF = LENCURSOR(M)
Print "That is not all. You can split the ANI file into individual images:"
Print "First step for this is - how much frames contains ANI file? Use function LENCURSOR!"
Print "Matronom.ani contains "; ImgF; "frames."
Sleep 3
Print "Ok"
Print "Now use function DecomposeCursor (handle, image number):"
Print "Extract all frames:"
Sleep 2
Cls
For all = 1 To ImgF
Image1 = DECOMPOSECURSOR(M, all)
_PutImage (300 + stpX, 450), Image1
stpX = stpX + _Width(Image1) * 2
_FreeImage Image1
Next
Print "Press any key for continue..."
Sleep
Cls
'continue previous old presentation
ReDim cursorsList(0) As String ' array contains drive path and file names
If WIN Then path$ = _CWD$ + "\cursors" Else path$ = "/cursors"
MakeList path$, "*.*", cursorsList() ' path, mask, array as STRING
Dim Animated_Cursors(UBound(cursorsList)) As Long
' load ANI and CUR files to memory (new - both use the same statements)
For a = 0 To UBound(cursorsList) - 1
Locate 1, 1: Print "Loading "; SHOW_PERCENTS(a, UBound(cursorsList) - 1); "%"
Animated_Cursors(a) = LOADCURSOR(cursorsList(a))
Next
path$ = _CWD$ + "\cur\aero_pen_xl.cur"
k = LOADCURSOR(path$) ' load mouse cursor, which is show on the screen with others cursors as mouse
b = a
x = 50: Y = 0 ' its because it is better to set it with _SETALPHA or _CLEARCOLOR by user, as need.
sb = 20
If UBound(cursorsList) > 48 Then OnScreenShow = 48 Else OnScreenShow = UBound(cursorsList) ' cursor to view to one screen: 40
Cls , _RGB32(25, 55, 100)
Do ' create on screen list for all cursors. Some CUR types have NOT UNVISIBLE BACKGROUND.
Do
If OnScreenShow > UBound(cursorsList) Then OnScreenShow = 48
start = OnScreenShow - 48
If UBound(cursorsList) < 48 Then OnScreenShow = UBound(cursorsList): start = LBound(cursorsList)
For a = start To OnScreenShow - 1
Y = Y + 55
If Y > _Height - 55 Then Y = 55: x = x + 250
If x > _Width Then x = 50: Y = 0
_PrintMode _KeepBackground
Cname$ = Right$(cursorsList(a), LastPos(cursorsList(a), Chr$(92))) + " [" + LTrim$(Str$(a)) + "]" ' _revinstr not exists in time i developed this (or i use older IDE :} )
If Len(Cname$) > 19 Then Cname$ = "..." + Right$(Cname$, 16)
_PrintString (x + 70, Y + 5), Cname$
Line (x, Y)-(x + 48, Y + 48), _RGB32(25, 55, 100), BF
PUTCURSOR Animated_Cursors(a), x, Y
Next
x = 50: Y = 0
PCopy _Display, 1
While _MouseInput: Wend
PUTCURSOR k, _MouseX, _MouseY
_PrintString (650, 730), "Press space for next or ESC for end"
_Display
' _LIMIT 15
PCopy 1, _Display
k& = _KeyDown(32)
kk& = _KeyDown(27)
Loop Until k& Or kk&
If kk& Then Exit Do
OnScreenShow = OnScreenShow + 40
_Delay .2
x = 50: Y = 0
Cls , _RGB32(25, 55, 100)
PCopy _Display, 1
Loop
Screen my&
For free = 1 To UBound(cursorsList) - 2 'index cursorslist - 1 is cursor named "k", You can ask to it with "PRINT k" if k is LOADCURSOR output value.
FREECURSOR free ' delete all cursors from memory, not "k" cursor
Next
FREECURSOR k
_Source my&
_Dest my&
Cls
vv& = _NewImage(50, 50, 256)
_ClearColor 0, vv&
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
If WIN Then
HourGlas = LOADCURSOR(_CWD$ + "\cursors\hourglas.ani")
M = LOADCURSOR(_CWD$ + "\cursors\hourgla2.ani") ' loading other cursor with name "m"
Else
HourGlas = LOADCURSOR(cwd$ + "/cursors/hourglas.ani")
M = LOADCURSOR(cwd$ + "/cursors/hourgla2.ani")
End If
If HourGlas < 1 Then Beep 'if is image not saved in memory, then beep (inspired with newimage)
Do
_Dest vv&
Cls , 255
PUTCURSOR HourGlas, 0, 0
_Dest my&
_PutImage (_Width / 2 - 150, _Height / 2 - 150)-(_Width / 2 + 150, _Height / 2 + 150), vv&, my&
While _MouseInput: Wend
PUTCURSOR M, _MouseX, _MouseY
Color _RGB32(255, 128, 99)
_PrintString (650, 730), " Press ESC for end", my&
_Limit 20
_Display
Cls , _RGB32(0, 0, 0)
Loop While _KeyDown(27) <> -1
'$include:'cursors.bm'
Function SHOW_PERCENTS (num, based)
SHOW_PERCENTS = Int(num / (based / 100))
End Function
Môže nám niekto pomôcť.
Mám problém s jedným algoritmom. Neviem to vyriešiť.
Ide o triedenie čísel od najväčšieho po najmenšie.
Predmet - Objekt - Strana - súradnice
- súradnice
- súradnice
- súradnice
- súradnice
- súradnice
Predmet - Objekt - Strana - súradnice
- súradnice
- súradnice
Objekt - Strana - súradnice
- súradnice
- súradnice
- súradnice
- súradnice
- súradnice
Objekt - Strana - súradnice
- súradnice
- súradnice
- súradnice
- súradnice
- súradnice
Predmet - Objekt - Strana - súradnice
- súradnice
- súradnice
Strana - súradnice
- súradnice
- súradnice
Strana - súradnice
- súradnice
- súradnice
Strana - súradnice
- súradnice
- súradnice
Predmet - Objekt - Strana - súradnice
- súradnice
- súradnice
- súradnice
- súradnice
- súradnice
Každý predmet má niekoľko objektov.
Každý objekt má niekoľko strán
Každá strana má niekoľko súradníc.
Čo sa môže zmeniť.
Musím ich vytriediť.
Vk = náhodné číslo
Objekt(1, 1, 1, 0).z = Vk
Objekt(1, 1, 1, 1).x = -Vk
Objekt(1, 1, 1, 1).y = -Vk
Objekt ( 2 , 1 , 2 , 6 )
Predmet - Objekt - Strana - súradnice
Počítal som súradnice a spočítal steny na obejct.
Teraz mám Predmet a Objekt
Skúsil som toto a nefunguje to veľmi dobre:
SwapStran(i, a, b).z = SwapStran(i, a, b).z + Z
SwapObjektov(i, a).z = SwapObjektov(i, a).z + SwapStran(i, a, b).z
--
SwapSubjektov(i).z = SwapSubjektov(i).z + SwapObjektov(i, a).z
toto už nie je možné
pretože súčet rôznych predmetov je príliš veľký a nefunguje to
--
SwapingStran:
Pre i = 1 Do PocetSubjektov
Ak PovolenieSwapObjektov(i) = 1 Potom
Znovu = 0
Pre a = 1 To Subjekt(i).PocetObjektov
Pre b = 1 To Subjekt(i).PocetStran
k = 1: Ak b = Predmet(i).PocetStran Potom k = 0
Ak SwapStran(i, a, b).z > SwapStran(i, a, b + k).z Potom
Swap SwapStran(i, a, b).z, SwapStran(i, a, b + k).z
Znovu = 1
Koniec Ak
Ďalej b
Ďalej a
Ak Znovu = 1, potom prejdite na SwapingStran:
Koniec Ak
Ďalej i
SwapingObjektov:
Pre i = 1 Do PocetSubjektov
Ak PovolenieSwapObjektov(i) = 1 Potom
Znovu = 0: O = 0: Ak i = PocetSubjektov Potom O = 1
Pre a = 1 To Subjekt(i).PocetObjektov
k = 1: Ak a = Subjekt(i).PocetObjektov Potom k = 0
Ak SwapObjektov(i - O, a).z < SwapObjektov(i, a + k).z Potom
Swap SwapObjektov(i - O, a).z, SwapObjektov(i, a + k).z
Znovu = 1
Koniec Ak
Ďalej a
Koniec Ak
Ďalej i
If Znovu = 1 Then GoTo SwapingObjektov
-------------------------------------------------- -------------------------------------
Tu je problém:
Výmena Subjektov:
Znovu = 0: ii = 0: a1 = 1: a = 0
Pre i = 1 Do PocetSubjektov
ii = ii + 1
Ak i + ii >= PocetSubjektov Potom ii = 0: Znovu = 0
Ak PovolenieSwapObjektov(i) = 1 alebo PovolenieSwapObjektov(i + ii) = 1 Potom
Do
a = a + 1
Ak SwapObjektov(i, a).z < SwapObjektov(i + ii, a1).z Potom
Swap SwapObjektov(i, a).z, SwapObjektov(i + ii, a1).z
Znovu = 1
Koniec Ak
Ak a >= Predmet(i).PocetObjektov Potom
a = 0
a1 = a1 + 1
Koniec Ak
Ak a1 >= Subjekt(i + ii).PocetObjektov Then a1 = 1: Exit Do
Slučka, kým znovu = 1
Koniec Ak
Ďalej i
If Znovu = 1 Then GoTo SwapingSubjektov
Posted by: Petr - 03-04-2023, 08:28 PM - Forum: Petr
- Replies (2)
On purpose. Who remembers my first program, back on the old
Galleon forum?
Hey guys, don't expect any physics! This was written purely for the show, for the joy of writing! Forget about any calculations! This is just total crap I love! PBF file is need!
Code: (Select All)
'programmed Petr Preclik. Contains none graphics orgy.
'DATE: 04/2018
start:
SmerY = 1
start = 0
BalonX = 125: BalonY = 10
If left = 0 And right = 0 And autostarted = 0 Then menu
Cls: _AutoDisplay
If _FileExists("voll.pbf") Then
Do While I$ <> Chr$(27)
_PrintMode _KeepBackground
' COLOR 0, 2
If oldleft <> left Then oldleft = left: score$ = Str$(left) + "-" + Str$(right): Locate 23, (80 - Len(score$)) / 2: Print score$
If oldright <> right Then oldright = right: Locate 23, 17: Print left; " - "; right
If autostarted = 0 Then I$ = InKey$
Color 15, 0
'============================================
If vs And autostarted Then
l = l + 1
Select Case l
Case 1
j$ = InKey$
If j$ = Chr$(27) Then
autostarted = 0: vs = 0: ODPOCET = Timer: j$ = "": GoTo start
Else I$ = j$
End If
Case 2
AUTOSTART 1: l = 0
End Select
End If
'=============================================
If Timer > ODPOCET And vs = 0 Then AUTOSTART 0
TestSmeru
If rest Then rest = 0: GoTo start
Select Case I$
Case "S", "s": start = 1: ODPOCET = 99999: pisk
Case Chr$(0) + Chr$(77)
pravysmer = 1
VidP = VidP + 1: If VidP > 13 Then VidP = 10
PravyX = PravyX + 1
If PravyX > 270 Then
PravyX = 270
doraz
End If
Case "D", "d"
levysmer = 1
VidL = VidL + 1: If VidL > 4 Then VidL = 1
LevyX = LevyX + 1
If LevyX > 100 Then
LevyX = 100
doraz
End If
Case Chr$(0) + Chr$(75)
pravysmer = 2
VidP = VidP - 1: If VidP < 10 Then VidP = 13
PravyX = PravyX - 1
If PravyX < 150 Then
PravyX = 150
doraz
End If
Case "A", "a"
levysmer = 2
VidL = VidL - 1: If VidL < 1 Then VidL = 4
LevyX = LevyX - 1
If LevyX < 10 Then
LevyX = 10
doraz
End If
Case Chr$(13)
If delkaskoku = 0 Then delkaskoku = Timer + .50
While delkaskoku > 0
Vyskok = 1
TestBalonu
TestSmeru
Select Case delkaskoku - Timer
Case Is > .25: PravyY = PravyY - 2
' TestBalonu
If PravyY < 20 Then PravyY = 20
If pravysmer = 1 Then
VidP = VidP + 1: If VidP > 13 Then VidP = 10
PravyX = PravyX + 1
If PravyX > 270 Then
PravyX = 270
doraz
End If
End If
If pravysmer = 2 Then
VidP = VidP - 1: If VidP < 10 Then VidP = 13
PravyX = PravyX - 1
If PravyX < 150 Then
PravyX = 150
doraz
End If
End If
Case Is < .25
' TestBalonu
PravyY = PravyY + 2
If PravyY >= 101 Then
PravyY = 101
delkaskoku = 0
I$ = ""
End If
End Select
okoli
rozpis VidP, PravyX, PravyY
rozpis Balon, BalonX, BalonY
rozpis VidL, LevyX, LevyY
rozpis 9, 130, 100
Line (0, 163)-(320, 163)
_Display
_Limit 30
Cls
Wend
Case Chr$(32)
If delkaskokuL = 0 Then delkaskokuL = Timer + .50
While delkaskokuL > 0
Vyskok = 1
TestBalonu
TestSmeru
Select Case delkaskokuL - Timer
Case Is > .25
' TestBalonu
LevyY = LevyY - 2
If LevyY < 20 Then levy = 20
If levysmer = 1 Then
VidL = VidL + 1: If VidL > 4 Then VidL = 1
LevyX = LevyX + 1
If LevyX > 100 Then
LevyX = 100
doraz
End If
End If
If levysmer = 2 Then
VidL = VidL - 1: If VidL < 1 Then VidL = 4
LevyX = LevyX - 1
If LevyX < 10 Then
LevyX = 10
doraz
End If
End If
Case Is < .25
'TestBalonu
LevyY = LevyY + 2
If LevyY >= 102 Then
LevyY = 102
delkaskokuL = 0
I$ = ""
End If
End Select
okoli
rozpis VidP, PravyX, PravyY
rozpis Balon, BalonX, BalonY
rozpis VidL, LevyX, LevyY
rozpis 9, 130, 100
Line (0, 163)-(320, 163)
_Display
_Limit 30
Cls
Wend
End Select
TestBalonu
If Timer > BalonTime Then BalonTime = Timer + .5: Balon = Balon + 1: If Balon > 8 Then Balon = 5
okoli
rozpis VidP, PravyX, PravyY ' right player frame, coordinate X, coordinate Y
rozpis Balon, BalonX, BalonY ' ball frame, coordinate X, coordinate Y
rozpis VidL, LevyX, LevyY ' left player frame, coordinate X, coordinate Y
rozpis 9, 130, 100
Line (0, 163)-(320, 163)
_Display
_Limit 30
Cls
Loop
left = 0: right = 0: autostarted = 0: vs = 0
GoTo start
Else
Print "voll.pbf not found!": Sleep 2: System
End If
Sub menu
Shared netiskni
netiskni = 0
_AutoDisplay: _KeyClear
I$ = ""
If Not vs Then ODPOCET = Timer + 30
SmerY = 1
start = 0
BalonX = 125: BalonY = 10
fto& = _NewImage(60, 60, 256)
_Dest fto&
rozpis 7, 0, 0
_Dest 0
netiskni = 1
po = 50
Do While I$ <> Chr$(27)
Cls
uhel = uhel + 3: If uhel > 360 Then uhel = 1
rotation fto&, 80, po, uhel, 1.5
I$ = InKey$
If Timer > ODPOCET And vs = 0 Then I$ = "3"
center 10, "Volleyball - B/W"
center 25, "Press keys 1 - 6 or arrows and enter"
_PrintString (100, 50), "1: 1 player and computer"
_PrintString (100, 70), "2: 2 players"
_PrintString (100, 90), "3: demo"
_PrintString (100, 110), "4: About"
_PrintString (100, 130), "5: Sound setup"
_PrintString (100, 150), "6: End"
Select Case I$
Case Chr$(0) + Chr$(80): po = po + 20
Case Chr$(0) + Chr$(72): po = po - 20
Case Chr$(13): I$ = Str$(((po + 10) / 20) - 2)
End Select
Select Case Val(I$)
Case 3: ODPOCET = Timer: Exit Sub ' AUTOSTART 2 PLRS
Case 2: autostarted = 0: Exit Sub ' PLAY GAME 2 PLRS
Case 4: about: menu ' ABOUT
Case 5: If snd = 0 Then snd = 1: _PrintString (100, 180), "Sound ON": _Display: Sleep 2 Else snd = 0: _PrintString (100, 180), "Sound OFF": _Display: Sleep 2 ' SOUND
Case 6: _FreeImage fto&: _MouseShow: System ' QUIT
Case 1: AUTOSTART 1: ODPOCET = Timer: Exit Sub ' CLS: menu ' PLAY GAME 1 PLR VS PC
End Select
If po > 150 Then po = 150
If po < 50 Then po = 50
If Len(I$) And I$ <> "3" Then ODPOCET = Timer + 30 'NYNI
_Display
_Limit 20
I$ = ""
Loop
End Sub
Sub about
Cls
Locate 2
Print "About:"
Locate 5
Print "This is game for 0 or 1 or 2 players. "
Print "Its shared so as it is, without hiscore."
Print "Contains automatic demo start after 30 sec."
Print
Locate 12
Print "Use A, D for move left player, S for "
Print "Ball, space for jump left."
Print "Use arrows left and right for move right"
Print "player, enter for jump right."
Print
Locate 20
Print "Writed Petr P."
Print
Print "Press key...."
_Display
Sleep
End Sub
Sub center (lin As Integer, text As String)
centr = (_Width / 2 - _PrintWidth(text) / 2)
_PrintString (centr, lin), text$
End Sub
Sub AUTOSTART (mode)
Shared tah
Select Case mode
Case 0 ' this is call if plays PC vs PC
autostarted = 1
If start = 0 Then start = 1
tah = tah + 1
Select Case tah
Case 1: If BalonX - 30 > LevyX Then I$ = "d" ' on coordinates based computer "intelligence"
Case 2: If BalonX - 30 < LevyX Then I$ = "a"
Case 3: If BalonX + 60 > PravyX Then I$ = Chr$(0) + LTrim$(Chr$(77))
Case 4: If BalonX + 30 < PravyX Then I$ = Chr$(0) + LTrim$(Chr$(75))
Case 5: If BalonX + 60 > 220 Then I$ = Chr$(13)
Case 6: If BalonX - 30 < 40 Then I$ = " "
tah = 0
End Select
If InKey$ <> "" Then autostarted = 0: ODPOCET = Timer + 20: left = 0: right = 0: restart 3
Case 1 ' this run, if plays human vs computer.
vs = 1
autostarted = 1
If start = 0 Then start = 1
tah = tah + 1
ODPOCET = Timer
' SHARED j$
Select Case tah
Case 5: If BalonX - 30 > LevyX Then I$ = "d" ' computer drive one player.
Case 6: If BalonX - 30 < LevyX Then I$ = "a"
Case 7: If BalonX - 30 < 90 Then I$ = Chr$(32)
End Select
If tah > 9 Then tah = 0
End Select
End Sub
Sub TestSmeru ' sub for testing how player go. If to right or to left.
Select Case pravysmer
Case 1
VidP = VidP + 1: If VidP > 13 Then VidP = 10
PravyX = PravyX + 1
If PravyX > 270 Then
PravyX = 270: pravysmer = 0
doraz
End If
Case 2
VidP = VidP - 1: If VidP < 10 Then VidP = 13
PravyX = PravyX - 1
If PravyX < 150 Then
doraz
PravyX = 150: pravysmer = 0
End If
End Select
Select Case levysmer
Case 1
VidL = VidL + 1: If VidL > 4 Then VidL = 1
LevyX = LevyX + 1
If LevyX > 100 Then
LevyX = 100: levysmer = 0
doraz
End If
Case 2
VidL = VidL - 1: If VidL < 1 Then VidL = 4
LevyX = LevyX - 1
If LevyX < 10 Then
LevyX = 10: levysmer = 0
doraz
End If
End Select
End Sub
Sub TestBalonu ' sub for testing ball fly
If start = 1 Then
If Timer Mod 5 = 0 And Sgn(SmerY) = 1 Then SmerY = SmerY + .0981
If Timer Mod 5 = 0 And Sgn(SmerY) = -1 Then SmerY = SmerY + -0.0981
If Abs(SmerY) > 3 Then SmerY = 3 * Sgn(SmerY)
If Abs(SmerX) > 3 Then SmerX = 3 * Sgn(SmerX)
If Vyskok And inCircle(BalonX + 33, BalonY + 37, 20, LevyX + 20, LevyY + 20, 23) Or skok And inCircle(BalonX + 33, BalonY + 37, 20, PravyX + 35, PravyY + 22, 20) Then
klep
Vyskok = 0 'resi kolizi ve vyskoku ball collision on the fly if player skip
SmerX = Rnd + SmerX * -1: SmerY = Rnd + SmerY * -1
While inCircle(BalonX + 33, BalonY + 37, 20, LevyX + 20, LevyY + 20, 23) Or inCircle(BalonX + 33, BalonY + 37, 20, PravyX + 35, PravyY + 22, 20)
BalonX = BalonX + SmerX
BalonY = BalonY - (1 + Rnd * 10)
SmerY = SmerY - .0990
BalonX = BalonX + SmerX
If BalonY < 10 Then SmerY = SmerY * -1: Do While BalonY < 30: BalonY = BalonY + SmerY: Loop
Wend
'EXIT SUB
GoTo sut
End If
' ball collision if player go
If inCircle(BalonX + 33, BalonY + 37, 20, LevyX + 20, LevyY + 20, 23) Then SmerX = Rnd / 2 + SmerX * -1: SmerY = SmerY * -1: BalonX = BalonX + 10 * SmerX: BalonY = BalonY + 10 * SmerY: klep
If inCircle(BalonX + 33, BalonY + 37, 20, PravyX + 35, PravyY + 22, 20) Then SmerX = Rnd / 2 + SmerX * -1: SmerY = SmerY * -1: BalonX = BalonX + 10 * SmerX: BalonY = BalonY + 10 * SmerY: klep
sut:
If SmerX = 0 Then sm = Rnd * 10: If sm <= 5 Then SmerX = 1 Else SmerX = -1
If SmerY = 0 Then sm = Rnd * 10: If sm <= 5 Then SmerY = 1 Else SmerY = -1
If BalonY < 10 Then SmerY = SmerY * -1: BalonY = 10
If BalonY > 80 And BalonX < 160 Then right = right + 1: start = 0: pad: restart 1 ' left player fail
If BalonY > 80 And BalonX > 160 Then left = left + 1: start = 0: pad: restart 2 ' right player fail
BalonX = BalonX + SmerX: BalonY = BalonY + SmerY
End If
End Sub
Sub klep
If snd Then Sound 550, .2
End Sub
Sub restart (who As _Unsigned _Byte)
Select Case who
Case 1: LeftPlayer = LeftPlayer - 1
Case 2: RightPlayer = RightPlayer - 1
End Select
BalonX = 125: BalonY = 10
rest = 1
End Sub
Function reader (file As String) ' Read PBF file. This is my own new format contains graphics or characters. Its based on the BIT image representing.
Shared frames
kx = 0: ky = 1
If _FileExists(file$) Then Open file$ For Binary As #1 Else Beep: Print "Error opening file "; file$: _Display: Sleep 3: System
ident$ = Space$(4)
ReDim big As Integer
Get #1, , ident$
If ident$ <> "Petr" Then Print "This is not my file format": Sleep 2: Exit Function
Get #1, , big
frames = (LOF(1) - 6) / (big ^ 2 / 8)
ReDim udaj As _Unsigned _Byte
ReDim sn(frames) As String
While Not EOF(1)
Get #1, , udaj
binar$ = DECtoBIN$(udaj)
sn(snindex) = sn(snindex) + binar$
For rozklad = 1 To Len(binar$)
inSeek = inSeek + 1 'vnitrni pocitadlo pozice
povel = Val(Mid$(binar$, rozklad, 1))
kx = kx + 1: If kx > big Then kx = 1: ky = ky + 1
Next rozklad
If inSeek Mod (big ^ 2) = 0 Then ky = ky + 10: snindex = snindex + 1
If _Height - ky < big Then ky = 1: posun = posun + 60
Wend
Cls
reader = big
End Function
Sub rozpis (snimek As Integer, posX As Integer, posY As Integer) ' Draw frames from PBF read by function READER
Shared netiskni
If autostarted And Not vs Then Color 2: Locate 23, 1: Print "Demo": Color 15
If autostarted And vs Then Color 2: Locate 23, 1: Print "PC vs Human": Color 15
If netiskni Then Locate 23, 17: Print left; " - "; right
big = bigs ' je typu shared, udava delku strany
binar$ = sn(snimek)
For rozklad = 1 To Len(binar$)
povel = Val(Mid$(binar$, rozklad, 1))
kx = kx + 1: If kx > big Then kx = 1: ky = ky + 1
If povel = 1 Then PSet (posX + kx, posY + ky) 'ELSE PRESET (posX + kx, posY + ky)
Next rozklad
End Sub
' modifiation original code from CIRCLE help.
Function inCircle (cx As Integer, cy As Integer, cr As Integer, x As Integer, y As Integer, r As Integer) 'detect circle to circle contact. Return 1 if is contact, else return 0
r = r + 1
For Crc = 0 To 1.6 * _Pi Step .1
pseudocircleX = (Sin(Crc) * r) + x
pseudocircleY = (Cos(Crc) * r) + y
xy& = ((pseudocircleX - cx) ^ 2) + ((pseudocircleY - cy) ^ 2) ' Pythagorean theorem
If cr ^ 2 >= xy& Then inCircle = 1: Ic = 1 Else inCircle = 0
If Ic = 1 Then Exit For
Next
End Function
Function DECtoBIN$ (vstup) ' decimal to binary number convertor
For rj = 7 To 0 Step -1
If vstup And 2 ^ rj Then BINtoDE$ = BINtoDE$ + "1" Else BINtoDE$ = BINtoDE$ + "0"
Next rj
DECtoBIN$ = BINtoDE$
End Function
Sub doraz
If snd And Not autostarted Then
For e = .1 To .15 Step .01
Sound e * 500, e
Sound (500 * .6) - e, e
Sound e * 10000, e / 2
Next
For e = .15 To .1 Step -.01
Sound e * 500, e
Sound (500 * .6) - e, e
Sound e * 10000, e / 2
Next
End If
End Sub
Sub pisk
If snd Then
For e = .1 To .5 Step .1
Sound Sqr(e * 100 ^ 2 * 5000), e * 3
Next
End If
End Sub
Sub pad
If snd Then
For e = 2 To .1 Step -.1
Sound e * 200, .5
Next
End If
End Sub
Sub rotation (image As Long, x As Integer, y As Integer, angle As Integer, zoom As Integer) ' inspired by demo from somewhere in the forum, rotate image in menu.
_Source image&
_Dest 0
wide% = _Width(image&): deep% = _Height(image&)
TLC$ = "BL" + Str$(wide% / 2) + "BU" + Str$(deep% / 2)
RET$ = "BD BL" + Str$(wide%)
Draw "BM" + Str$(x) + ", " + Str$(y) + "TA=" + VarPtr$(angle%) + "S" + Str$(zoom) + TLC$
For y = 0 To deep% - 1
For x = 0 To wide% - 1
Draw "C" + Str$(Point(x, y)) + "R1"
Next x
Draw RET$
Next y
End Sub
Sub okoli
Line (0, 164)-(319, 200), 2, BF 'travnik pozadi
End Sub
After downloading file voll.zip do not try extract it, just rename it as voll.pbf, forum allow not add this file directly, then copy it to the same folder with source code.
Sometimes I actually plan a project before I start coding. That can involve actual diagrams and notes for myself. Here's a planner sheet for just one tiny part of a project; the attached image is the firing arc options for a spaceship combat game somewhat like super-trek but using hexes for a different look.
At first I was going to try a little something for alpha blending to make the thing look more like a transparent tube.
Then I got more interested in the "parts" of the tube than in the tube itself. Seeing as I particularly enjoy seeing the details of the whole, I had to add a little space between the circles to see them.
Then I was getting a sense of elongation of the tube, and I wanted to see the elongation motion. The randomness of the circles gives a little bit of an illusion of the circles moving, so that was good enough for this kid.
Do we have a native date/time type, with all the associated functions (dateadd, datediff, date to UNIX epoch & vice-versa, timezone operations, etc.) or has anyone built an equivalent library in QB64PE or related?