Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize Christmas Tree based on graphics.h in C language

Shulou Source: shulou.com Published: 2022-06-02 05:38:23 10月03日 Update

This article mainly introduces the C language based on graphics.h how to achieve Christmas tree, the article is very detailed, has a certain reference value, interested friends must read it!

Header file icon.h:

# pragma once#ifndef _ ICON_H_#define _ ICON_H_# include#include#include#include#include#include#include#pragma comment (lib, "winmm.lib") using namespace std; void init () {initgraph (600,720); setbkcolor (RGB (255,255,255)); cleardevice ();} void drawTree () {IMAGE tree; setfillcolor (RGB (255,255,255)) Setbkcolor (RGB (255,255,255); loadimage (& tree, "tree.jpg", 600,580, true); putimage (0150, & tree);} void drawDelc () {IMAGE delc; setfillcolor (RGB (255,255,255)); setbkcolor (RGB (255,255,255)); loadimage (& delc, "delc.jpg", 150,150, true) Putimage (220,0, & delc);} void Star (int x drawing int y) {IMAGE star; setfillcolor (RGB (255,255,255)); setbkcolor (RGB (255,255,255)); loadimage (& star, "star.jpg", 50,50, true); putimage (x, y, & star);} void Shining (int x drawing int y) {setbkcolor (RGB (255,255,255)) Clearrectangle (x400); Star (x, y);} void music () {mciSendString (TEXT ("open Christmas.wav alias bgm"), NULL, 0, NULL); mciSendString (TEXT ("play bgm"), NULL, 0, NULL);} void close () {getchar (); closegraph ();} # endif / /! _ ICON_H_

If the music function plays Christmas.wav music in the same directory, you need to import the music into the same directory and modify the music file directory in the function as appropriate, otherwise there will be no sound.

Image materials also need to be imported on their own.

Cpp file Christmas tree. Cpp:

# include#include#include#include#include#include "icon.h" using namespace std; int main () {init (); drawTree (); drawDelc (); Star (60,360); Star (490,360); Star (150,180); Star (400,180); music (); while (1) {music () Shining (60,360); Shining (490,360); Shining (150,180); Shining (400,180);} close (); return 0;}

Effect picture:

The above is all the content of the article "how to realize Christmas Tree based on graphics.h in C language". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Christmas trees files directories languages contents functions articles music alto values interests images sounds guys buddies situations effects effects more knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info NVidia Apple Shulou Information Linux