\"Draw a happy face image using the graphics commands. Have the image move acros
ID: 3605643 • Letter: #
Question
"Draw a happy face image using the graphics commands. Have the image move across the screen. When it reaches the right hand side of the screen, have the image re-appear on the left hand side of the screen and move to the right side again and repeat the above process. Display a happy face text message onto the screen using the graphics command."
I have created the Happy face. HERE IS MY PROGRAM. How could I make the eyes as hearts? and to get it to move?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Smile_13
{
public partial class Lawrence : Form
{
int xpos = 5;
int ypos = 5;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen myPen = new Pen(Brushes.Red, 10);
Pen myPen2 = new Pen(Brushes.Pink, 10);
int endX = this.ClientRectangle.Width;
int emdY = this.ClientRectangle.Height;
int xCenter = this.ClientRectangle.Left + (this.ClientRectangle.Width / 2);
int yCenter = this.ClientRectangle.Top + (this.ClientRectangle.Height /2);
Pen circlePen = new Pen(Brushes.Pink, 9);
Font myFont = new Font("Comic Sans MS", 36, FontStyle.Italic);
g.DrawString("Hello Mr.Bossie", myFont, Brushes.Pink, 300, 30);
g.DrawEllipse(circlePen, xpos, ypos + 150, 250, 200);
g.FillEllipse(Brushes.Black, xpos, ypos + 150, 250, 200);
g.DrawEllipse(circlePen, xpos + 85, ypos + 200, 20, 35);
g.FillEllipse(Brushes.Pink, xpos + 85, ypos + 200, 20, 35);
g.DrawEllipse(circlePen, xpos + 160, ypos + 200, 20, 35);
g.FillEllipse(Brushes.Pink, xpos + 160, ypos + 200, 20, 35);
g.DrawArc(circlePen, xpos + 60, ypos + 215, 130, 120, 35, 115);
}
private void timer_Tick(object sender, EventArgs e)
{
xpos = xpos + 7;
if (xpos >= this.ClientRectangle.Right - 350)
{
xpos = 0;
}
this.Invalidate();
}
}
}
Explanation / Answer
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" Grid.Column="0">
<Canvas Name="canvas1" Background="Transparent">
<Ellipse Width="100" Height="100"
Fill="Yellow" Stroke="Red" StrokeThickness="3"/>
<Ellipse Width="20" Height="30"
Canvas.Left="20" Canvas.Top="20"
Fill="White" Stroke="Black" StrokeThickness="1"/>
<Ellipse Width="10" Height="20"
Canvas.Left="30" Canvas.Top="25"
Fill="Black" Stroke="Black" StrokeThickness="1"/>
<Ellipse Width="20" Height="30"
Canvas.Left="60" Canvas.Top="20"
Fill="White" Stroke="Black" StrokeThickness="1"/>
<Ellipse Width="10" Height="20"
Canvas.Left="70" Canvas.Top="25"
Fill="Black" Stroke="Black" StrokeThickness="1"/>
<Ellipse Width="15" Height="25"
Canvas.Left="42.5" Canvas.Top="45"
Fill="LightBlue" Stroke="Blue" StrokeThickness="1"/>
<Path Stroke="Black" StrokeThickness="2"
Data="M 15,50 A 35,35 0 1 0 85,50" />
</Canvas>
</Grid>
...
</Grid>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.