Coder Social home page Coder Social logo

pixel-smile's Introduction

Pixel Smiley in Console

This TypeScript program draws a simple Smiley face using pixels (X) in the console.

How it Works

The "Pixels" are represented by a boolean[] array (true = pixel on, false = pixel off), stored in a row-major order, meaning that each subsequent array's member is a pixel next to the previous one.

Main Functions

drawDot(x: number, y: number)

Draws a single dot at the given (x, y) position, if it is within image boundaries.

drawHorizontalLine(x: number, y: number, length: number)

Draws a horizontal line starting from the (x, y) position for the specified length in pixels.

drawVerticalLine(x: number, y: number, length: number)

Draws a vertical line starting from the (x, y) coordinates for the specified length in pixels.

drawRectangle(x: number, y: number, width: number, height: number)

Draws a rectangle of specified width and height, starting from position (x, y).

outputImage(onChar = "X", offChar = " ")

Prints the current state of imageData to the console, representing "on" pixels as "X" (default) or whatever character is passed as onChar, and "off" pixels as " " (default) or whatever character is passed as offChar.

createImageData(): boolean[]

This function initializes the array imageData with the false values, effectively "clearing" our canvas image.

Visual Output

Here is what the output looks like in console:

Console Pixel Smiley

Unleash Your Creativity!

This code is really a starting point. From here you can expand this to draw more complex images or even animations in your console. Creativity is your only limitation. Plus, it would be a fun way to get more understanding of how images are drawn digitally. Enjoy your coding journey! Happy coding adventure! ๐Ÿš€

pixel-smile's People

Contributors

merv-e avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.