STEP1
完成语义分析器
我用的vs2013 c语言写的
这个过程会在下一篇文章中详讲
准备好几个编译好的图,放在一个文件夹里,像下面这样
STEP2
规划好html的框架
上代码!
(截图版)
(文本版)
<body>
<div class="menu" id="menu">设置class id名称是为了css代码中用选择器
<div> <p>test 1</p>
<ul>
<li>origin is (20, 200);<br>rot is 0;<br>scale is (40, 40);<br>for T from 0 to 2*pi step pi/50 draw (t, -sin(t));<br>origin is (20, 240);<br>for T from 0 to 2*pi step pi/50 draw (t, -sin(t));<br>origin is (20, 280);<br>for T from 0 to 2*pi step pi/50 draw (t, -sin(t));<br><br><a><img src="1.png" width="485" height="170"/></a>我的5张图片大小不一样,所以他们的长宽都是独立设置的
</li>
</ul>
</div> <div> <p>test 2</p>
<ul>
<li>origin is (380, 240);<br>scale is (80, 80/3);<br>rot is pi/2+0*pi/3 ;<br>for T from -pi to pi step pi/50 draw (cos(t), sin(t));<br>rot is pi/2+2*pi/3;<br>for T from -pi to pi step pi/50 draw (cos(t), sin(t));<br>rot is pi/2-2*pi/3;<br>for T from -pi to pi step pi/50 draw (cos(t), sin(t));<br><br><a><img src="2.png" width="200" height="180" /></a><br></li>
</ul>
</div> <div> <p>test 3</p>
<ul>
<li>origin is(580, 240);<br>scale is (80, 80);<br>rot is 0;<br>for t from 0 to 2*pi step pi/50 draw(cos(t),sin(t));<br>for t from 0 to Pi*20 step Pi/50 draw<br>((1-/(0/7))*Cos(T)+/(10/7)*Cos(-T*((10/7)-1)),<br>(1-1/(10/7))*Sin(T)+1/(10/7)*Sin(-T*((10/7)-1)));<br><br><a><img src="3.png" width="200" height="180"/></a></li>
</ul>
</div> <div> <p>test 4</p>
<ul>
<li>rot is 0; origin is (50, 400); scale is (2, 1);<br>for T from 0 to 300 step 1 draw (t, 0);<br>for T from 0 to 300 step 1 draw (0, -t);<br>scale is (2, 1); for T from 0 to 300 step 1 draw (t, -t);<br>scale is (2, 0.1); for T from 0 to 55 step 1 draw (t, -t*t);<br>scale is (10, 5); for T from 0 to 60 step 1 draw (t, -sqrt(t));<br>scale is (20, 0.1); for T from 0 to 8 step 0.1 draw (t, -exp(t));<br>scale is (2, 20); for T from 0 to 300 step 1 draw (t, -ln(t));<br><br><a><img src="4.png" width="485" height="200"/></a></li>
</ul>
</div> <div> <p>test 5</p>
<ul>
<li>origin is (100, 300);<br>rot is 0;<br>scale is (1, 1);<br>for T from 0 to 200 step 1 draw (t, 0);<br>for T from 0 to 150 step 1 draw (0, -t);<br>for T from 0 to 120 step 1 draw (t, -t);<br><br><a><img src="5.png" width="300" height="220"/></a></li>
</ul>
</div> </div><!-- menu end -->这个注释非常建议写,因为会比较清晰的看出结构
STEP3
完成css部分
<style type="text/css">
*{margin:;
padding:;
list-style:none;}开始先清除原来所有格式
body{background-image: url(two.jpg)}设置背景图片,要注意把图片和代码放在同一个文件夹里
.menu{width:550px;
margin-top: 50px;
margin-left: 500px;
/* border:1px solid #ccc;*/
}
.menu p{height:25px;
line-height:25px;
font-weight:bold;
background:#B7EECF;16进制表示颜色
border-bottom:1px solid gray;英文表示颜色
cursor:pointer;鼠标放在text1(text2等等)上面,会显示手指的样子
padding-left:5px;
text-align: center;} .menu div ul{display:none;}点进页面的初态,测试代码和编译图片是不显示的,通过js改变显示状态 .menu li{
padding-left:5px;
/*background-color: #B1F4C3;*/
background-color: #D3D3B1;}挑一个好看的颜色~ p:hover{color: #F1ADA2;text-decoration: underline;font-style: italic;font-size:27px;
}当鼠标滑过text1(text2等)上面时,字会变成粉色(#F1ADA2),加下划线,斜体,放大2号
li:active{color:brown;
}当鼠标点击测试代码时,测试代码会变成棕色
a:hover{border-bottom:2px solid gold;} 当鼠标滑过图片时,图片会加金色的底边线
</style>
STEP4
JavaScript部分
<script type="text/javascript">
window.onload=function()
{
var menu=document.getElementById('menu'),
ps=menu.getElementsByTagName('p'),
uls=menu.getElementsByTagName('ul');
for(var i in ps)
{
ps[i].id=i;
ps[i].onclick=function()
{
var u=uls[this.id]; 更改测试代码和编译图片的显示状态
if(u.style.display=='block')
{
u.style.display='none';
}else
{
u.style.display='block';
}
}
} }
</script>
STEP5
来看最终效果图
需要注意备选背景图的大小,因为这个图片要铺满整个网页。
喵~