本文目录一览:
- 1、KTR是外国品牌吗?
- 2、KTR POLY联轴器|POLY弹性联轴器的价格|货期哪里可以查?
- 3、MMsegmentation教程 6: 自定义运行设定
- 4、用C语言设计一个简单计算器
- 5、求解分数阶微分方程
- 6、怎么用C语言做二维 三维 动画 窗口的程序?
KTR是外国品牌吗?
是的
德国KTR 品牌简介
KUPPLUNGSTECHNIK GMBH自从进入中国市场以来,凭借其优良的品质、丰富的产品种类以及热情的服务,在中国联轴器市场取得了极大的成功,尤其是其ROTEX系列联轴器,在中国的CNC以及工程机械行业占领了较大的市场份额。
KTR连轴器广泛应用于工程机械、机床、冶金、石油化工设备及各种通用机械等,几乎所有需要动力传递的机械设备中都要用到KTR的产品。由于其的性能和优良的品质,KTR的产品已为世界各地的设备厂商所采用。
KTR联轴器特点:
有钢质轴套,扭向弹性,免维护,吸收振动;
轴向插入式安装,失效保护;
良好的动态特性;设计紧凑,惯性小;
成品孔径公差按照ISO标准为H7,键槽宽公差标准DIN 6885/1为JS9.
KTR联轴器弹性体的正常工作温度为-40-+100℃,允许的zui高瞬时温度为120℃.弹性体的肖氏硬度通常为92 Shore A,若需传递更高扭矩,可选用硬度为95/98 Shore A和64D-F的弹性体.弹性体耐磨,抗油,抗臭氧,抗老化,其耐水解性适合热带气候地区.由于具有的内部缓冲,能保护传动不受过载的影响.
德国KTR公司主要产品有:KTR联轴器、KTR曲面齿联轴器、KTR尼龙曲面齿联轴器、KTR特种曲面齿联轴器、KTR扭力限制器、KTR涨紧套、KTR力矩转速检测仪
KTR POLY联轴器|POLY弹性联轴器的价格|货期哪里可以查?
济南埃姆依机电设备有限责任公司是一家多年从事机电一体化设备销售的专业性公司
公司成立伊始,就把“为客户提供一流的传动机械设备”作为经营理念;把“客户是上帝,一切为用户着想”作为服务理念。全心全意为广大用户服务,经过全体员工的不懈努力,公司业绩蒸蒸日上。现在我公司已成为多个国内外知名品牌在山东的核心代理商,我们代理的主要产品是:汉森减速机系列、、电机系列以及KTR联轴器系列,各个产品的价格优势都非常明显。
主要经营产品:
KTR联轴器,德国EK2联轴器,EKL联轴器
纽卡特(Neugart)行星减速机
伦茨伺服系统
R+W联轴器
汉森减速机
三木联轴器
等
电话:
0531-88014512
传真:
0531-88014557
邮箱:
jn_me@126.com
地址:山东省济南市花园路45号
网址:
24小时服务:
(0)13465310635
MMsegmentation教程 6: 自定义运行设定
我们已经支持 PyTorch 自带的所有优化器,唯一需要修改的地方是在配置文件里的 optimizer 域里面。
例如,如果您想使用 ADAM (注意如下操作可能会让模型表现下降),可以使用如下修改:
为了修改模型的学习率,使用者仅需要修改配置文件里 optimizer 的 lr 即可。
使用者可以参照 PyTorch 的 API 文档
直接设置参数。
一个自定义的优化器可以按照如下去定义:
假如您想增加一个叫做 MyOptimizer 的优化器,它的参数分别有 a , b , 和 c 。
您需要创建一个叫 mmseg/core/optimizer 的新文件夹。
然后再在文件,即 mmseg/core/optimizer/my_optimizer.py 里面去实现这个新优化器:
为了让上述定义的模块被框架发现,首先这个模块应该被导入到主命名空间 (main namespace) 里。
有两种方式可以实现它。
mmseg.core.optimizer.my_optimizer 模块将会在程序运行的开始被导入,并且 MyOptimizer 类将会自动注册。
需要注意只有包含 MyOptimizer 类的包 (package) 应当被导入。
而 mmseg.core.optimizer.my_optimizer.MyOptimizer 不能 被直接导入。
事实上,使用者完全可以用另一个按这样导入方法的文件夹结构,只要模块的根路径已经被添加到 PYTHONPATH 里面。
之后您可以在配置文件的 optimizer 域里面使用 MyOptimizer
在配置文件里,优化器被定义在 optimizer 域里,如下所示:
为了使用您自己的优化器,这个域可以被改成:
有些模型可能需要在优化器里有一些特别参数的设置,例如 批归一化层 (BatchNorm layers) 的 权重衰减 (weight decay)。
使用者可以通过自定义优化器的构造器去微调这些细粒度参数。
默认的优化器构造器的实现可以参照 这里 ,它也可以被用作新的优化器构造器的模板。
优化器没有实现的一些技巧应该通过优化器构造器 (optimizer constructor) 或者钩子 (hook) 去实现,如设置基于参数的学习率 (parameter-wise learning rates)。我们列出一些常见的设置,它们可以稳定或加速模型的训练。
如果您有更多的设置,欢迎在 PR 和 issue 里面提交。
我们根据默认的训练迭代步数 40k/80k 来设置学习率,这在 MMCV 里叫做 PolyLrUpdaterHook 。
我们也支持许多其他的学习率计划表: 这里 ,例如 CosineAnnealing 和 Poly 计划表。下面是一些例子:
工作流是一个专门定义运行顺序和轮数 (running order and epochs) 的列表 (phase, epochs)。
默认情况下它设置成:
意思是训练是跑 1 个 epoch。有时候使用者可能想检查模型在验证集上的一些指标(如 损失 loss,精确性 accuracy),我们可以这样设置工作流:
于是 1 个 epoch 训练,1 个 epoch 验证将交替运行。
注意 :
如果钩子已经在 MMCV 里被实现,如下所示,您可以直接修改配置文件来使用钩子:
以下的常用的钩子没有被 custom_hooks 注册:
在这些钩子里,只有 logger hook 有 VERY_LOW 优先级,其他的优先级都是 NORMAL 。
上述提及的教程已经包括了如何修改 optimizer_config , momentum_config 和 lr_config 。
这里我们展示我们如何处理 log_config , checkpoint_config 和 evaluation 。
MMCV runner 将使用 checkpoint_config 去初始化 CheckpointHook .
使用者可以设置 max_keep_ckpts 来仅保存一小部分检查点或者通过 save_optimizer 来决定是否保存优化器的状态字典 (state dict of optimizer)。 更多使用参数的细节请参考 这里 。
log_config 包裹了许多日志钩 (logger hooks) 而且能去设置间隔 (intervals)。现在 MMCV 支持 WandbLoggerHook , MlflowLoggerHook 和 TensorboardLoggerHook 。
详细的使用请参照 文档 。
evaluation 的配置文件将被用来初始化 EvalHook 。
除了 interval 键,其他的像 metric 这样的参数将被传递给 dataset.evaluate() 。
用C语言设计一个简单计算器
#includestdio.h
void add(int a,int b,int c)
{
c=a+b;
printf("%d\t",c);
printf("\n");
}
void minus(int a,int b,int c)
{
c=a-b;
printf("%d\t",c);
printf("\n");
}
void multiplication(int a,int b,int c)
{
c=a*b;
printf("%d\t",c);
printf("\n");
}
void div(int a,int b,int c)
{
c=(float)a/(float)b;
printf("%f\t",c);
printf("\n");
}
main()
{
int a,b,c;
char p;
puts("input A:\n");
scanf("%d",a);
puts("input B:\n");
scanf("%d",b);
puts("input operation:\n");
getchar();
p=getchar();
if(p=='+') add(a,b,c);else
if(p=='-') minus(a,b,c);else
if(p=='*') multiplication(a,b,c);else
if(p=='/') div(a,b,c);else
puts("没有注册这个运算符号\n");
}
以上是设计的一个简易计算器。可以进行相应的加减乘除。
简介:
C语言是一种计算机程序设计语言,它既具有高级语言的特点,又具有汇编语言的特点。它由美国贝尔研究所的D.M.Ritchie于1972年推出,1978年后,C语言已先后被移植到大、中、小及微型机上,它可以作为工作系统设计语言,编写系统应用程序,也可以作为应用程序设计语言,编写不依赖计算机硬件的应用程序。它的应用范围广泛,具备很强的数据处理能力,不仅仅是在软件开发上,而且各类科研都需要用到C语言,适于编写系统软件,三维,二维图形和动画,具体应用比如单片机以及嵌入式系统开发。
求解分数阶微分方程
MATLAB
每一数阶微分作为一种新的变量 (variable)
polyfitn可以得到对应b0的变量 di/dt
可以在谷歌搜索polyfitn
polyfitn(indepvar,depvar,modelterms)function polymodel = polyfitn(indepvar,depvar,modelterms)
% polyfitn: fits a general polynomial regression model in n dimensions
% usage: polymodel = polyfitn(indepvar,depvar,modelterms)
%
% Polyfitn fits a polynomial regression model of one or more
% independent variables, of the general form:
%
% z = f(x,y,...) + error
%
% arguments: (input)
% indepvar - (n x p) array of independent variables as columns
% n is the number of data points
% p is the dimension of the independent variable space
%
%
% modelterms - defines the terms used in the model itself
%p=1
% the terms selected will be:
%
% {constant, x, y}
%
% Beware the consequences of high order polynomial
% models.
%
% IF modelterms is a (k x p) numeric array, then each
% row of this array designates the exponents of one
% term in the model. Thus to designate a model with
% the above list of terms, we would define modelterms as
%
%
% Arguments: (output)
% polymodel - A structure containing the regression model
% polymodel.ModelTerms = list of terms in the model
% polymodel.Coefficients = regression coefficients
% polymodel.ParameterVar = variances of model coefficients
% polymodel.ParameterStd = standard deviation of model coefficients
% polymodel.R2 = R^2 for the regression model
% polymodel.AdjustedR2 = Adjusted R^2 for the regression model
% polymodel.RMSE = Root mean squared error
% polymodel.VarNames = Cell array of variable names
% as parsed from a char based model specification.
%
% Note 1: Because the terms in a general polynomial
% model can be arbitrarily chosen by the user, I must
% package the erms and coefficients together into a
% structure. This also forces use of a special evaluation
% tool: polyvaln.
%
% Note 2: A polymodel can be evaluated for any set
% of values with the function polyvaln. However, if
% you wish to manipulate the result symbolically using
% my own sympoly tools, this structure can be converted
% to a sympoly using the function polyn2sympoly.
%
% Note 3: When no constant term is included in the model,
% the traditional R^2 can be negative. This case is
% identified, and then a more appropriate computation
% for R^2 is then used.
%
% Note 4: Adjusted R^2 accounts for changing degrees of
% freedom in the model. It CAN be negative, and will always
% be less than the traditional R^2 values.
%
% Find my sympoly toolbox here:
% ;objectType=FILE
%
% Author: John D'Errico
% Release: 2.0
% Release date: 2/19/06
if nargin1
help polyfitn
return
end
% get sizes, test for consistency
[n,p] = size(indepvar);
if n == 1
indepvar = indepvar';
[n,p] = size(indepvar);
end
[m,q] = size(depvar);
if m == 1
depvar = depvar';
[m,q] = size(depvar);
end
% only 1 dependent variable allowed at a time
if q~=1
error 'Only 1 dependent variable allowed at a time.'
end
if n~=m
error 'indepvar and depvar are of inconsistent sizes.'
end
% Automatically scale the independent variables to unit variance
stdind = sqrt(diag(cov(indepvar)));
if any(stdind==0)
warning 'Constant terms in the model must be entered using modelterms'
stdind(stdind==0) = 1;
end
% scaled variables
indepvar_s = indepvar*diag(1./stdind);
% do we need to parse a supplied model?
if iscell(modelterms) || ischar(modelterms)
[modelterms,varlist] = parsemodel(modelterms,p);
if size(modelterms,2) p
modelterms = [modelterms, zeros(size(modelterms,1),p - size(modelterms,2))];
end
elseif length(modelterms) == 1
% do we need to generate a set of modelterms?
[modelterms,varlist] = buildcompletemodel(modelterms,p);
elseif size(modelterms,2) ~= p
error 'ModelTerms must be a scalar or have the same # of columns as indepvar'
end
nt = size(modelterms,1);
% check for replicate terms
if nt1
mtu = unique(modelterms,'rows');
if size(mtu,1)nt
warning 'Replicate terms identified in the model.'
end
end
% build the design matrix
M = ones(n,nt);
scalefact = ones(1,nt);
for i = 1:nt
for j = 1:p
M(:,i) = M(:,i).*indepvar_s(:,j).^modelterms(i,j);
scalefact(i) = scalefact(i)/(stdind(j)^modelterms(i,j));
end
end
% estimate the model using QR. do it this way to provide a
% covariance matrix when all done. Use a pivoted QR for
% maximum stability.
[Q,R,E] = qr(M,0);
polymodel.ModelTerms = modelterms;
polymodel.Coefficients(E) = R\(Q'*depvar);
yhat = M*polymodel.Coefficients(:);
% recover the scaling
polymodel.Coefficients=polymodel.Coefficients.*scalefact;
% variance of the regression parameters
s = norm(depvar - yhat);
if n nt
Rinv = R\eye(nt);
Var(E) = s^2*sum(Rinv.^2,2)/(n-nt);
polymodel.ParameterVar = Var.*(scalefact.^2);
polymodel.ParameterStd = sqrt(polymodel.ParameterVar);
else
% we cannot form variance or standard error estimates
% unless there are at least as many data points as
% parameters to estimate.
polymodel.ParameterVar = inf(1,nt);
polymodel.ParameterStd = inf(1,nt);
end
% R^2
% is there a constant term in the model? If not, then
% we cannot use the standard R^2 computation, as it
% frequently yields negative values for R^2.
if any((M(1,:) ~= 0) all(diff(M,1,1) == 0,1))
% we have a constant term in the model, so the
% traditional %R^2 form is acceptable.
polymodel.R2 = max(0,1 - (s/norm(depvar-mean(depvar)) )^2);
% compute adjusted R^2, taking into account the number of
% degrees of freedom
polymodel.AdjustedR2 = 1 - (1 - polymodel.R2).*((n - 1)./(n - nt));
else
% no constant term was found in the model
polymodel.R2 = max(0,1 - (s/norm(depvar))^2);
% compute adjusted R^2, taking into account the number of
% degrees of freedom
polymodel.AdjustedR2 = 1 - (1 - polymodel.R2).*(n./(n - nt));
end
% RMSE
polymodel.RMSE = sqrt(mean((depvar - yhat).^2));
% if a character 'model' was supplied, return the list
% of variables as parsed out
polymodel.VarNames = varlist;
% ==================================================
% =============== begin subfunctions ===============
% ==================================================
function [modelterms,varlist] = buildcompletemodel(order,p)
%
% arguments: (input)
% order - scalar integer, defines the total (maximum) order
%
% p - scalar integer - defines the dimension of the
% independent variable space
%
% arguments: (output)
% modelterms - exponent array for the model
%
% varlist - cell array of character variable names
% build the exponent array recursively
if p == 0
% terminal case
modelterms = [];
elseif (order == 0)
% terminal case
modelterms = zeros(1,p);
elseif (p==1)
% terminal case
modelterms = (order:-1:0)';
else
% general recursive case
modelterms = zeros(0,p);
for k = order:-1:0
t = buildcompletemodel(order-k,p-1);
nt = size(t,1);
modelterms = [modelterms;[repmat(k,nt,1),t]];
end
end
% create a list of variable names for the variables on the fly
varlist = cell(1,p);
for i = 1:p
varlist{i} = ['X',num2str(i)];
end
% ==================================================
function [modelterms,varlist] = parsemodel(model,p);
%
% arguments: (input)
% model - character string or cell array of strings
%
% p - number of independent variables in the model
%
% arguments: (output)
% modelterms - exponent array for the model
modelterms = zeros(0,p);
if ischar(model)
model = deblank(model);
end
varlist = {};
while ~isempty(model)
if iscellstr(model)
term = model{1};
model(1) = [];
else
[term,model] = strtok(model,' ,');
end
% We've stripped off a model term. Now parse it.
% Is it the reserved keyword 'constant'?
if strcmpi(term,'constant')
modelterms(end+1,:) = 0;
else
% pick this term apart
expon = zeros(1,p);
while ~isempty(term)
vn = strtok(term,'*/^. ,');
k = find(strncmp(vn,varlist,length(vn)));
if isempty(k)
% its a variable name we have not yet seen
% is it a legal name?
nv = length(varlist);
if ismember(vn(1),'1234567890_')
error(['Variable is not a valid name: ''',vn,''''])
elseif nv=p
error 'More variables in the model than columns of indepvar'
end
varlist{nv+1} = vn;
k = nv+1;
end
% variable must now be in the list of vars.
% drop that variable from term
i = strfind(term,vn);
term = term((i+length(vn)):end);
% is there an exponent?
eflag = false;
if strncmp('^',term,1)
term(1) = [];
eflag = true;
elseif strncmp('.^',term,2)
term(1:2) = [];
eflag = true;
end
% If there was one, get it
ev = 1;
if eflag
ev = sscanf(term,'%f');
if isempty(ev)
error 'Problem with an exponent in parsing the model'
end
end
expon(k) = expon(k) + ev;
% next monomial subterm?
k1 = strfind(term,'*');
if isempty(k1)
term = '';
else
term(k1(1)) = ' ';
end
end
modelterms(end+1,:) = expon;
end
end
% Once we have compiled the list of variables and
% exponents, we need to sort them in alphabetical order
[varlist,tags] = sort(varlist);
modelterms = modelterms(:,tags);
% 数阶微分
% ;oldq=1
怎么用C语言做二维 三维 动画 窗口的程序?
我有相关的资料(原版英文书), 但无法传递给你!!! 给你个实例程序:(太长,程序没发完)
/*
GRAPHICS DEMO FOR TURBO C 2.0
Copyright (c) 1987,88 Borland International. All rights reserved.
From the command line, use:
tcc bgidemo graphics.lib
*/
#ifdef __TINY__
#error BGIDEMO will not run in the tiny model.
#endif
#include dos.h
#include math.h
#include conio.h
#include stdio.h
#include stdlib.h
#include stdarg.h
#include graphics.h
#define ESC 0x1b /* Define the escape key */
#define TRUE 1 /* Define some handy constants */
#define FALSE 0 /* Define some handy constants */
#define PI 3.14159 /* Define a value for PI */
#define ON 1 /* Define some handy constants */
#define OFF 0 /* Define some handy constants */
char *Fonts[] = {
"DefaultFont", "TriplexFont", "SmallFont",
"SansSerifFont", "GothicFont"
};
char *LineStyles[] = {
"SolidLn", "DottedLn", "CenterLn", "DashedLn", "UserBitLn"
};
char *FillStyles[] = {
"EmptyFill", "SolidFill", "LineFill", "LtSlashFill",
"SlashFill", "BkSlashFill", "LtBkSlashFill", "HatchFill",
"XHatchFill", "InterleaveFill", "WideDotFill", "CloseDotFill"
};
char *TextDirect[] = {
"HorizDir", "VertDir"
};
char *HorizJust[] = {
"LeftText", "CenterText", "RightText"
};
char *VertJust[] = {
"BottomText", "CenterText", "TopText"
};
struct PTS {
int x, y;
}; /* Structure to hold vertex points */
int GraphDriver; /* The Graphics device driver */
int GraphMode; /* The Graphics mode value */
double AspectRatio; /* Aspect ratio of a pixel on the screen*/
int MaxX, MaxY; /* The maximum resolution of the screen */
int MaxColors; /* The maximum # of colors available */
int ErrorCode; /* Reports any graphics errors */
struct palettetype palette; /* Used to read palette info */
/* */
/* Function prototypes */
/* */
void Initialize(void);
void ReportStatus(void);
void TextDump(void);
void Bar3DDemo(void);
void RandomBars(void);
void TextDemo(void);
void ColorDemo(void);
void ArcDemo(void);
void CircleDemo(void);
void PieDemo(void);
void BarDemo(void);
void LineRelDemo(void);
void PutPixelDemo(void);
void PutImageDemo(void);
void LineToDemo(void);
void LineStyleDemo(void);
void CRTModeDemo(void);
void UserLineStyleDemo(void);
void FillStyleDemo(void);
void FillPatternDemo(void);
void PaletteDemo(void);
void PolyDemo(void);
void SayGoodbye(void);
void Pause(void);
void MainWindow(char *header);
void StatusLine(char *msg);
void DrawBorder(void);
void changetextstyle(int font, int direction, int charsize);
int gprintf(int *xloc, int *yloc, char *fmt, ... );
/* */
/* Begin main function */
/* */
int main()
{
Initialize(); /* Set system into Graphics mode */
ReportStatus(); /* Report results of the initialization */
ColorDemo(); /* Begin actual demonstration */
if( GraphDriver==EGA || GraphDriver==EGALO || GraphDriver==VGA )
PaletteDemo();
PutPixelDemo();
PutImageDemo();
Bar3DDemo();
BarDemo();
RandomBars();
ArcDemo();
CircleDemo();
PieDemo();
LineRelDemo();
LineToDemo();
LineStyleDemo();
UserLineStyleDemo();
TextDump();
TextDemo();
CRTModeDemo();
FillStyleDemo();
FillPatternDemo();
PolyDemo();
SayGoodbye(); /* Give user the closing screen */
closegraph(); /* Return the system to text mode */
return(0);
}
/* */
/* INITIALIZE: Initializes the graphics system and reports */
/* any errors which occured. */
/* */
void Initialize(void)
{
int xasp, yasp; /* Used to read the aspect ratio*/
GraphDriver = DETECT; /* Request auto-detection */
initgraph( GraphDriver, GraphMode, "" );
ErrorCode = graphresult(); /* Read result of initialization*/
if( ErrorCode != grOk ){ /* Error occured during init */
printf(" Graphics System Error: %s\n", grapherrormsg( ErrorCode ) );
exit( 1 );
}
getpalette( palette ); /* Read the palette from board */
MaxColors = getmaxcolor() + 1; /* Read maximum number of colors*/
MaxX = getmaxx();
MaxY = getmaxy(); /* Read size of screen */
getaspectratio( xasp, yasp ); /* read the hardware aspect */
AspectRatio = (double)xasp / (double)yasp; /* Get correction factor */
}
/* */
/* REPORTSTATUS: Report the current configuration of the system */
/* after the auto-detect initialization. */
/* */
void ReportStatus(void)
{
struct viewporttype viewinfo; /* Params for inquiry procedures*/
struct linesettingstype lineinfo;
struct fillsettingstype fillinfo;
struct textsettingstype textinfo;
struct palettetype palette;
char *driver, *mode; /* Strings for driver and mode */
int x, y;
getviewsettings( viewinfo );
getlinesettings( lineinfo );
getfillsettings( fillinfo );
gettextsettings( textinfo );
getpalette( palette );
x = 10;
y = 4;
MainWindow( "Status report after InitGraph" );
settextjustify( LEFT_TEXT, TOP_TEXT );
driver = getdrivername();
mode = getmodename(GraphMode); /* get current setting */
gprintf( x, y, "Graphics device : %-20s (%d)", driver, GraphDriver );
gprintf( x, y, "Graphics mode : %-20s (%d)", mode, GraphMode );
gprintf( x, y, "Screen resolution : ( 0, 0, %d, %d )", getmaxx(), getmaxy() );
gprintf( x, y, "Current view port : ( %d, %d, %d, %d )",
viewinfo.left, viewinfo.top, viewinfo.right, viewinfo.bottom );
gprintf( x, y, "Clipping : %s", viewinfo.clip ? "ON" : "OFF" );
gprintf( x, y, "Current position : ( %d, %d )", getx(), gety() );
gprintf( x, y, "Colors available : %d", MaxColors );
gprintf( x, y, "Current color : %d", getcolor() );
gprintf( x, y, "Line style : %s", LineStyles[ lineinfo.linestyle ] );
gprintf( x, y, "Line thickness : %d", lineinfo.thickness );
gprintf( x, y, "Current fill style : %s", FillStyles[ fillinfo.pattern ] );
gprintf( x, y, "Current fill color : %d", fillinfo.color );
gprintf( x, y, "Current font : %s", Fonts[ textinfo.font ] );
gprintf( x, y, "Text direction : %s", TextDirect[ textinfo.direction ] );
gprintf( x, y, "Character size : %d", textinfo.charsize );
gprintf( x, y, "Horizontal justify : %s", HorizJust[ textinfo.horiz ] );
gprintf( x, y, "Vertical justify : %s", VertJust[ textinfo.vert ] );
Pause(); /* Pause for user to read screen*/
}
/* */
/* TEXTDUMP: Display the all the characters in each of the */
/* available fonts. */
/* */
void TextDump()
{
static int CGASizes[] = {
1, 3, 7, 3, 3 };
static int NormSizes[] = {
1, 4, 7, 4, 4 };
char buffer[80];
int font, ch, wwidth, lwidth, size;
struct viewporttype vp;
for( font=0 ; font5 ; ++font ){ /* For each available font */
sprintf( buffer, "%s Character Set", Fonts[font] );
MainWindow( buffer ); /* Display fontname as banner */
getviewsettings( vp ); /* read current viewport */
settextjustify( LEFT_TEXT, TOP_TEXT );
moveto( 2, 3 );
buffer[1] = '\0'; /* Terminate string */
wwidth = vp.right - vp.left; /* Determine the window width */
lwidth = textwidth( "H" ); /* Get average letter width */
if( font == DEFAULT_FONT ){
changetextstyle( font, HORIZ_DIR, 1 );
ch = 0;
while( ch 256 ){ /* For each possible character */
buffer[0] = ch; /* Put character into a string */
outtext( buffer ); /* send string to screen */
if( (getx() + lwidth) wwidth )
moveto( 2, gety() + textheight("H") + 3 );
++ch; /* Goto the next character */
}
}
else{
size = (MaxY 200) ? CGASizes[font] : NormSizes[font];
changetextstyle( font, HORIZ_DIR, size );
ch = '!'; /* Begin at 1st printable */
while( ch 127 ){ /* For each printable character */
buffer[0] = ch; /* Put character into a string */
outtext( buffer ); /* send string to screen */
if( (lwidth+getx()) wwidth ) /* Are we still in window? */
moveto( 2, gety()+textheight("H")+3 );
++ch; /* Goto the next character */
}
}
Pause(); /* Pause until user acks */
} /* End of FONT loop */
}
/* */
/* BAR3DDEMO: Display a 3-D bar chart on the screen. */
/* */
void Bar3DDemo(void)
{
static int barheight[] = {
1, 3, 5, 4, 3, 2, 1, 5, 4, 2, 3 };
struct viewporttype vp;
int xstep, ystep;
int i, j, h, color, bheight;
char buffer[10];
MainWindow( "Bar 3-D / Rectangle Demonstration" );
h = 3 * textheight( "H" );
getviewsettings( vp );
settextjustify( CENTER_TEXT, TOP_TEXT );
changetextstyle( TRIPLEX_FONT, HORIZ_DIR, 4 );
outtextxy( MaxX/2, 6, "These are 3-D Bars" );
changetextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
setviewport( vp.left+50, vp.top+40, vp.right-50, vp.bottom-10, 1 );
getviewsettings( vp );
line( h, h, h, vp.bottom-vp.top-h );
line( h, (vp.bottom-vp.top)-h, (vp.right-vp.left)-h, (vp.bottom-vp.top)-h );
xstep = ((vp.right-vp.left) - (2*h)) / 10;
ystep = ((vp.bottom-vp.top) - (2*h)) / 5;
j = (vp.bottom-vp.top) - h;
settextjustify( CENTER_TEXT, CENTER_TEXT );
for( i=0 ; i6 ; ++i ){
line( h/2, j, h, j );
itoa( i, buffer, 10 );
outtextxy( 0, j, buffer );
j -= ystep;
}
j = h;
settextjustify( CENTER_TEXT, TOP_TEXT );
for( i=0 ; i11 ; ++i ){
color = random( MaxColors );
setfillstyle( i+1, color );
line( j, (vp.bottom-vp.top)-h, j, (vp.bottom-vp.top-3)-(h/2) );
itoa( i, buffer, 10 );
outtextxy( j, (vp.bottom-vp.top)-(h/2), buffer );
if( i != 10 ){
bheight = (vp.bottom-vp.top) - h - 1;
bar3d( j, (vp.bottom-vp.top-h)-(barheight[i]*ystep), j+xstep, bheight, 15, 1 );
}
j += xstep;
}
Pause(); /* Pause for user's response */
}
/* */
/* RANDOMBARS: Display random bars */
/* */
void RandomBars(void)
{
int color;
MainWindow( "Random Bars" );
StatusLine( "Esc aborts or press a key..." ); /* Put msg at bottom of screen */
while( !kbhit() ){ /* Until user enters a key... */
color = random( MaxColors-1 )+1;
setcolor( color );
setfillstyle( random(11)+1, color );
bar3d( random( getmaxx() ), random( getmaxy() ),
random( getmaxx() ), random( getmaxy() ), 0, OFF);
}
Pause(); /* Pause for user's response */
}
/* */
/* TEXTDEMO: Show each font in several sizes to the user. */
/* */
void TextDemo(void)
{
int charsize[] = {
1, 3, 7, 3, 4 };
int font, size;
int h, x, y, i;
struct viewporttype vp;
char buffer[80];
for( font=0 ; font5 ; ++font ){ /* For each of the four fonts */
sprintf( buffer, "%s Demonstration", Fonts[font] );
MainWindow( buffer );
getviewsettings( vp );
changetextstyle( font, VERT_DIR, charsize[font] );
settextjustify( CENTER_TEXT, BOTTOM_TEXT );
outtextxy( 2*textwidth("M"), vp.bottom - 2*textheight("M"), "Vertical" );
changetextstyle( font, HORIZ_DIR, charsize[font] );
settextjustify( LEFT_TEXT, TOP_TEXT );
outtextxy( 2*textwidth("M"), 2, "Horizontal" );
settextjustify( CENTER_TEXT, CENTER_TEXT );
x = (vp.right - vp.left) / 2;
y = textheight( "H" );
for( i=1 ; i5 ; ++i ){ /* For each of the sizes */
size = (font == SMALL_FONT) ? i+3 : i;
changetextstyle( font, HORIZ_DIR, size );
h = textheight( "H" );
y += h;
sprintf( buffer, "Size %d", size );
outtextxy( x, y, buffer );
}
if( font != DEFAULT_FONT ){ /* Show user declared font size */
y += h / 2; /* Move down the screen */
settextjustify( CENTER_TEXT, TOP_TEXT );
setusercharsize( 5, 6, 3, 2 );
changetextstyle( font, HORIZ_DIR, USER_CHAR_SIZE );
outtextxy( (vp.right-vp.left)/2, y, "User Defined Size" );
}
Pause(); /* Pause to let user look */
} /* End of FONT loop */
}
/* */
/* COLORDEMO: Display the current color palette on the screen. */
/* */
void ColorDemo(void)
{
struct viewporttype vp;
int color, height, width;
int x, y, i, j;
char cnum[5];
MainWindow( "Color Demonstration" ); /* Show demonstration name */
color = 1;
getviewsettings( vp ); /* Get the current window size */
width = 2 * ( (vp.right+1) / 16 ); /* Get box dimensions */
height = 2 * ( (vp.bottom-10) / 10 );
x = width / 2;
y = height / 2; /* Leave 1/2 box border */
for( j=0 ; j3 ; ++j ){ /* Row loop */
for( i=0 ; i5 ; ++i ){ /* Column loop */
setfillstyle(SOLID_FILL, color); /* Set to solid fill in color */
setcolor( color ); /* Set the same border color */
bar( x, y, x+width, y+height ); /* Draw the rectangle */
rectangle( x, y, x+width, y+height ); /* outline the rectangle */
if( color == BLACK ){ /* If box was black... */
setcolor( WHITE ); /* Set drawing color to white */
rectangle( x, y, x+width, y+height ); /* Outline black in white*/
}
itoa( color, cnum, 10 ); /* Convert # to ASCII */
outtextxy( x+(width/2), y+height+4, cnum ); /* Show color # */
color = ++color % MaxColors; /* Advance to the next color */
x += (width / 2) * 3; /* move the column base */
} /* End of Column loop */
y += (height / 2) * 3; /* move the row base */
x = width / 2; /* reset column base */
} /* End of Row loop */
Pause(); /* Pause for user's response */
}
/* */
/* ARCDEMO: Display a random pattern of arcs on the screen */
/* until the user says enough. */
/* */
void ArcDemo(void)
{
int mradius; /* Maximum radius allowed */
int eangle; /* Random end angle of Arc */
struct arccoordstype ai; /* Used to read Arc Cord info */
MainWindow( "Arc Demonstration" );
StatusLine( "ESC Aborts - Press a Key to stop" );
mradius = MaxY / 10; /* Determine the maximum radius */
while( !kbhit() ){ /* Repeat until a key is hit */
setcolor( random( MaxColors - 1 ) + 1 ); /* Randomly select a color */
eangle = random( 358 ) + 1; /* Select an end angle */
arc( random(MaxX), random(MaxY), random(eangle), eangle, mradius );
getarccoords( ai ); /* Read Cord data */
line( ai.x, ai.y, ai.xstart, ai.ystart ); /* line from start to center */
line( ai.x, ai.y, ai.xend, ai.yend ); /* line from end to center */
} /* End of WHILE not KBHIT */
Pause(); /* Wait for user's response */
}