|
Codevault questions and contributions!
Beni
|
// returns 0(false) or 1(true) at intervals using systemtime
// ontime = length of time function should return 1
// offtime = length of time function should return 0
int blinker(int ontime, int offtime)
{
int t = systemtime % (ontime + offtime);
if (t<ontime)
return 1;
return 0;
}
// example: Turns a red color filter on and off every half second
void alarm()
{
if(blinker(50,50))
ColorFilter(CF_RED,screen);
}
Posted on 2004-12-22 05:11:45
|
RageCage
|
hey that's pretty cool =p
Posted on 2004-12-22 14:26:52
|
RageCage
|
double post, whoops...
Posted on 2004-12-22 14:27:13 (last edited on 2004-12-22 14:28:15)
|
blues_zodiakos
|
Hehe, Ness, I hadn't thought of that. With Silhouette, there would be no point in using fonts with more than one color. Now if only someone would updated that PrintStringAlpha function... it was spiffy. I think they fixed TextHeight and TextWidth returning the same value, so it would be easy to update it.
edit: In fact, you know what would REALLY be spiffy? A function that would load TrueType/OpenType fonts and display text with them. I tried looking up the specifications once for TrueType and got pretty much nowhere fast.
Posted on 2004-12-22 15:00:32 (last edited on 2004-12-22 15:02:02)
|
Gayo
|
You know someone made a TTF-to-V3font converter, right?
Posted on 2004-12-23 01:19:28
|
RageCage
|
Quote:Originally posted by zonker6666
Rage if you ran the following line ..
PrintString(0,0,screen,0,str(random(100,0-100)));
you would see that it does not ;)
if you ran PrintString(0,0,screen,0,str(random(0-100,100))); you would see that it does. The only condition is that the first variable has to be the smaller of the two.
Posted on 2004-12-23 11:53:22
|
zonker6666
|
That was my point. It cant function with the second parameter being the smaller of the 2.
Posted on 2004-12-23 15:53:14
|
Overkill
|
zonker6666: Couldn't you just have gone:
int rand(int a, int b)
{
return Random(min(a,b),max(a,b));
}
[Zip: Added min() and max() to vault, and don't post such wide pre-s in future, you little varmit!]
Posted on 2004-12-23 16:01:29 (last edited on 2004-12-23 21:43:28)
|
Beni
|
I use alot of dma. I use it instead of structs because I don't like the limitations of verge structs. But you can't store a string in dma. If you're like me, these functions will be useful. I use my own ascii function. If you use the one in the Code Vault just replace this
ascii(s,c)
with this
asc(mid(s,c,1))
// creates a dma array and stores a string in it
// I call it an istr (int string)
// returns the pointer
int makeIStr(string s)
{
int size = len(s) + 1;
int istr = malloc(size);
dma.byte[istr] = len(s);
int c;
for(c=0; c<len(s); c++)
dma.byte[istr + c + 1] = ascii(s,c);
return istr;
}
// converts an istr into a regular string
string IStrToString(int istr)
{
string s;
int l = dma.byte[istr];
int c;
for(c=0; c<l; c++)
s = s + chr(dma.byte[istr + c + 1]);
return s;
}
// gets the ascii value of a character in a string
int ascii(string s, int char)
{
if(len(s) <= char)
return 0-1;
s = mid(s,char,1);
int i = 0;
while(strcmp(chr(i),s) != 0)
i++;
return i;
}
The functions I use aren't exactly like this but if I showed them, I'd have to show my whole library of dma handling functions.
Posted on 2004-12-23 17:20:12
|
Zip
|
I know I've been a little slow on adding all, this, been coding for ovk. Will do it tonight. Beni - was verge's string handling not slow enough for you already without having to for-loop each and every chr into dma? :D But I can certainly see uses for this... saving to file etc... just not runtime. :D
Oh, and I'll be adding my vector to the Code Vault, so when I do that you can check yours against it and add stuff if you like.
Zip
Posted on 2004-12-23 18:05:04
|
Zip
|
Right, been adding string printing funcs. Done some testing in the process, which was quite fun:
Plain PrintString():
Ness' SuperPrintText() full scale:
Ness' SuperPrintText() 75%:
PrintStringAdvanced() full scale:
PrintStringAdvanced() 75%:
Zonker's CPrintString():
PrintStringCol():
I squeezed a little extra speed out of both functions, fixed the scale bug in Ness' and the large font problem with Zonker's. Note the text fade out at the top of the box is a feature of the textbox, not the string printing functions.
Zip
[Edit: Added vanilla PrintString() to give the speeds perspective]
Posted on 2004-12-23 21:32:14 (last edited on 2004-12-23 21:45:12)
|
blues_zodiakos
|
Yes, I know that Aen (I THINK) made a TTfont to verge font converter. It's sitting here in my folder now. The main problem is that verge fonts, when they are scaled, look REALLY ugly. The nice thing about TT fonts is that you can scale them to pretty much any size, because they are stored as vector information. I don't want to convert a font 20 times just to be able to have a good looking font I can display at different sizes. The verge font functions seem really limiting to me in that regard.
Posted on 2004-12-23 21:38:17
|
TomT64
|
Zip you may want to add the functions MixColors() and MakeGradient() from my file tt64_graphics.vc in my v3textbox demo 0.95. They work together to make a four color corner gradient image.
Posted on 2004-12-24 03:43:01
|
Zip
|
Wow Tom, you're right, that should definately be in the code vault. Not only have you got a duplication of MixColor() but you've used it to write the *SLOWEST* rendering function I've ever seen.
On this computer, the SetPixel() overhead for rendering a 1024x768 image is 0.61 seconds. Ask your func. to do the same size it takes 16.90 seconds! I know that's bigger than you'd ever use, but I was getting a second delay rendering a 240x180 image, so thought I'd scale up to see the difference. If I make the interesting optimisation of removing the 's' from MixColours(), it becomes a much more reasonable 1.32 seconds. Hell, I can render that and write it as a bitmap in less than 3.
Fun bit of trivia, vec added MixColor() in the build released on 02/22/04, your demo is listed as uploaded on 2004-02-21. :)
Zip
Posted on 2004-12-24 07:10:03
|
RageCage
|
if you use a black and white font set you can alias it and print with this:
void printAlpha(int x, int y, int dest, int thisFont, int color, string txt){
int width=TextWidth(thisFont, txt);
int height=Fontheight(thisFont);
int fill=newImage(width, height);
rectFill(0,0,width, height,color,fill);
int alphaFont=newImage(width, height);
rectFill(0,0,width, height,0,alphaFont);
printString(0,0,alphaFont,thisFont,txt);
alphaBlit(x,y,fill,alphaFont,dest);
freeImage(fill);
freeImage(alphaFont);
}
It works with enableVariableWidth too but you have to go into the font image and add death magenta to the parts that dont have any information already.
Posted on 2004-12-24 13:29:57
|
Zip
|
Nice. Rage's func:
Add a plain PrintString() underneath:
Zip
Posted on 2004-12-24 18:21:20
|
TomT64
|
Hey, totally sorry about my gradient function being slow. It was an adaptation of something from ika. Did you adapt it to use vec's MixColor?
Posted on 2004-12-24 19:01:35
|
zonker6666
|
a little lengthy and coded somewhat lazily but ...
Will read through the .vc files of a project
actually any file as long as its in the filelist file
in the following format ...
3
system.vc
file1.vc
file2.vc
(3 is the number of files of course)
All files 'must' have the line
// eof
at the very end.
It will generate an html list of the files along with function definitions + any // comments.
void FunctionList(string filelist, string reportfile)
{
int fptr=FileOpen(reportfile, FILE_WRITE);
int fptr2;
int fptr3=FileOpen(filelist, FILE_READ);
int NumFiles;
int done;
int i;
string line_;
string nextfile;
if(!fptr3)
Exit('Error opening the file list for reading.');
if(!fptr)
Exit('Error opening the report file for writing.');
NumFiles=val(FileReadLn(fptr3));
for(i=0;i<NumFiles;i++)
{
nextfile=FileReadLn(fptr3);
FileWriteln(fptr, '<a href='#' + nextfile + ''>' + nextfile + '</a><br>');
}
FileSeekLine(fptr3, 1);
FileWriteln(fptr, '<br><br>');
for(i=0;i<NumFiles;i++)
{
nextfile=FileReadLn(fptr3);
fptr2=FileOpen(nextfile, FILE_READ);
if(!fptr2)
Exit('Error opening ' + nextfile + ' for reading.');
FileWriteln(fptr, '<a name='#' + nextfile + ''>' + nextfile + '</b><br><table border=1><tr><td> </td><td>');
done=0;
while(!done)
{
line_=FileReadLn(fptr2);
if(!strcmp(left(line_, 4), 'void') || !strcmp(left(line_, 3), 'int') || !strcmp(left(line_, 6), 'string'))
{
if(!strcmp(right(line_, 1), ')'))
{
FileWriteln(fptr, '<i><b>' + line_ + '</b></i><br>');
}
}
else if(!strcmp(line_, '// eof'))
{
done=1;
}
else if(!strcmp(left(line_, 2), '//'))
{
FileWriteln(fptr, '<table><tr><td width=30> </td><td width=320><i><font color=#555555>' + right(line_, len(line_)-2) + '</font></i></td></tr></table><br>');
}
}
FileWriteln(fptr,'</td></tr></table><br>');
FileClose(fptr2);
}
FileClose(fptr3);
FileClose(fptr);
Messagebox('Code documentation created!');
}
Posted on 2004-12-25 02:44:28 (last edited on 2004-12-25 03:10:13)
|
gannon
|
zonker6666 that looks like it would be usefull with a little refinment. (Like making the comments lines optional) That would make making docs alot easier if you make the docs after you make the code.
Posted on 2004-12-25 03:00:55
|
zonker6666
|
Vertical gradient function.
void VGradientRect(int X, int Y, int W, int H, int Color1, int Color2, int steps, int dest)
{
int R1,G1,_B1;
int R2,G2,_B2;
int Rinc, Ginc, Binc;
int Vinc=abs(Y-(Y+H))/steps;
int i;
R1=GetR(Color1);
G1=GetG(Color1);
_B1=GetB(Color1);
R2=GetR(Color2);
G2=GetG(Color2);
_B2=GetB(Color2);
Rinc=abs(R1-R2)/steps;
Binc=abs(_B1-_B2)/steps;
Ginc=abs(G1-G2)/steps;
for(i=0;i<steps;i++)
{
RectFill(X,Y+(Vinc*i), X+W, Y+(Vinc*(i+1)), RGB(R1+(Rinc*i),G1+(Ginc*i),_B1+(Binc*i)), dest);
}
}
Posted on 2004-12-28 21:15:00
|
|
|