Python画笑脸的程序(用python画笑脸简单)
用c语言怎么画笑脸?求代码。
先在程序定义一个在屏幕中运动的点的结构:
struct
move_point
{
int
x,
y;/*该点的位置,包括x坐标和y坐标*/
int
xv,
yv;/*该点在x轴、y轴的速度*/
};
运动的原理是,先擦去物体先前的轨迹,让物体按其速度移动一段距离,再画出该物体让我们看到以下代码:
gotoxy(man.x,
man.y);/*把光标移到指定的坐标*/
printf(““);/*输出一个空格,把先前的字符擦去*/
然后我们让物体按其速度运动:
man.x
+=
man.xv;/*水平方向按x轴的速度运动*/
man.y
+=
man.yv;/*垂直方向按y轴的速度运动*/
运动后还要判断物体是否出界,如果出了界,就令物体反弹,即让它下一刻的速度等于现在的速度的相反数最后打印出这个笑脸:
gotoxy(man.x,
man.y);
printf(“%c\b”,
2);
/*输出ascii码值为2的“笑脸”字符*/
望采纳,谢谢
如何用c语言编写一个程序,输出一张笑脸?
#includestdio.h
#include Windows.h
struct move_point
{
int x,y;
int xv,yv;
}man;
void gotoxy(int x, int y) //x为列坐标,y为行坐标
{
COORD pos = {x,y};//定义坐标
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);//设置一个句
SetConsoleCursorPosition(hOut, pos);
}
void main()
{
int i;
gotoxy(10, 10);
printf("%c", 2);
for(i = 0; i 40; i++)
{
gotoxy(10 + i, 10)
printf(" ");
printf("%c", 2);
Sleep(100);
}
}
求一个python编写一个类的代码
一个用字符展示表情的类,传入参数次数,可使用方法smile, dizzy, peace, greedy, nerd
这个里面代码都没空格,请自行加空格或分隔符
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
class code_emoji():
def __init__(self, n):
self.number = n
self.code = [94, 95, 118, 62, 60, 39, 36]
def __str__(self):
return 'this is just a code emoji class!'
def __order(self, func):
func = getattr(func, '__name__')
if func == "smile":
return [self.code[0], self.code[1], self.code[0]]
elif func == "peace":
return [self.code[2], self.code[1], self.code[2]]
elif func == "dizzy":
return [self.code[3], self.code[1], self.code[4]]
elif func == "greedy":
return [self.code[-1], self.code[1], self.code[-1]]
elif func == "nerd":
return [self.code[-2], self.code[1], self.code[-2]]
def smile(self):
print "\n笑脸"
for i in xrange(self.number):
print "".join([chr(i) for i in self.__order(self.smile)])
def dizzy(self):
print "\n晕"
for i in xrange(self.number):
print "".join([chr(i) for i in self.__order(self.dizzy)])
def peace(self):
print "\n平静"
for i in xrange(self.number):
print "".join([chr(i) for i in self.__order(self.peace)])
def greedy(self):
print "\n贪婪"
for i in xrange(self.number):
print "".join([chr(i) for i in self.__order(self.greedy)])
def nerd(self):
print "\n毫无波动"
for i in xrange(self.number):
print "".join([chr(i) for i in self.__order(self.nerd)])
if __name__ == '__main__':
a = code_emoji(2)
a.smile()
a.dizzy()
a.peace()
a.greedy()
a.nerd()
程序运行结果:
C:\Python27\python.exe G:/windows_code/python/threat/just_test.py
笑脸
^_^
^_^
晕
_
_
平静
v_v
v_v
贪婪
$_$
$_$
毫无波动
'_'
'_'
Process finished with exit code 0