April 25, 2024, 10:47:17 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


User Defined Graphics?

Started by whitenite1, March 19, 2011, 10:51:37 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

whitenite1

  I was wondering if there is a way to create user defined graphics in IWBasic2? I converted a ZX program called 'Binominal Distribution' and it has a 'O' cascading down, and was wanting to create a solid, colored ball instead. Can this be done?
  Thanks..

whitenite1

aurelCB


LarryMc

You can't use graphics in a console program and since you are asking in the Console board I'm assuming you're using a console application.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

whitenite1

Larry..
  Yes, I'm using a console window. I was hoping some unused letters could be re-defined into a different character, so I could make it look like a solid ball instead of an O. AurelCB mentioned to draw it as a bitmap, but I figured that was for a window program, since ball.bmp is in the '2D Samples' directory. Well, I figured now I'll try to convert it into a windows mode program, and use the ball.bmp as well.
  Thanks for your help, Larry and AurelCB. If I run into more problems before finishing the program, I'll upload it, and see what smarter minds than mine, can come up with.

whitenite1

Kian

Hi whitenite,
It is possible to change the character set used by your console window but it involves messing around with the registry (always risky) and hardly suitable for distributing to anyone else. A windows program seems the only sensible way to go.
Just out of curiosity, would this be based on a type-in for the '81 from Sinclair Programs I seem to recall from faaaaaar too many years ago?
Kian

billhsln

Take a look at this program and look closely at the 'PRINT STRING$(15,249)', CHR$(249) prints a filled in Circle for me.

Create the program as CONSOLE and then compile.


STRING CMD$
INT I

CONST BLACK    = 0
CONST BLUE     = 1
CONST GREEN    = 2
CONST CYAN     = 3
CONST RED      = 4
CONST MAGENTA  = 5
CONST BROWN    = 6
CONST WHITE    = 7
CONST GRAY     = 8
CONST LBLUE    = 9
CONST LGREEN   = 10
CONST LCYAN    = 11
CONST LRED     = 12
CONST LMAGENTA = 13
CONST YELLOW   = 14
CONST LWHITE   = 15

OPENCONSOLE
CLS
COLOR LGREEN,0
PRINT CHR$(201)+STRING$(5,205)+CHR$(187)+"  "+CHR$(201)+STRING$(2,205)+CHR$(203)+STRING$(2,205)+CHR$(187)
PRINT CHR$(186)+STRING$(5," ")+CHR$(186)+"  "+CHR$(186)+STRING$(2," ")+CHR$(186)+STRING$(2," ")+CHR$(186)
PRINT CHR$(204)+STRING$(5,205)+CHR$(185)+"  "+CHR$(186)+STRING$(2," ")+CHR$(186)+STRING$(2," ")+CHR$(186)
PRINT CHR$(186)+STRING$(5," ")+CHR$(186)+"  "+CHR$(200)+STRING$(2,205)+CHR$(202)+STRING$(2,205)+CHR$(188)
PRINT CHR$(200)+STRING$(5,205)+CHR$(188)
PRINT " "

PRINT CHR$(201)+STRING$(2,205)+CHR$(203)+STRING$(2,205)+CHR$(187)+"  "+CHR$(201)+CHR$(203)+CHR$(187)
PRINT CHR$(204)+STRING$(2,205)+CHR$(206)+STRING$(2,205)+CHR$(185)+"  "+CHR$(204)+CHR$(206)+CHR$(185)
PRINT CHR$(200)+STRING$(2,205)+CHR$(202)+STRING$(2,205)+CHR$(188)+"  "+CHR$(200)+CHR$(202)+CHR$(188)

COLOR LCYAN,0
PRINT " "
PRINT CHR$(218)+STRING$(5,196)+CHR$(191)+"  "+CHR$(218)+STRING$(2,196)+CHR$(194)+STRING$(2,196)+CHR$(191)
PRINT CHR$(179)+STRING$(5," ")+CHR$(179)+"  "+CHR$(179)+STRING$(2," ")+CHR$(179)+STRING$(2," ")+CHR$(179)
PRINT CHR$(195)+STRING$(5,196)+CHR$(180)+"  "+CHR$(179)+STRING$(2," ")+CHR$(179)+STRING$(2," ")+CHR$(179)
PRINT CHR$(179)+STRING$(5," ")+CHR$(179)+"  "+CHR$(192)+STRING$(2,196)+CHR$(193)+STRING$(2,196)+CHR$(217)
PRINT CHR$(192)+STRING$(5,196)+CHR$(217)
PRINT " "

PRINT CHR$(218)+STRING$(2,196)+CHR$(194)+STRING$(2,196)+CHR$(191)+"  "+CHR$(218)+CHR$(194)+CHR$(191)
PRINT CHR$(195)+STRING$(2,196)+CHR$(197)+STRING$(2,196)+CHR$(180)+"  "+CHR$(195)+CHR$(197)+CHR$(180)
PRINT CHR$(192)+STRING$(2,196)+CHR$(193)+STRING$(2,196)+CHR$(217)+"  "+CHR$(192)+CHR$(193)+CHR$(217)

PRINT " "
PRINT STRING$(15,249)

'FOR I = 120 TO 255
' PRINT I, CHR$(I),
' IF (I-119)%20 = 0
' DO
' CMD$ = INKEY$
' UNTIL CMD$ <> ""
' ENDIF
'NEXT I

DO
CMD$ = INKEY$
UNTIL CMD$ <> ""
CLOSECONSOLE
END


Hope this helps.

Bill
When all else fails, get a bigger hammer.

Kian

March 20, 2011, 12:59:49 AM #6 Last Edit: March 20, 2011, 01:09:33 AM by Kian
Are you trying to load the ball image as a sprite:
myball = LOADSPRITE(GETSTARTPATH + "ball.bmp")
which can then be drawn with:
DRAWSPRITEXY myball,x,y
or as an image:
myball = LOADIMAGE(GETSTARTPATH + "ball.bmp", @IMGBITMAP)
which would be drawn with:
SHOWIMAGE mywin, myball, @IMGBITMAP, x, y
?

By the way, nice touch using the "^" instead of the '81-friendly block characters.
Thanks for the code.
Kian

sapero

March 20, 2011, 08:50:37 AM #7 Last Edit: March 20, 2011, 09:26:07 AM by sapero
I have a GDI solution for console mode:
$define WIN32_LEAN_AND_MEAN
$include "windowssdk.inc"

sub MoveBall() ' modified
COLOR 14,9
LOCATE y, xp
print " " ' erase
y = y + 1

LOCATE y, x
print "O" ' print something to allow erase at the next time
DrawCircle(x-1, y-1, RGB(255,255,0))
Sleep (300)
RETURN y
ENDSUB

sub DrawCircle(int x, int y, int rgbColor) ' added
static CONSOLE_FONT_INFO cfi
static HWND hwndConsole
WINRECT rc

if (!hwndConsole)
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE)
hwndConsole = GetConsoleWindow()
GetCurrentConsoleFont(hStdOut, FALSE, &cfi) ' cfi.dwFontSize.X / .Y
'$if __IWVER__ > 0x2000002
' cfi.dwFontSize = GetConsoleFontSize(hStdOut, cfi.nFont)
'$else
$undeclare GetConsoleFontSize
declare import,GetConsoleFontSize(HANDLE hConsoleOutput, DWORD nFont),DWORD
DWORD crd = GetConsoleFontSize(hStdOut, cfi.nFont)
cfi.dwFontSize.X = crd&65535
cfi.dwFontSize.Y = crd>>16
'$endif
endif

rc.left   = cfi.dwFontSize.X * x
rc.top    = cfi.dwFontSize.Y * y
rc.right  = rc.left + cfi.dwFontSize.X - 1
rc.bottom = rc.top + cfi.dwFontSize.Y - 1

HDC hdcConsole = GetDC(hwndConsole)
HGDIOBJ brush = SelectObject(hdcConsole, CreateSolidBrush(rgbColor))
HGDIOBJ pen   = SelectObject(hdcConsole, CreatePen(PS_SOLID, 1, rgbColor))

_Ellipse(hdcConsole, rc.left, rc.top, rc.right, rc.bottom)

DeleteObject(SelectObject(hdcConsole, pen))
DeleteObject(SelectObject(hdcConsole, brush))
ReleaseDC(hwndConsole, hdcConsole)
endsub

Kian

March 20, 2011, 01:06:39 PM #8 Last Edit: March 20, 2011, 01:21:18 PM by Kian
Whitenite:
The crash was caused by this line:
SHOWIMAGE(frame,myball,@IMGSCALABLE,10,15,30,30)
It should be @IMGBITMAP
Please find attached a zip of my hastily thrown together (as usual)  version of your code.
Lines 24-33 plot the '^' characters in screen co-ordinates so that their locations are precisely known.
Hope this is some help.
Kian
(Still blaming Sir Clive for my obsession with this programming lark)

Edit: just ran the program all the way through and noticed the 'waitcon'. This is only for console programs. Make sure that window is closed with 'CLOSEWINDOW frame'.


Sapero: Very nice! I get completely lost after the first dozen or so lines of the code but still, very nice!

LarryMc

March 24, 2011, 12:25:40 AM #9 Last Edit: March 24, 2011, 12:28:10 AM by LarryMc
I modified your program that is in the User Offerings board.
I added some and cleaned up some.
Unzip in different folder than original.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

I thought about adding an edit control so you could enter how many 'tries' you wanted.
To support that a Start button would need to be added.

You could also add two radio buttons to switch between using the number entered above to represent either the total # of tries or the max # in one bucket like your original.
It would be easy to set the program up for that.

It was late last night and I just wanted to correct some structure mistakes and to 'spiffy' it up a little to give you a 'go-by'.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Kian

I've been metaphorically locked away in a darkened room at work this week and missed all the goings on.
It's great to see the 'shiny' windows version up and running, although there's something in me (probably the old goat) that really loves the look of the console version.
Very nice drop-shadow &c., whitenite.
Another example of this community pulling together. ;D

P.S. really like the ZX site. I've actually come across it before and already have '15','Wolf' and 'Code Breaker' sitting comfortably in my '81 emulator folder.(Despite being a Maths teacher I've always been rubbish at Sudoku. :-[)

Kian

Brian

Hi,

I cut my metaphorical programming teeth on the ZX81 (1kb memory) and later the
Spectrums (oh, the dizzy heights of 48kb!)

I've seen the different emulators on the 'net, and wondered which one was
the best for running under XP, so I could re-live things like Horace Goes Skiing!

Any ideas?

Brian

LarryMc

Quote from: whitenite1 on March 26, 2011, 11:51:00 AM
...I worked on converting a C64 program called "Mystery at Mycroft Mews", which I also converted to Creative Basic, but the 'AND/OR' ML program messes up the end of basic, and causes the program to crash.
Show us what you're having problems with and we might be able to help.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

Great - thanks a lot, I'll give them a whirl

Brian

LarryMc

Senior moment!!

I misunderstood; you're absolutely correct. ;)

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Kian

I've sent you a PM re the '81 ML prob (to avoid 'off-topicness')
Kian