1,首先用圖紙畫(huà)一個(gè)心形。 2,使用方框,把每筆,做成一個(gè)點(diǎn)。 3,輸出這些點(diǎn)。就可以了。 希望能幫到你
創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站制作、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的金安網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
把如下代碼加入body區(qū)域中
style type="text/css"
body
{
background-color:#FFFFFF;
font-family: Arial;
font-size:10pt;
}
/style
script
text=new Array('www','njcatv','net','需要放大的
/\/\
\ /
\/
文字')
var numText=4
color=new Array('#000000','#2F2F2F','#4F4F4F','#7F7F7F','#408080')
var numColors=5
var endSize=70
var Zspeed=30
var Cspeed=200
var font='Arial Black'
var hide=false
var size=10
var gonum=0
var ie, n;
if (document.all) {
n=0
ie=1
zoomText='document.all.zoom.innerText=text[num]'
zoomSize='document.all.zoom.style.fontSize=size'
closeIt=""
fadeColor="document.all.zoom.style.color=color[num]"
}
if (document.layers) {
n=1;ie=0
zoomText=""
zoomSize="document.zoom.document.write('p align=\"center\" style=\"font-family:'+font+'; font-size:'+size+'px; color:'+color[0]+'\"'+text[num]+'/p')"
closeIt="document.zoom.document.close()"
fadeColor="document.zoom.document.write('p align=\"center\" style=\"font-family:'+font+'; font-size:'+endSize+'px; color:'+color[num]+'\"'+text[numText-1]+'/p')"
}
function zoom(num,fn){
if (sizeendSize){
eval(zoomText)
eval(zoomSize)
eval(closeIt)
size+=5;
setTimeout("zoom("+num+",'"+fn+"')",Zspeed)
}else{
eval(fn);
}
}
function fadeIt(num){
if (numnumColors){
eval(fadeColor)
eval(closeIt)
num+=1;
setTimeout("fadeIt("+num+")",Cspeed)
}else{
hideIt()
}
}
function hideIt(){
if(hide){
if(ie)document.all.zoom.style.visibility="hidden"
if(n)document.layers.zoom.visibility="hidden"
}
}
function init(){
if(ie){
document.all.zoom.style.color=color[0]
document.all.zoom.style.fontFamily=font
}
if(ie || n) go(0)
}
function go(num){
gonum+=1
size=10
if(numnumText){
zoom(num,'go('+gonum+')')
}else{
fadeIt(0)
}
}
/script
div id="zoom" align="center" style="position:absolute; top:150"
用方程的話肯定輸出不會(huì)和你的圖完全一致
心形線方程如圖
用上面行第二個(gè)比較簡(jiǎn)單,程序如下
#include?stdio.h
bool?draw(float?x,?float?y)
{
float?a?=?x?*?x?+?y?*?y?-?1.0;
float?b?=?x?*?x?*?y?*?y?*?y;
return?a?*?a?*?a?-?b?=?0;
}
int?main(int?argc,?char*?argv[])
{
for?(float?y?=?1.5;?y?=?-1.5;?y?-=?0.1)
{
for?(float?x?=?-1.2;?x?=?1.2;?x?+=?0.05)
{
if?(draw(x,?y))
{
bool?left?=?draw(x?-?0.05,?y);
bool?right?=?draw(x?+?0.05,?y);
bool?up?=?draw(x,?y?+?0.1);
bool?down?=?draw(x,?y?-?0.1);
if?(left??right??up??down)
printf("?");
else
printf("*");
}
else
printf("?");
}
printf("\n");
}
return?0;
}
draw函數(shù)是判斷(x,y)坐標(biāo)是否在心形范圍內(nèi)
主函數(shù)循環(huán),y取值±1.5之間,步長(zhǎng)0.1,x取值±1.2之間,步長(zhǎng)0.05
如果(x,y)坐標(biāo)在心形范圍外打印空格
如果(x,y)坐標(biāo)在心形范圍內(nèi),由于這個(gè)心是空心的,要繼續(xù)判斷是不是心形邊緣,判斷周?chē)?個(gè)點(diǎn)坐標(biāo),如果都在范圍內(nèi),表示(x,y)坐標(biāo)不會(huì)是邊緣,打印空格,否則是邊緣,打印星號(hào)
最終結(jié)果如圖
import java.util.Scanner;
public class test{
static void draw(int n)
{
int i,j;
for (i=1-(n1);i=n;i++)
if (i0)
{
for (j=0;ji;j++) System.out.print(" ");
for (j=1;j=2*(n-i)+1;j++)
if (j==1||j==2*(n-i)+1) System.out.print(" *");
else System.out.print(" ");
System.out.println("\n");
}
else
if (i==0)
{
System.out.print(" *");
for (j=1;jn;j++) System.out.print(" ");
System.out.print(" *");
for (j=1;jn;j++) System.out.print(" ");
System.out.print(" *\n");
}
else
{
for (j=i;j0;j++) System.out.print(" ");
for (j=1;j=n+2*i+1;j++)
if (i==1-(n1)) System.out.print(" *");
else if (j==1||j==n+2*i+1) System.out.print(" *");
else System.out.print(" ");
for (j=1;j=-1-2*i;j++) System.out.print(" ");
for (j=1;j=n+2*i+1;j++)
if (i==1-(n1)) System.out.print(" *");
else if (j==1||j==n+2*i+1) System.out.print(" *");
else System.out.print(" ");
System.out.print("\n");
}
}
public static void main(String[] args) {
System.out.println("Please input the size (n=4):");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
draw(n);
}
}先說(shuō)明這個(gè)不是我寫(xiě)的 是看了有人用C語(yǔ)言寫(xiě)的 就順便改成了java 結(jié)果有點(diǎn)像愛(ài)心 還湊合著 你看看怎么樣吧 哈
1,首先用圖紙畫(huà)一個(gè)心形。
2,使用方框,把每筆,做成一個(gè)點(diǎn)。
3,輸出這些點(diǎn)。就可以了。
希望能幫到你
分享標(biāo)題:java顯示心形代碼 java編程一個(gè)心形圖案
標(biāo)題鏈接:http://www.chinadenli.net/article0/hpggio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、定制網(wǎng)站、搜索引擎優(yōu)化、網(wǎng)站設(shè)計(jì)公司、服務(wù)器托管、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容