58 Best Lunar/Chinese New Year Templates and Graphics

The Lunar New Year brings people together in celebration of ancient tradition. If you love this time of year and plan on having a celebration of your own, check out this collection of premium design assets below.

What Is the Lunar New Year?

With celebrations starting at the turn of the traditional Lunar New Year, the Chinese New Year is a festival that is centuries old with roots in several ancient myths and traditions.

Each year, an animal represents the year according to the ancient Chinese zodiac. It’s also known as the Chinese New Year, and celebrations range from traditional prayers and feasts to incredible lion dances showcasing beautiful costumes. As 2017 comes to an end, 2018 marks the Year of the Dog. Following the rooster in the zodiac, this symbol is believed to represent honesty and loyalty.

So in this collection of over 50 amazing assets, we present you with a plethora of amazing resources from both Envato Market and Envato Elements.

Need help modifying these templates? Enlist the help of a design professional by contacting the good folks at Envato Studio.

25 High-Quality Premium Flyers

Let’s kick things off with 27 premium party flyers full of color and wonder. With designs ranging from simple to more complex, you’ll be sure to find just the right flyer to fit your holiday needs.

Simplistic Chinese New Year Flyer

If
a simple look is more your style, this beautiful flyer features a few
Chinese-inspired elements against a vibrant red background. The file for
this template comes 100% ready to print, with organized layers that you
can easily modify.

Simplistic Chinese New Year Flyer

Gold Chinese New Year Flyer

Gold adds instant luxury to any design. Enjoy this lovely flyer, for instance. The sleek design features a few golden lanterns and text placeholders for your party details written with several free fonts.  Give this one a try!

Gold Chinese New Year Flyer

Sexy Chinese New Year Flyer

Complete with two separate versions available, this flyer is sizzling with fiery red colors and traditional Chinese elements. Replace the model seen below with your own stock for a more personalized touch.

Sexy Chinese New Year Flyer

Chinese New Year Party Flyer

Most flyers during this time will have the same colors. Step out of the box with this suite of unique color schemes. This download includes fully editable Photoshop and Illustrator files ready for your personal touch.

Chinese New Year Party Flyer

Ancient Chinese New Year Flyer

Adorned with ancient Asian symbols and incredible architectural elements, this poster will dazzle your partygoers with its beauty and mysticism. This template comes complete with several color options organized into easy-to-edit layers.

Ancient Chinese New Year Flyer

Happy Chinese New Year

What New Year would be complete without fireworks, champagne, and dragons? This explosive flyer features a dazzling modern design that is easy to modify, with all the design elements included.

Happy Chinese New Year

Golden Chinese New Year Party Flyer

If you love a bit of shine and dazzle with your designs, consider this gorgeous template jam-packed with beautiful golden coins and treasure. Perfect for the newbie to Photoshop, this flyer needs no model and is ready for printing right away!

Golden Chinese New Year Party Flyer

Modern Chinese New Year Flyer

Or keep things minimal with this modern flyer. At the center of its design is a firecracker blasting through typography. Choose from three different color schemes or develop your own using this template!

Modern Chinese New Year Flyer

Fierce Chinese New Year Template

With the glowing eyes of a beautiful traditional dragon as its centered subject, this gorgeous template design features large, bold text and beautiful orange lanterns. View the video tutorial included with this template to learn how to customize this flyer quickly and easily.

Fierce Chinese New Year Template

Chinese New Year Sale Flyer

Are flyers good for your business? Test it out with this minimalist design. This template features a bold headline to grab your customers with plenty of room for store and sale details.

Chinese New Year Sale Flyer

Chinese New Year Flyer Template

For more subdued colors and design, check out this Chinese New Year template below. This design features some elegant sparkly text front and center, with a beautiful red curtain behind it. Change out the party information for your own and send this flyer straight to the printer!

Chinese New Year Flyer Template

Chinese New Year Club Flyer

In this incredible club flyer, you get fully editable text organized in an A4 file that is easy to use. Complete your club experience with this fantastic flyer and download your own stock to replace the beautiful model below.

Chinese New Year Club Flyer

Chinese New Year of The Goat Flyer

Bring in the Chinese New Year with this elegant and traditional vibe. With five alternatively colored versions to choose from, you’ll be able to use this design for many more years to come.

Chinese New Year of The Goat Flyer

Elegant Chinese New Year Flyer

Need something elegant with an artistic flair? This Chinese-inspired flyer comes complete with a beautiful golden border and a few simple design elements to celebrate the Lunar New Year. With multiple color options to choose from, you’ll find this template a breeze to use.

Elegant Chinese New Year Flyer

Chinese New Year Celebration Flyer

For a beautiful design with a subtle hint of tradition and history, check out this incredible party flyer. Complete with unique fonts and gorgeous background elements, this flyer is perfect for your next celebration.

Chinese New Year Celebration Flyer

Chinese New Year Celebration

Dragons are an important part of any Chinese New Year celebration. Showcase your love for the traditional lion dance with this fun party flyer design. With several color styles to choose from, these design elements are 100% scalable and completely print-ready.

Chinese New Year Celebration

Chinese Year of the Monkey Flyer

For your next celebration or party event, consider this gorgeous flyer design. Change the text easily to fit your celebrations, and swap out the model below for the preferred stock of your choice.

Chinese Year of the Monkey Flyer

Chinese New Year Celebration Flyer

Red lanterns bring a stunning warm hue to any room. And you can enjoy that vibrant look with this festive flyer. Just add your details for professional design in minutes. Enjoy!

Chinese New Year Celebration

Chinese New Year Party Flyer

You might want to get your sunglasses for this party flyer. Complete with bright red Chinese elements against a sunny yellow background, this flyer is sure to impress as the perfect invite for your celebration.

Chinese New Year Party Flyer

Simple Chinese New Year Flyer

Need a flyer that’s simple in design? Well look no further! This elegant flyer design celebrates the year of the monkey, but feel free to adjust the text to your preferences in the fully editable file.

Simple Chinese New Year Flyer

Chinese New Year Celebration Flyer

Dive into this Chinese New Year flyer to get access to fully editable layers and so much more. Created in Photoshop, this design features a festive design with Chinese-inspired masks, parasols, and statues. Also included in this package are amazing free fonts.

Chinese New Year Celebration Flyer

Happy Chinese New Year

The beautiful costumes, architecture, and designs of the Chinese culture are truly highlighted in this gorgeous flyer design. Complete with a help file and links to free fonts, this flyer template is incredibly easy to use.

Happy Chinese New Year

Lantern Chinese New Year Flyer

Show off your fashion and style with this fun party flyer design. Swap out the model’s photo for your own, and kick off your celebrations with this print-ready template.

Lantern Chinese New Year Flyer

Chinese Lunar New Year Flyer

Celebrate the history and tradition of this special time of the year with this incredible premium flyer. Swap out the model’s picture for a stock of your own, and download the free fonts included to utilize this flyer to its fullest.

Chinese Lunar New Year Flyer

Watercolor Chinese New Year

With a beautiful watercolor back splash of brush textures for the background, these unique party poster features Chinese lanterns, easily editable text, and elements that are 100% scalable.

Watercolor Chinese New Year

11 Gorgeous Greeting Cards

In this next collection of Chinese New Year-themed designs, check out these beautiful greeting cards you can use for your personal invitations. Enjoy these incredible designs curated from GraphicRiver.

Happy Chinese New Year Greeting Card Design

Kick off your celebrations with this minimalist greeting card. This design features a gorgeous landscape with red paper lanterns and festive elements. Just add your message to finish the charming design.

Happy Chinese New Year Greeting Card Design

Folding Fan Chinese New Year Template

We start this collection of cards with this elegant and gorgeous folding fan design. This card features a beautiful fan adorned with traditional cherry blossoms, and text that spells out “Happy New Year”. Download this remarkable vector file to complete your New Year celebrations.

Folding Fan Chinese New Year Template

Chinese New Year Greeting Card

Though 2016 marked the Year of the Monkey, you can easily customize this greeting card design to fit your needs. Simply download the appropriate file after your purchase, and swap out the text for the title of your choice.

Chinese New Year Card

Firecracker Chinese New Year Card

Celebrate the moment when fireworks light up the air and the wonderful festivities of the Chinese New Year begin. This charming greeting card design features beautiful golden text with firework elements in the background. Included with this template are free fonts, a help file, and so much more.

Firecracker Chinese New Year Card

Red Background Chinese New Year Greeting Card

Greet your friends and relatives with this elegant greeting card design. This design features three gorgeous vector lanterns against a simple red background that is perfect for any invitation.

Red Background Chinese Greeting Card

Fun Chinese New Year Greeting Card

This fun and clever design features a funny ensemble of traditionally dressed characters and beautiful golden lanterns adorned with happy faces. Enjoy this vector illustration and customize this card to fit your needs with the help of Adobe Illustrator.

Fun Chinese New Year Greeting Card

Happy Chinese New Year Card

Check out this awesome greeting card featuring an amazing character design that is sure to impress your partygoers. This card can be used as a greeting card or e-card for your company and comes with layered Photoshop files for easy editing.

Happy Chinese New Year Card

Cherry Blossom Chinese New Year Flyer

Whether you’ve fallen in love with the funny monkey character or love cherry blossoms, this fun greeting card is sure to bring you and your event attendees some delight. Complete with organized layers, this template is easy to customize in Adobe Photoshop.

Cherry Blossom Chinese New Year

Chinese New Year Greeting Card

Send your loved ones this happy greeting card for a special treat! This design features a charming festival dancer with traditional Chinese New Year elements. Enjoy the bright colors and minimalist details.

Chinese New Year Greeting Card

Chinese New Year Gold Dragon Greeting Card

Inspire
a fun mood with this fun dragon greeting card. Created for the Chinese
New Year, this design features a massive gold dragon and small red
lantern. Try it out! We’re sure your friends and family will be happy to
receive this card!

Chinese New Year Gold Dragon Greeting Card

Chinese Greeting Card

Or leave an elegant message behind with this vibrant greeting card. This illustration features traditional Chinese lanterns, and more details we’re sure you’ll love. Combine it with a nice font for a thoughtful message. Try this design!

Chinese Greeting Card

22 Divine Vector Design Elements

Last but not least, this next selection includes gorgeous design elements inspired by this fantastic holiday. From icon sets to character designs and more, bring in the Chinese New Year by featuring these incredible designs.

Chinese New Year Icons Set

These modern pictograms are happy and energetic. And this essential set includes 10 vector icons with a modern line style. Choose from amazing designs like fire crackers, lotus flowers, and beautiful lanterns.

Chinese New Year Icons Set

Chinese Vector Dragon

Dragons are not only an important part of the Chinese New Year festival, but they also represent one of the many animals on the Chinese zodiac. Adorn your celebratory designs with these clean vector dragons: one in the traditional red color, and the second featuring an awesome mix of colors.

Chinese Dragon

Chinese New Year Celebration Characters

In this lovely vector illustration, two kids join together to celebrate the Chinese New Year. Download this file after your purchase, and customize this design to create a darling greeting card or invitation.

Chinese New Year Celebration Characters

Chinese New Year Celebration

You can find many beautiful vector illustrations that celebrate this unique time of the year. In this simple illustration, a group of kids are celebrating the Chinese New Year and enjoying all the festivities. Customize this file yourself, or leave it as is for a beautiful backdrop.

Chinese New Year Celebration

Chinese New Year Icons

In this collection of Chinese New Year Icons, you’ll find nine vector illustrations that embody this celebration. From lanterns to fruit and so much more, this set will complete your icon needs.

Chinese New Year Icons

Chinese New Year Background

Need a simple background for your flyers, invites, and more? This lovely Chinese-themed background comes complete with elegantly designed flowers and a simple banner with Chinese calligraphy. The translation means “Happy New Year”, so it’ll be sure to fit all your celebratory needs.

Chinese New Year Background

Happy Chinese New Year Vector Design

If you’re looking for a simple way to say “Happy New Year” without all the fuss, then feast your eyes on this unique vector design. This design features a sublime winter theme with this saying written out in traditional Chinese lettering.

Happy Chinese New Year Vector Design

Chinese New Year Lion Dance

If you ever have the chance of witnessing a traditional lion dance, you’ll stand there in amazement as two dancers skillfully move around in this incredible costume. The following design showcases this dance perfectly, with one dancer on the bottom as the other flies into the air. Incorporate this illustration into your designs for cards, flyers, and so much more.

Chinese New Year Lion Dance

Modern Chinese New Year Icons

For that clean, modern look, take a look at these simple vector icon designs. These designs can be used pretty much anywhere, and the file comes complete with fully editable layers that can be customized quickly and easily.

Modern Chinese New Year Icons

Dragon – Chinese Symbol

The Chinese dragon is one of the most beautifully designed animals, with a history in ancient myths and folklore. To celebrate the Chinese New Year, adorn your designs with this simple vector dragon for your print or web materials.

Dragon - Chinese Symbol

Chinese New Year Kids

Among the incredibly vibrant festivities of the Chinese New Year you’ll also find amazing costumes and delectable looking foods. This set of kids’ illustrations features three young children celebrating the Lunar New Year with traditional attire and food.

Chinese New Year Kids

Mandarin Vector Illustrations

If you’re looking for a set of vector illustrations with incredible beauty and detail, then download this set of graphics. Included in this pack are pattern files, high-resolution images, and Asian-inspired design elements you can modify with Adobe Illustrator.

Mandarin Vector Illustrations

Chinese Lunar New Year Lion Dance Fight

Lion dances feature incredible Chinese costumes with vibrant accents. Use this fun illustration of a lion dance fight for posters and more. Included in this download are vector files you can edit with Adobe Illustrator.

Chinese Lunar New Year Lion Dance Fight

Chinese New Year Character Set

In this charming set of character designs, you’ll find people celebrating the festival with their traditional Chinese New Year costumes. Also included are additional elements like lanterns and a simple banner to celebrate all the festivities.

Chinese New Year Character Set

Family Celebrating Chinese New Year

The holiday season is all about family. Show how much you love your family and the tradition of Chinese culture with this darling family illustration. Use it as the centerpiece of your designs for that unique and heartwarming feel.

Family Celebrating Chinese New Year

Chinese New Year Icons

If you’re an avid collector of icons, you’ll definitely want this set in your collection. This collection features several fun designs inspired by the Lunar New Year festival, including lanterns, dragons, firecrackers, and two happy characters.

Chinese New Year Icons

Chinese Lanterns – Yellow Background

For a simple design without any text, consider this gorgeous background. This design comes complete with three red lanterns and beautiful golden flowers to complement the yellow background. Download this file and set it as your desktop or choose it as the centerpiece of your next design.

Chinese Lanterns - Yellow Background

Chinese Lanterns – Red Background

When looking for designs inspired by this wonderful tradition, you’ll be amazed at how many incredibly detailed and absolutely gorgeous elements you’ll find. This design features two Chinese lanterns hanging from a branch against a vibrant red background. Download the files and add your own elements to customize this look.

Red Background Chinese Lanterns

Chinese New Year Facebook Cover

One of the best ways to celebrate any holiday is to simply update your Facebook cover! Download this wonderful Chinese New Year design and customize it with your own information for a clever and unique cover design.

Chinese New Year Facebook Cover

Shanghai Chinese New Year Skyline

One of the many places where you’ll see these celebrations take place is Shanghai, China. Download this simple vector illustration and insert it into your designs to kick off the New Year with a modern twist.

Shanghai Chinese New Year Skyline

Chinese Good Luck Mascot

Bring charm and good luck to the New Year with this delightful Chinese-themed character design. It’s fully customizable and 100% made in Adobe Illustrator so you definitely know you’re sure to retain a high-quality design.

Chinese Good Luck Mascot

Chinese New Year Line Design Icons

Sometimes, the simpler the design, the better. You’re sure to be in agreement with this set of simple icon designs. Featuring a style that emphasizes clean lines and few colors, this set covers everything you need for the New Year.

Chinese New Year Line Design Icons

Chinese New Year Tutorials

Need a fun project? Celebrate the Chinese New Year with a tutorial! Try your hands at these amazing lessons created by our experts. Learn important tips and tricks for working with a variety of creative software.

Conclusion

This list is jam-packed with exciting resources for the avid designer
familiar with Adobe Photoshop and Illustrator. If you need additional
help modifying these templates, enlist the skills of a talented
professional by choosing one of the amazing designers from Envato Studio.

And with hundreds of design elements for the Chinese New Year at your fingertips, chances are we’ve missed a few to add to your personal collection. Be sure to browse Envato Market and Envato Elements for more resources, and let us know your favorites in the comments below!

View Tutorial: 58 Best Lunar/Chinese New Year Templates and Graphics

How to Stretch Paper for Watercolour and Gouache and Avoid My Mistakes!

Final product image
What You’ll Be Creating

In this tutorial, I will introduce you to the traditional process of paper stretching. There are a lot of tutorials and videos on the subject, but I want to take you through my many, many mistakes—ones that you can avoid—as well as teaching you how to stretch your watercolour paper. 

Why Stretch Paper?

If
you don’t stretch paper, it will buckle—the thinner the paper, the worse the
buckling, and the greater the chances of it tearing. This will lead to unsightly undulations in your work and puddling and pooling of your paint.

Many
artists avoid stretching paper altogether, while some use staples to secure their
paper. I find this destroys my board after only a short time, and I struggle to remove the staples.

I
am very heavy-handed with my watercolours and gouache. Very. I need paper that will take all the abuse I can
throw at it, and I have found a simple stretching process that still holds the paper
flat once my paintings have dried. It works for me 95% of the time, and if
on that rare occasion my paper has dried buckled, I simply cut out the paper and do it
again using the same sheet. It is a wee bit smaller because of the tape, but
it’s not completely wasted.

Below
is an example of 100gsm with a very light touch of watered-down paint.

Wrinkled and buckled paper

I used to buy pre-stretched blocks of paper but
found that the gum around the edges would tear over time. The stretch wasn’t
strong enough either, and the more I removed my finished paintings from the block, the weaker the stretch became. I eventually found I couldn’t
use the last eight or so sheets unless I stretched them myself anyway. And these blocks are expensive.

What You Will Need

1. Board for Stretching Your Paper Upon

I
only use one type of board—conti. It is the white furniture panel
that cupboards and kitchen units are made out of and can be easily found in
most DIY shops. It has woodchips in the middle which are sandwiched between
melamine. It is durable, can put up with all the water I have been known to
throw at it, is easy to clean after use (leaving it smooth), can be used over
and over again, and is inexpensive for a lot of board.

The
thickness I use is 1.5cm, and the DIY shop cuts it down to the sizes I want. I
tend to have five paintings on the go at the same time (so I can keep working as
other paintings dry), and I got my five boards from one sheet of conti. Its
downside is that it can be heavy, but once it is cut down to the sizes I prefer
to work on, it is very manageable.

Conti board

My Mistake: I
used to use normal wood, which was porous, and my tape wouldn’t stick to it 75%
of the time. If it did stick, I either couldn’t get the tape back off once the
painting was finished so I could reuse the wood, or the tape removed chunks and
splinters, leaving a ragged surface. MDF had the same problems and
expanded when it was too wet.

My Mistake: I
did some research online and sealed the wood and MDF but found that my
paintings would stick to this extra coat and tore when I tried to remove them;
or the sealant would lift off the wood with the tape as it dried, which defeated the purpose.

2. Paper

Examples of paper

I
tend to use 220gsm and 300gsm paper. They cope well with the quantities of
liquids and punishment I mete out, but only once stretched. You can get all sorts
of textured or smooth papers, and it is really up to you what you prefer, but
stretching them is more important the lighter they are. The standard ones are 190gsm, 300gsm, 356gsm, and 638gsm (this is coming into the realms
of card and can be expensive).

Try to choose an acid-free paper as this will help
prevent the deterioration of your colours. The texture is up to you, but I
would recommend a NOT (also known as cold pressed) paper. The surface is not
too rough and not too smooth (that’s not why it’s called NOT, which refers to
the way the paper has been made—not hot pressed).

3. Gummed Tape and Other Material

Gummed tape sciccors and sponge

Gummed Tape

Gummed tape is basically a strip of brown paper
with thin dry glue on one side (the shiny side). This can be bought from all good art shops and online. I
use 5cm wide tape. In the past, I have used 2.5cm, but it was too
narrow and didn’t keep my paper stretched.

Sponge

Any flat sponge will do that can be easily wrung out. Mine is a kitchen
one that is small enough to be comfortably held in my hand and has a flat,
smooth surface.

Scissors

Scissors are optional. I always have them at the
ready, but prefer to tear the gummed tape to size (it rips very easily).

Make Some Decisions

Where Are You Going to Work?

You
will need somewhere that you don’t mind getting wet, with enough space to lay
your conti board flat. I use my bathroom.

What Is Going to Contain Your Water?

Choose
something that is big enough to hold your preferred size of paper flat; a large
basin, sink, bath, or shower tray (with its drain blocked with a tennis ball).
I use my bath.

Where Will You Be Able to Comfortably Work on Your Board?

I rest
mine flat on the toilet; it’s far from glamorous, but it works. Use a table, put it on the floor, or securely place it on a sink.

Where Can You Lay Your Gummed Tape?

I
do this on the edge of my sink because it is flat, but you can use another
conti board or the edge of your bath.

Where Will You Leave Your Stretching Paper to Dry?

This
is the slow bit, so find somewhere you can leave your board (or boards) flat overnight, undisturbed.

Stretching Your Paper

Measure out strips of your gummed tape along each
side of your dry paper, tearing or cutting them so that each width is about 6cm
wider than each side of your paper. I measure by eye, just unrolling the tape and holding it against the paper as I go. I split out the lengths, putting the shorter and longer
lengths in separate piles.

My Mistake: My hands were slightly damp when I measured out
the gummed paper. They stuck to themselves, to me, and to the surface I placed
them on. Make sure your hands and the surface you are placing them on are dry.

My Mistake: I didn’t have long enough strips, and
they didn’t have enough tape on either end to stick to the conti board.

Paper soaking in the bath

Fill your bath/basin/sink with around 5–10cm
deep of cold water and place your paper in it, pushing it down gently with spread fingers so that
all of it is covered by the water. It will still float on the surface. I leave
300gsm paper for 15 minutes and 220gsm for 10 minutes. Anything thinner than
that, I leave for 5 minutes or less.

My Mistake: I didn’t leave the paper for long
enough, and the paper didn’t soak all the way through. It buckled when it was
dry, tearing at the tape I had placed round it. Useless. But this paper can be
reused. Just cut off the tape, and soak it again properly.

My Mistake: I left the paper for too long, and it
tore.

Have your sponge at the ready.

After the allotted time, lift your paper out of its
water using both your hands at opposite corners. Give it a
gentle wiggle to get rid of excess water and lay it flat on your conti board from the bottom of the paper to your hands.
If it’s not straight, lift it up again by the same two corners and lay it
gently down again. Don’t try sliding it about—you won’t be able to.

The paper may have bubbles in it or not want to lie
completely flat, but that is OK. Just gently wipe it down with your sponge
(squeeze it out every so often), taking care to move from the middle out. Don’t
rub back and forth; just sweep in one direction. If the bubbles are still
there, again, don’t worry—these will disappear when it stretches.

Soaked paper on conti board ready for stretching

My Mistake: I rubbed too hard and tore the paper or
rubbed off the top layer of the paper. Keep it light handed.

On a flat dampened surface, lay your first strip of tape gummed or shiny side up. This will keep
it flat—it always wants to roll back up.

Dry tape

Hold one end of it with one finger and with a damp
sponge stroke from your finger to the opposite end across the glue—once only.
It will now lie flat. Have a look at the tape, and if there are any bits
that are not wet, touch them up gently (including the bit where your
finger was).

Sponged gummed tape

My Mistake: I dipped the entire tape into water.
All the glue washed off.

My Mistake: I rubbed the sponge across the tape too
often and rubbed all the glue off.

My Mistake: I wasn’t gentle enough when stroking my sponge across the tape, making it too wet, and it stuck to itself.

My Mistake: I didn’t maintain dry hands, and the
tape stuck to me.

Using two hands, place your tape on the wet paper, overlapping the
paper and the conti board—2cm of tape should be on your paper—and gently
smooth it out with your sponge. If it sits at an angle, slide it into place,
but try not to move it about too much as you will lose glue.

Keep squeezing your sponge out as often as possible.

My Mistake: I used one hand when lifting it, and the tape stuck to itself.

The first strip placed on my soaked paper

Repeat this process with all four sides.

Paper with two strips of tape
Paper with three strips of tape
Paper with four strips of tape

Using your sponge, press the tape into the edges of the paper, but don’t fiddle
with it too much. Again, squeeze out excess water from your sponge as you go.

You
will find that as it dries, the paper will buckle, but it will flatten out as time
goes on.

Leave
your paper to dry overnight or until it is no longer cold to the touch, and as
tempting as it is, don’t use a hairdryer on it. The paper and tape need to dry
at the same pace, slowly.

Using Your Stretched Paper

Once
your paper is dry, it is ready to use. However, I have sometimes found that the tape has torn. But if the paper is flat, I’ve still been able to use it without any consequences, as you can see below.

This tape tore as it dried

The
paper did buckle a bit when it was wet, but dried flat every time.

Once
you have finished your painting, use a sharp knife and ruler to cut it out. It doesn’t matter if you cut into the conti
board as the scores don’t seem to affect the next paper I stretch. Just try to avoid it if you can, as you want the board to last a long time.

Cut out your painting with a sharp knife

You can also see in the image above how the tape
has torn along the edge of the paper. This didn’t affect the paper while I
worked on it—and this painting had gesso, sand medium, glues, and oriental
papers stuck to it as well as watercolour and gouache paints.

Below is an example of a painting in progress; you can just see where the paint is pooling (the blue puddle). This is where the
paper is buckling because I have laid so much down on it. Again, the painting
dried flat.

Painting with bumps and buckling

Preparing a Used Board

Board with score

Tear off the remaining tape and paper after
removing your painting (you can see where I scored the board with my knife,
above) and using a Stanley knife blade, scrape off anything else that still
remains (below). Use a damp sponge to wipe away excess paper and paint,
effectively cleaning the conti, ready for your next stretching session.

Scraping the board clean

Conclusion

Stretching
paper takes patience. The actual activity time is fairly short; it’s the drying
time that takes a while. I have found it to be very worthwhile, and given that artists have been doing it for centuries, I find it very warming that I am part of that old, old tradition.

Just avoid my mistakes and you’ll be fine.

View Tutorial: How to Stretch Paper for Watercolour and Gouache and Avoid My Mistakes!

Create an Intense “Blade Runner” Inspired Composition With Shattered Glass and Bullets

Learn how to this surreal photo manipulation of Blade Runner on an interior skyscraper with Photoshop In this lesson, you learn to work with the transformation of objects and blend modes for them. Composition and construction work on the cloning of elements. Realistic change in space and adding the effect of movement. Throughout the tutorial, […]

The post Create an Intense “Blade Runner” Inspired Composition With Shattered Glass and Bullets appeared first on Photoshop Tutorials.

View Tutorial: Create an Intense “Blade Runner” Inspired Composition With Shattered Glass and Bullets

Create the Perfect Carousel, Part 1

Carousels are a staple of streaming and e-commerce sites. Both Amazon and Netflix use them as prominent navigation tools. In this tutorial, we’ll evaluate the interaction design of both, and use our findings to implement the perfect carousel.

In this tutorial series, we’ll also be learning some functions of Popmotion, a JavaScript motion engine. It offers animation tools like tweens (useful for pagination), pointer tracking (for scrolling), and spring physics (for our delightful finishing touches.)

Part 1 will evaluate how Amazon and Netflix have implemented scrolling. We’ll then implement a carousel that can be scrolled via touch.

By the end of this series, we’ll have implemented wheel and touchpad scroll, pagination, progress bars, keyboard navigation, and some little touches using spring physics. We’ll also have been exposed to some basic functional composition.

Perfect?

What does it take for a carousel to be “perfect”? It has to be accessible by:

  • Mouse: It should offer previous and next buttons that are easy to click and don’t obscure content.
  • Touch: It should track the finger, and then scroll with the same momentum as when the finger lifts from the screen.
  • Scroll wheel: Often overlooked, the Apple Magic Mouse and many laptop trackpads offer smooth horizontal scrolling. We should utilise those capabilities!
  • Keyboard: Many users prefer not to, or are unable to use a mouse for navigation. It’s important we make our carousel accessible so those users can use our product too.

Finally, we’ll take things that extra step further and make this a confident, delightful piece of UX by making the carousel respond clearly and viscerally with spring physics when the slider has reached the end.

Setup

First, let’s get the HTML and CSS necessary to build a rudimentary carousel by forking this CodePen

The Pen is set up with Sass for preprocessing CSS and Babel for transpiling ES6 JavaScript. I’ve also included Popmotion, which can be accessed with window.popmotion.

You can copy the code to a local project if you prefer, but you’ll need to ensure your environment supports Sass and ES6. You’ll also need to install Popmotion with npm install popmotion.

Creating a New Carousel

On any given page, we might have many carousels. So we need a method to encapsulate the state and functionality of each.

I’m going to use a factory function rather than a class. Factory functions avoid the need to use the often-confusing this keyword and will simplify the code for the purposes of this tutorial.

In your JavaScript editor, add this simple function:

function carousel(container) {
}

carousel(document.querySelector('.container'));

We’ll be adding our carousel-specific code inside this carousel function.

The Hows and Whys of Scrolling

Our first task is to make the carousel scroll. There are two ways we could go about this:

Native Browser Scrolling

The obvious solution would be to set overflow-x: scroll on the slider. This would allow native scrolling on all browsers, including touch and horizontal mouse wheel devices.

There are, however, drawbacks to this approach:

  • Content outside the container would not be visible, which can be restrictive for our design.
  • It also limits the ways we can use animations to indicate we’ve reached the end.
  • Desktop browsers will have an ugly (though accessible!) horizontal scroll bar.

Alternatively:

Animate translateX

We could also animate the carousel’s translateX property. This would be very versatile as we’d be able to implement exactly the design we like. translateX is also very performant, as unlike the CSS left property it can be handled by the device’s GPU.

On the downside, we’d have to reimplement scrolling functionality using JavaScript. That’s more work, more code.

How Do Amazon and Netflix Approach Scrolling?

Both Amazon and Netflix carousels make different trade-offs in approaching this problem.

Amazon animates the carousel’s left property when in “desktop” mode. Animating left is an incredibly poor choice, as changing it triggers a layout recalculation. This is CPU-intensive, and older machines will struggle to hit 60fps.

Whoever made the decision to animate left instead of translateX must be a real idiot (spoiler: it was me, back in 2012. We weren’t as enlightened in those days.)

When it detects a touch device, the carousel uses the browser’s native scrolling. The problem with only enabling this in “mobile” mode is desktop users with horizontal scroll wheels miss out. It also means any content outside the carousel will have to be visually cut off:

Screenshot of Amazon illustrating lack of design bleed

Netflix correctly animates the carousel’s translateX property, and it does so on all devices. This enables them to have a design that bleeds outside the carousel:

Screenshot of Netflix carousel illustrating design bleed

This, in turn, allows them to make a fancy design where items are enlarged outside of the x and y edges of the carousel and the surrounding items move out of their way:

Screenshot of Netflix carousel illustrating enlarged item

Unfortunately, Netflix’s reimplementation of scrolling for touch devices is unsatisfactory: it uses a gesture-based pagination system which feels slow and cumbersome. There’s also no consideration for horizontal scroll wheels.

We can do better. Let’s code!

Scrolling Like a Pro

Our first move is to grab the .slider node. While we’re at it, let’s grab the items it contains so we can figure out the slider’s dimension.

function carousel(container) {
  const slider = container.querySelector('.slider');
  const items = slider.querySelectorAll('.item');
}

Measuring the Carousel

We can figure out the visible area of the slider by measuring its width:

const sliderVisibleWidth = slider.offsetWidth;

We’ll also want the total width of all the items contained within. To keep our carousel function relatively clean, let’s put this calculation in a separate function at the top of our file.

By using getBoundingClientRect to measure the left offset of our first item and the right offset of our last item, we can use the difference between them to find the total width of all items.

function getTotalItemsWidth(items) {
  const { left } = items[0].getBoundingClientRect();
  const { right } = items[items.length - 1].getBoundingClientRect();
  return right - left;
}

After our sliderVisibleWidth measurement, write:

const totalItemsWidth = getTotalItemsWidth(items);

We can now figure out the maximum distance our carousel should be allowed to scroll. It’s the total width of all our items, minus one full width of our visible slider. This provides a number that allows the rightmost item to align with the right of our slider:

const maxXOffset = 0;
const minXOffset = - (totalItemsWidth - sliderVisibleWidth);

With these measurements in place, we’re ready to start scrolling our carousel.

Setting translateX

Popmotion comes with a CSS renderer for the simple and performant setting of CSS properties. It also comes with a value function which can be used to track numbers and, importantly (as we’ll soon see), to query their velocity.

At the top of your JavaScript file, import them like so:

const { css, value } = window.popmotion;

Then, on the line after we set minXOffset, create a CSS renderer for our slider:

const sliderRenderer = css(slider);

And create a value to track our slider’s x offset and update the slider’s translateX property when it changes:

const sliderX = value(0, (x) => sliderRenderer.set('x', x));

Now, moving the slider horizontally is as simple as writing:

sliderX.set(-100);

Try it!

Touch Scroll

We want our carousel to start scrolling when a user drags the slider horizontally and to stop scrolling when a user stops touching the screen. Our event handlers will look like this:

let action;

function stopTouchScroll() {
  document.removeEventListener('touchend', stopTouchScroll);
}

function startTouchScroll(e) {
  document.addEventListener('touchend', stopTouchScroll);
}

slider.addEventListener('touchstart', startTouchScroll, { passive: false });

In our startTouchScroll function, we want to:

  • Stop any other actions powering sliderX.
  • Find the origin touch point.
  • Listen to the next touchmove event to see if the user is dragging vertically or horizontally.

After document.addEventListener, add:

if (action) action.stop();

This will stop any other actions (like the physics-powered momentum scroll that we’ll implement in stopTouchScroll) from moving the slider. This will allow the user to immediately “catch” the slider if it scrolls past an item or title that they want to click on.

Next, we need to store the origin touch point. That will allow us to see where the user moves their finger next. If it’s a vertical movement, we’ll allow the scrolling of the page as usual. If it’s a horizontal movement, we’ll scroll the slider instead.

We want to share this touchOrigin between event handlers. So after let action; add:

let touchOrigin = {};

Back in our startTouchScroll handler, add:

const touch = e.touches[0];
touchOrigin = {
  x: touch.pageX,
  y: touch.pageY
};

We can now add a touchmove event listener to the document to determine the drag direction based on this touchOrigin:

document.addEventListener('touchmove', determineDragDirection);

Our determineDragDirection function is going to measure the next touch location, check it has actually moved and, if so, measure the angle to determine whether it’s vertical or horizontal:

function determineDragDirection(e) {
  const touch = e.changedTouches[0];
  const touchLocation = {
    x: touch.pageX,
    y: touch.pageY
  };
}

Popmotion includes some helpful calculators for measuring things like the distance between two x/y coordinates. We can import those like this:

const { calc, css, value } = window.popmotion;

Then measuring the distance between the two points is a matter of using the distance calculator:

const distance = calc.distance(touchOrigin, touchLocation);

Now if the touch has moved, we can unset this event listener.

if (!distance) return;
document.removeEventListener('touchmove', determineDragDirection);

Measure the angle between the two points with the angle calculator:

const angle = calc.angle(touchOrigin, touchLocation);

We can use this to determine whether this angle is a horizontal or vertical angle, by passing it to the following function. Add this function to the very top of our file:

function angleIsVertical(angle) {
  const isUp = (
    angle <= -90 + 45 &&
    angle >= -90 - 45
  );
  const isDown = (
    angle <= 90 + 45 &&
    angle >= 90 - 45
  );

  return (isUp || isDown);
}

This function returns true if the provided angle is within -90 +/- 45 degrees (straight up) or 90 +/-45 degrees (straight down.) So we can add another return clause if this function returns true.

if (angleIsVertical(angle)) return;

Pointer Tracking

Now we know the user is trying to scroll the carousel, we can begin tracking their finger. Popmotion offers a pointer action that will output the x/y coordinates of a mouse or touch pointer.

First, import pointer:

const { calc, css, pointer, value } = window.popmotion;

To track the touch input, provide the originating event to pointer:

action = pointer(e).start();

We want to measure the initial x position of our pointer and apply any movement to the slider. For that, we can use a transformer called applyOffset.

Transformers are pure functions that take a value, and return it—yes—transformed. For instance: const double = (v) => v * 2.

const { calc, css, pointer, transform, value } = window.popmotion;
const { applyOffset } = transform;

applyOffset is a curried function. This means that when we call it, it creates a new function that can then be passed a value. We first call it with a number we want to measure the offset from, in this case the current value of action.x, and a number to apply that offset to. In this case, that’s our sliderX.

So our applyOffset function will look like this:

const applyPointerMovement = applyOffset(action.x.get(), sliderX.get());

We can now use this function in the pointer’s output callback to apply pointer movement to the slider.

action.output(({ x }) => slider.set(applyPointerMovement(x)));

Stopping, With Style

The carousel is now draggable by touch! You can test this by using device emulation in Chrome’s Developer Tools.

It feels a little janky, right? You may have encountered scrolling that feels like this before: You lift your finger, and the scrolling stops dead. Or the scrolling stops dead and then a little animation takes over to fake a continuation of the scrolling.

We’re not going to do that. We can use the physics action in Popmotion to take the true velocity of sliderX and apply friction to it over a duration of time.

First, add it to our ever-growing list of imports:

const { calc, css, physics, pointer, value } = window.popmotion;

Then, at the end of our stopTouchScroll function, add:

if (action) action.stop();

action = physics({
  from: sliderX.get(),
  velocity: sliderX.getVelocity(),
  friction: 0.2
})
  .output((v) => sliderX.set(v))
  .start();

Here, from and velocity are being set with the current value and velocity of sliderX. This ensures our physics simulation has the same initial starting conditions as the user’s dragging motion.

friction is being set as 0.2. Friction is set as a value from 0 to 1, with 0 being no friction at all and 1 being absolute friction. Try playing around with this value to see the change it makes to the “feeling” of the carousel when a user stops dragging.

Smaller numbers will make it feel lighter, and larger numbers will make movement heavier. For a scrolling motion, I feel 0.2 hits a nice balance between erratic and sluggish.

Boundaries

But there’s a problem! If you’ve been playing around with your new touch carousel, it’s obvious. We haven’t bounded movement, making it possible to literally throw your carousel away!

There’s another transformer for this job, clamp. This is also a curried function, meaning if we call it with a min and max value, say 0 and 1, it will return a new function. In this example, the new function will restrict any number given to it to between 0 and 1:

clamp(0, 1)(5); // returns 1

First, import clamp:

const { applyOffset, clamp } = transform;

We want to use this clamping function across our carousel, so add this line after we define minXOffset:

const clampXOffset = clamp(minXOffset, maxXOffset);

We’re going to amend the two output we’ve set on our actions using some light functional composition with the pipe transformer.

Pipe

When we call a function, we write it like this:

foo(0);

If we want to give the output of that function to another function, we might write that like this:

bar(foo(0));

This becomes slightly difficult to read, and it only gets worse as we add more and more functions.

With pipe, we can compose a new function out of foo and bar which we can reuse:

const foobar = pipe(foo, bar);
foobar(0);

It’s also written in a natural start -> finish order, which makes it easier to follow. We can use this to compose applyOffset and clamp into a single function. Import pipe:

const { applyOffset, clamp, pipe } = transform;

Replace the output callback of our pointer with:

pipe(
  ({ x }) => x,
  applyOffset(action.x.get(), sliderX.get()),
  clampXOffset,
  (v) => sliderX.set(v)
)

And replace the output callback of physics with:

pipe(clampXOffset, (v) => sliderX.set(v))

This kind of functional composition can quite neatly create descriptive, step-by-step processes out of smaller, reusable functions.

Now, when you drag and throw the carousel, it won’t budge outside of its boundaries.

The abrupt stop isn’t very satisfying. But that’s a problem for a later part!

Conclusion

That’s all for part 1. So far, we’ve taken a look at existing carousels to see the strengths and weaknesses of different approaches to scrolling. We’ve used Popmotion’s input tracking and physics to performantly animate our carousel’s translateX with touch scrolling. We’ve also been introduced to functional composition and curried functions.

You can grab a commented version of the “story so far” on this CodePen.

In upcoming installments, we’ll look at:

  • scrolling with a mouse wheel
  • remeasuring the carousel when the window resizes
  • pagination, with keyboard and mouse accessibility
  • delightful touches, with the help of spring physics

Look forward to seeing you there!

View Tutorial: Create the Perfect Carousel, Part 1

Quick Tip: How to Create a Denim Pattern in Adobe Photoshop

Final product image
What You’ll Be Creating

Realistic textures and patterns are easy to make in Photoshop. They’re perfect for text effects and help make shape layers stand out.

Want that denim look yourself? Learn how to make a denim pattern in this quick tip!

Get inspired with incredible patterns and more from Envato Market and Envato Elements.

1. How to Create a Denim Pattern in Photoshop

Step 1

Create a New Document at 850 x 850 pixels.

Here are all the colors I’ll be using for this effect:

  • Light Blue: 6279a4
  • Dark Blue: 42516e
  • Red: ff430e

Step 2

Set the Foreground Color to light blue and the Background Color a few shades
darker.

Set the foreground and background colors

Then create a New Layer and Fill it with that darker blue using the Paint Bucket Tool (G).

Fill layer

Step 3

Now go to Filter > Sketch > Halftone Pattern and set the Size to 3 and the Contrast to 5.

Halftone Pattern Filter

Step 4

Keep the filter window open and add a New Effect Layer. Then go to Artistic > Smudge Stick, and plug in these numbers:

  • Stroke Length: 2
  • Highlight Area: 2
  • Intensity: 10

Adding new effect layers like this can help you mix and match filters fast. Hit OK when you’re finished.

Artistic Smudge Stick Filter

Step 5

Again, add a New Effect Layer. Then go to Distort > Water Paper, and plug in these numbers:

  • Fiber Length: 8
  • Brightness: 55
  • Contrast: 81

Step 6

Create a New Layer and repeat the same steps as before, this time setting the Foreground Color to dark blue and the Background Color to white.

Fill the layer with the dark blue using the Paint Bucket Tool (G).

Then go to Filter > Sketch > Halftone Pattern and set the Size to 3 and the Contrast to 5.

Halftone Pattern

Step 7

Keep the filter window open and add a New Effect Layer. Then go to Artistic > Sponge, and plug in these numbers:

  • Brush Size: 7
  • Definition: 11
  • Smoothness: 1

Set the second layer with the new fiber texture to Multiply. Lower the Opacity to 75%.

Set fiber to Multiply

Step 8

Create a third New Layer, and follow the same steps as before, this time setting the Foreground Color to dark blue and the Background Color to bright red.

Repeat foreground background steps

Just like our previous steps, we’ll need to apply the Halftone Pattern filter first, followed by the Smudge Stick filter.

Halftone pattern settings

Step 9

Keep the filter window open and add a New Effect Layer. Then go to Artistic > Smudge Stick, and plug in these numbers:

  • Stroke Length: 2
  • Highlight Area: 3
  • Intensity: 10
Sponge Filter

Set this third layer to Divide, and lower the Opacity to 40%. Study jean reference images to understand the general makeup of its thread and fabric.

Set to Divide

Step 10

Create a New Adjustment Layer of Color Balance to correct the color scheme. Add the following values for the Shadows, Midtones, and Highlights.

Color balance adjustment

Merge all the layers together. Here’s the first denim pattern texture.

Denim Pattern Texture

2. How to Make Different Denim Colors

Step 1

For a few more color variations, try these quick steps.

Control-J the selected denim layer to create a Copy.

Duplicate the denim texture

Cycle through the different Layer Blend Modes to apply this copy to the original denim texture. Each mode will give you a slightly different denim color. Here I set the Blend Mode to Exclusion.

This second layer will help us create a more realistic denim finish.

Then Merge the two layers together.

Original denim vs new color
Here is a comparison of the original against the new color.

Continue to try out different Blend Modes so you can save a variety of denim colors.

Different Denim Colors

Step 2

When you’re through, select it with the Rectangular Marquee Tool (M), and then go to Edit > Define Pattern to use it in future projects. 

Access your saved patterns at any time with the Preset Manager.

Access Patterns with Preset Manager

3. How to Apply the Denim Pattern

Using this pattern is just as easy as making it! If you need a quick refresher on how to install Photoshop patterns, check out this video:

Test out your pattern with a cool shape by selecting the Custom Shape Tool (U). Try out different shapes to see your pattern in effect.

Just select the Pattern option from the dropdown menu and choose your new denim swatch (either of the last two swatches).

Apply the denim pattern

Show Us Your Results!

Remember, the best way to absorb this material is to try it out. Practice with different textures to perfect your custom patterns.

Most of the textures we find in our everyday lives can be replicated with design software. Experiment with Photoshop’s advanced filters, color adjustments, and more to improve your skills with time.

Check out these tutorials to learn more from design lovers like you!

Denim Texture Photoshop Tutorial
View Tutorial: Quick Tip: How to Create a Denim Pattern in Adobe Photoshop

Secure Coding With Concurrency in Swift 4

In my previous article about secure coding in Swift, I discussed basic security vulnerabilities in Swift
such as injection attacks. While injection attacks are common, there are other ways your app can be compromised. A common but sometimes-overlooked kind of vulnerability is race conditions. 

Swift 4
introduces Exclusive Access to Memory, which consists of a set of
rules to prevent the same area of memory being accessed at the same time.
For example, the inout argument in Swift tells a method that it can
change the value of the parameter inside the method.

func changeMe(_ x : inout MyObject, andChange y : inout MyObject)

But what happens if we pass in the same variable to change at the same time?

changeMe(&myObject, andChange:&myObject) // ???

Swift 4
has made improvements that prevent this from compiling. But while Swift can find these obvious scenarios at compile
time, it is difficult, especially for performance reasons, to find
memory access problems in concurrent code, and most of
the security vulnerabilities exist in the form of race conditions.

Race Conditions

As soon as you have more than one thread that needs to write to the same data at the same time, a race condition can occur. Race conditions cause data corruption. For these types of attacks, the vulnerabilities are usually more subtle—and the exploits more creative. For instance, there might be the ability to alter a shared resource to change the flow of security code happening on another thread, or in the case of authentication status, an attacker might be able to take advantage of a time gap between the time of check and the time of use of a flag.

The way to avoid race conditions is to synchronize the data. Synchronizing data usually means to “lock” it so that only one thread can access that part of the code at a time (said to be a mutex—for mutual exclusion). While you can do this explicitly using the NSLock class, there is potential to miss places where the code should have been synchronized. Keeping track of the locks and whether they are already locked or not can be difficult.

Grand Central Dispatch

Instead of using primitive locks, you can use Grand Central Dispatch (GCD)—Apple’s modern concurrency API designed for performance and security. You don’t need to think about the locks yourself; it does the work for you behind the scenes. 

DispatchQueue.global(qos: .background).async  //concurrent queue, shared by system
{
    //do long running work in the background here
    //...
    
    DispatchQueue.main.async //serial queue
    {
        //Update the UI - show the results back on the main thread
    }
}

As you can see, it’s quite a simple API, so use GCD as your first choice when designing your app for concurrency.

Swift’s runtime security checks cannot be performed across GCD threads because it creates a significant performance hit. The solution is to use the Thread Sanitizer tool if you are working with multiple threads. The Thread Sanitizer tool is great at finding problems you might never find by looking at the code yourself. It can be enabled by going to Product > Scheme > Edit Scheme > Diagnostics, and checking the Thread Sanitizer option.

If the design of your app makes you work with multiple threads, another way to protect yourself from the security issues of concurrency is to try to design your classes to be lock free so that no synchronization code is necessary in the first place. This requires some real thought about the design of your interface, and can even be considered a separate art in and of itself!

The Main Thread Checker

It is important to mention that data corruption can also occur if you do UI updates on any thread other than the main thread (any other thread is referred to as a background thread). 

Sometimes it’s not even obvious you are on a background thread. For example, NSURLSession‘s delegateQueue, when set to nil, will by default call back on a background thread. If you do UI updates or write to your data in that block, there is a good chance for race conditions. (Fix this by wrapping the UI updates in DispatchQueue.main.async {} or pass in OperationQueue.main as the delegate queue.) 

New in Xcode 9 and enabled by default is the Main Thread Checker (Product > Scheme > Edit Scheme > Diagnostics > Runtime API Checking > Main Thread Checker). If your code is not synchronized, issues will show up in the Runtime Issues on the left pane navigator of Xcode, so pay attention to it while testing your app. 

To code for security, any callbacks or completion handlers that you write should be documented whether they return on the main thread or not. Better yet, follow Apple’s newer API design which lets you pass a completionQueue in the method so you can clearly decide and see what thread the completion block returns on.

A Real-World Example

Enough talk! Let’s dive into an example.

class Transaction
{
    //...
}

class Transactions
{
    private var lastTransaction : Transaction?
    
    func addTransaction(_ source : Transaction)
    {
        //...
        lastTransaction = source
    }
}

//First thread
transactions.addTransaction(transaction)
        
//Second thread
transactions.addTransaction(transaction)

Here we have no synchronization, but more than one thread accesses the data at the same time. The good thing about Thread Sanitizer is that it will detect a case like this. The modern GCD way to fix this is to associate your data with a serial dispatch queue.

class Transactions
{
    private var lastTransaction : Transaction?
    private var queue = DispatchQueue(label: "com.myCompany.myApp.bankQueue")
    
    func addTransaction(_ source : Transaction)
    {
        queue.async
        {
            //...
            self.lastTransaction = source
        }
    }
}

Now the code is synchronized with the .async block. You might be wondering when to choose .async and when to use .sync. You can use .async when your app doesn’t need to wait until the operation inside the block is finished. It might be better explained with an example.

let queue = DispatchQueue(label: "com.myCompany.myApp.bankQueue")
var transactionIDs : [String] = ["00001", "00002"]
        
//First thread
queue.async
{
    transactionIDs.append("00003")
}
//not providing any output so don't need to wait for it to finish
        
//Another thread
queue.sync
{
    if transactionIDs.contains("00001") //...Need to wait here!
    {
        print("Transaction already completed")
    }
}

In this example, the thread that asks the transaction array if it contains a specific transaction provides output, so it needs to wait. The other thread doesn’t take any action after appending to the transaction array, so it doesn’t need to wait until the block is completed.

These sync and async blocks can be wrapped in methods that return your internal data, such as getter methods.

get
{
    return queue.sync { transactionID }
}

Scattering GCD blocks all over the areas of your code that access shared data is not a good practice as it is harder to keep track of all the places that need to be synchronized. It’s much better to try and keep all this functionality in one place. 

Good design using accessor methods is one way to solve this problem. Using getter and setter methods and only using these methods to access the data means that you can synchronize in one place. This avoids having to update many parts of your code if you are changing or refactoring the GCD area of your code.

Structs

While single stored properties can be synchronized in a class, changing properties on a struct will actually affect the entire struct. Swift 4 now includes protection for methods that mutate the structs. 

Let’s first look at what a struct corruption (called a “Swift access race”) looks like.

struct Transaction
{
    private var id : UInt32
    private var timestamp : Double
    //...
            
    mutating func begin()
    {
        id = arc4random_uniform(101) // 0 - 100
        //...
    }
            
    mutating func finish()
    {
        //...
        timestamp = NSDate().timeIntervalSince1970
    }
}

The two methods in the example change the stored properties, so they are marked mutating. Lets say thread 1 calls begin() and thread 2 calls finish(). Even if begin() only changes id and finish() only changes timestamp, it’s still an access race. While normally it’s better to lock inside accessor methods, this doesn’t apply to structs as the entire struct needs to be exclusive. 

One solution is to change the struct to a class when implementing your concurrent code. If you needed the struct for some reason, you could, in this example, create a Bank class which stores Transaction structs. Then the callers of the structs inside the class can be synchronized. 

Here is an example:

class Bank
{
    private var currentTransaction : Transaction?
    private var queue : DispatchQueue = DispatchQueue(label: "com.myCompany.myApp.bankQueue")
    func doTransaction()
    {
        queue.sync
        {
                currentTransaction?.begin()
                //...
        }
    }
}

Access Control

It would be pointless to have all this protection when your interface exposes a mutating object or an UnsafeMutablePointer to the shared data, because now any user of your class can do whatever they want with the data without the protection of GCD. Instead, return copies to the data in the getter. Careful interface design and data encapsulation are important, especially when designing concurrent programs, to make sure that the shared data is really protected.

Make
sure the synchronized variables are marked
private, as opposed to open or public, which would allow members
from any source file to access it. One
interesting change in Swift 4 is that the
private access level scope is expanded to
be available in extensions.
Previously it could only be
used within the enclosing declaration, but in Swift 4, a private variable can be
accessed in an extension,
as long as the extension
of that declaration is in the same source file.

Not only are variables at risk for data corruption but files as well. Use the FileManager Foundation class, which is thread-safe, and check the result flags of its file operations before continuing in your code.

Interfacing With Objective-C

Many Objective-C objects have a mutable counterpart depicted by their
title. NSString‘s mutable version is named NSMutableString, NSArray‘s is
NSMutableArray, and so on. Besides the fact that
these objects can be mutated outside of synchronization, pointer
types coming from Objective-C also subvert Swift optionals. There is
a good chance that you could be expecting an object in Swift, but from
Objective-C it is returned as nil. 

If the app crashes, it gives valuable insight into the internal logic. In this case, it could be that user input was not properly checked and that area of the app flow is worth looking at to try and exploit.

The
solution here is to update your Objective-C code to include
nullability annotations. We can take a slight diversion here as this advice applies to safe interoperability in general, whether between Swift and Objective-C or between two other programming languages. 

Preface your Objective-C
variables with nullable when nil
can be returned, and nonnull when it shouldn’t.

- (nonnull NSString *)myStringFromString:(nullable NSString *)string;

You can also add nullable
and nonnull to the attribute list of Objective-C properties.

@property (nullable, atomic, strong) NSDate *date;

The
Static Analyzer tool in Xcode has always been great for finding
Objective-C bugs. Now with nullability annotations, in Xcode 9 you can use the Static Analyzer on your
Objective-C code
and it will find nullability
inconsistencies in your file. Do this by navigating to
Product > Perform Action > Analyze.

While it’s enabled by default, you can also control the nullability checks in
LLVM with -Wnullability* flags.

Nullability
checks are good for finding issues at compile time, but they don’t
find runtime issues. For example, sometimes we assume in a part of
our code that an optional value will always exist and use the force
unwrap ! on it. This is an implicitly unwrapped optional, but there is really no guarantee that it will always exist. After all, if it
were marked optional, it’s likely to be nil at some point. Therefore,
it’s a good idea to avoid force unwrapping with !. Instead, an elegant
solution is to check at runtime like so:

guard let dog = animal.dog() else
{
    //handle this case
    return
}
//continue...

To further help you out, there
is a new feature added in Xcode 9 to perform nullability checks at runtime.
It is part of the Undefined Behavior Sanitizer, and while it’s not enabled
by default, you can enable it by going to Build Settings >
Undefined Behavior Sanitizer
and setting Yes for Enable Nullability
Annotation Checks
.

Readability

It’s good practice to write your methods with only one entry and one exit point. Not only is this good for readability, but also for advanced multithreading support. 

Let’s say a class was designed without concurrency in mind. Later the requirements changed so that it must now support the .lock() and .unlock() methods of NSLock. When it comes time to place locks around parts of your code, you may need to rewrite a lot of your methods just to be thread-safe. It’s easy to miss a return hidden in the middle of a method that was later supposed to lock your NSLock instance, which can then cause a race condition. Also, statements such as return will not automatically unlock the lock. Another part of your code that assumes the lock is unlocked and tries to lock again will deadlock the app (the app will freeze and eventually be terminated by the system). Crashes can also be security vulnerabilities in multithreaded code if temporary work files are never cleaned up before the thread terminates. If your code has this structure:

if x
    if y
		return true
	else
		return false
...
return false

You can instead store the Boolean, update it along the way and then return it at the end of the method. Then synchronization code can easily be wrapped in the method without much work.

var success = false
// <--- lock
if x
    if y
		success = true
...
// < --- unlock
return success

The .unlock() method must be called from the same thread that called .lock(),  otherwise it results in
undefined behavior.

Testing

Often, finding and fixing vulnerabilities in concurrent code comes down to
bug hunting. When you find a bug, it’s like holding a mirror up to
yourself—a great learning opportunity. If you
forgot to synchronize in one place, it’s likely that the same mistake
is elsewhere in the code. Taking the time to check the rest of your
code for the same mistake when you encounter a bug is a very
efficient way of preventing security vulnerabilities that would keep
appearing over and over again in future app releases. 

In fact, many of
the recent iOS jailbreaks have been because of repeated coding
mistakes found in Apple’s IOKit. Once you know the developer’s style, you can check other parts of the code for similar bugs.

Bug finding is good motivation for code
reuse. Knowing that you fixed a problem in one place and don’t have to go
find all the same occurrences in copy/paste code can be a big relief.

Race
conditions can be complicated to find during testing because memory might have to be
corrupted in just the “right way” in order to see the problem, and sometimes the problems appear a long time later in the app’s execution. 

When you are testing,
cover all your code. Go through each flow and case and test each line
of code at least once. Sometimes it helps to input random data (fuzzing the inputs), or choose extreme values in hopes of finding an edge case that would not be
obvious from looking at the code or using the app in a normal way. This, along with the new Xcode tools available, can go a long way towards preventing
security vulnerabilities. While no code is 100% secure, following
a routine, such as early-on functional tests, unit tests, system
test, stress and regression tests, will really pay off.

Beyond debugging your app, one thing that is different for the release configuration (the
configuration for apps
published on the store) is that code optimizations are included. For
example, what the compiler thinks is an unused operation can get optimized out, or a variable may not stick
around longer than necessary in a concurrent block. For your published
app, your code is actually changed, or different from the one that you
tested. This means that bugs can be
introduced that only exist once you release your app. 

If you are not
using a test configuration, make sure you test your app on release mode
by
navigating to Product > Scheme > Edit Scheme. Select Run from
the list on the left, and in the Info pane on the right, change Build
Configuration
to Release. While it’s good to cover your entire app in
this mode, know that because of optimizations, the breakpoints and
the debugger will not behave as expected. For example,
variable descriptions might not be available even though the code is
executing correctly.

Conclusion

In this post, we looked at race conditions and how to avoid them by coding securely and using tools like the Thread Sanitizer. We also talked about Exclusive
Access to Memory, which is a great addition to Swift 4. Make sure it’s set
to Full Enforcement in Build Settings > Exclusive
Access to Memory

Remember that these enforcements are only on for debug
mode, and if you are still using Swift 3.2, many of the
enforcements discussed come in the form of warnings only. So take the warnings seriously, or
better yet, make use of all the new features available by adopting Swift 4 today!

And while you’re here, check out some of my other posts on secure coding for iOS and Swift!

View Tutorial: Secure Coding With Concurrency in Swift 4

How to Manage Multiple Applications in CodeIgniter

Today, we’re going to explore how you can manage multiple applications in the CodeIgniter web framework using a single codebase. In the course of that, we’ll go ahead and create two different CodeIgniter applications that will share the core CodeIgniter codebase.

Sharing the core codebase across different applications is not something new as it’s already practiced by different frameworks and open-source systems, and CodeIgniter is no different. It easily allows you to manage multiple applications that share the core CodeIgniter library and API files, and at the same time you could use different databases and site-specific configurations.

To start with, we’ll go through the benefits of the multisite setup, and as we move on we’ll go through a practical demonstration of what it takes to set up multiple applications in the CodeIgniter framework.

Benefits of the Multisite Setup

In this section, we’ll highlight a couple of benefits of having a multisite setup.

One of the most obvious benefits that I could straightaway point out is that the multisite setup shares a common codebase, and that should make the upgrade and maintenance processes of your application much easier.

For example, let’s imagine that you have ten different CodeIgniter applications running under your belt. And you just came to know that a new version of the CodeIgniter framework is available for upgrade and you would like to upgrade it as soon as possible to make sure that the code remains secure and stable.

If you had a separate codebase for each of your applications, it would definitely be a tedious process to go through each and every site and upgrade it in turn. With the multisite setup, you just need to do it once as the core codebase is shared across all the sites!

Next, it allows you use a different database for each application even though they share a common codebase. In fact, it’s one of the most popular use cases of setting up multisite!

Apart from using a different database for each application, you could create a setup that uses the same database but a different theme or layout in the front-end.

If you are still using the FTP-based approach to move your site files across the different servers, I would say you’re going to love the multisite approach as it minimizes your work to a great extent!

How to Create Multiple Applications

In this section, we’ll set up the basic directory structure in order to implement a multisite setup.

At the root of your CodeIgniter application, create an applications directory. This is the main directory that will hold our different applications.

Next, go ahead and create two new directories—applications/app_one and applications/app_two. Of course, you could name it the way you want it to be, but I’ll keep things simple for now.

So, as you can see, we’re going to set up two different applications that will use the single codebase of the CodeIgniter framework. Although the multisite setup will reuse most of the CodeIgniter framework files, we still need to duplicate a couple of files and directories to each and every application we create.

Let me quickly list the files and directories that you should copy from the default application in the first place.

Copy the following directories from the default application directory to applications/app_one and applications/app_two:

  • cache
  • config
  • logs

As you can see, it’s obvious to have separate directories for cache and logs for each application. And the config directory is a must have for the working of your CodeIgniter application, so we are going to copy it anyway.

Next, let’s copy a couple of files along with the necessary directories that allow us to test our multisite application.

Copy the following files to our app_one and app_two applications from the default CodeIgniter application:

  • controllers/welcome.php
  • views/errors
  • views/welcome_message.php

For your quick reference, the controllers/welcome.php file should look like:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller { 

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *         http://example.com/index.php/welcome
     *    - or -
     *         http://example.com/index.php/welcome/index
     *    - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {
        $this->load->view('welcome_message');
    }
}

And the views/welcome_message.php file should look like.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Welcome to CodeIgniter</title>

    <style type="text/css">

    ::selection { background-color: #E13300; color: white; }
    ::-moz-selection { background-color: #E13300; color: white; }

    body {
        background-color: #fff;
        margin: 40px;
        font: 13px/20px normal Helvetica, Arial, sans-serif;
        color: #4F5155;
    }

    a {
        color: #003399;
        background-color: transparent;
        font-weight: normal;
    }

    h1 {
        color: #444;
        background-color: transparent;
        border-bottom: 1px solid #D0D0D0;
        font-size: 19px;
        font-weight: normal;
        margin: 0 0 14px 0;
        padding: 14px 15px 10px 15px;
    }

    code {
        font-family: Consolas, Monaco, Courier New, Courier, monospace;
        font-size: 12px;
        background-color: #f9f9f9;
        border: 1px solid #D0D0D0;
        color: #002166;
        display: block;
        margin: 14px 0 14px 0;
        padding: 12px 10px 12px 10px;
    }

    #body {
        margin: 0 15px 0 15px;
    }

    p.footer {
        text-align: right;
        font-size: 11px;
        border-top: 1px solid #D0D0D0;
        line-height: 32px;
        padding: 0 10px 0 10px;
        margin: 20px 0 0 0;
    }

    #container {
        margin: 10px;
        border: 1px solid #D0D0D0;
        box-shadow: 0 0 8px #D0D0D0;
    }
    </style>
</head>
<body>

<div id="container">
    <h1>Welcome to CodeIgniter! You're browsing Application One!</h1>

    <div id="body">
        <p>The page you are looking at is being generated dynamically by CodeIgniter.</p>

        <p>If you would like to edit this page you'll find it located at:</p>
        <code>application/views/welcome_message.php</code>

        <p>The corresponding controller for this page is found at:</p>
        <code>application/controllers/Welcome.php</code>

        <p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
    </div>

    <p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo  (ENVIRONMENT === 'development') ?  'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>
</div>

</body>
</html>

Of course, you should change the following message in the view file so that we could differentiate the application during the testing.

For applications/app_one/views/welcome_message.php, it should look like:

<h1>Welcome to CodeIgniter! You're browsing Application One!</h1>

And for applications/app_two/views/welcome_message.php, it should look like:

<h1>Welcome to CodeIgniter! You're browsing Application Two!</h1>

Now, we have everything done as far as our multisite setup is concerned. However, it won’t work out of the box yet as we still need to inform CodeIgniter about our multisite setup since it always loads the default application located in the application directory.

Finishing Touches

Let’s have a quick look at the setting that configures the default application directory. Go ahead and open the index.php file at the root of your application and look for the following code snippet.

/*
 *---------------------------------------------------------------
 * APPLICATION DIRECTORY NAME
 *---------------------------------------------------------------
 *
 * If you want this front controller to use a different "application"
 * directory than the default one you can set its name here. The directory
 * can also be renamed or relocated anywhere on your server. If you do,
 * use an absolute (full) server path.
 * For more info please see the user guide:
 *
 * https://codeigniter.com/user_guide/general/managing_apps.html
 *
 * NO TRAILING SLASH!
 */
$application_folder = 'application';

It’s pretty clear from the above snippet that it allows you to set the path of your default application. So this is the place where we can make changes so that it picks up the default application from a directory other than the default one.

Of course, you could go ahead and straight away do something like this, and that should run the app_one application.

$application_folder = 'applications/app_one';

On the other hand, what would you do if you want to run app_two? As a quickie, you could copy the index.php file to index_app_one.php and index_app_two.php for each application. In your virtual host, make sure that you make the changes accordingly.

On the other hand, I prefer a slightly different approach, and I would like to rely on the ENV variable to choose between the different applications at run time.

For example, you can set up the custom ENV variable in NGINX as shown in the following snippet.

// set the env variable CI_DEFAULT_APP in the "location" directive of vhost
fastcgi_param  CI_DEFAULT_APP  applications/app_one;

If you’re using the Apache web server, the same could be achieved with:

SetEnv CI_DEFAULT_APP applications/app_one

Next, let’s revise the code in the index.php file that takes advantage of the ENV variable to decide the default application to run.

...
...
$application_folder = (isset($_SERVER['CI_DEFAULT_APP']) ? $_SERVER['CI_DEFAULT_APP'] : 'application');
...
...

So, as you can see, we check the existence of the CI_DEFAULT_APP ENV variable in the first place, and if it’s not available then we’ll fall back to the default application.

More often than not, you want to run your different applications on different domains. Ideally, I would like to use two different virtual hosts for each application. A quick example of each virtual host should look something like this in the context of NGINX.

The www.ci-app-one.com domain points to app_one:

server {
  listen {YOUR_IP}:80;
  server_name  www.ci-app-one.com;
  root   /var/www/html;
  index index.html index.php;

  location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
    access_log off;
    expires max;
  }

  location / {
     # Check if a file or directory index file exists, else route it to index.php.
     try_files $uri $uri/ /index.php;
  }

  location ~ \.php$ {
    root   /var/www/html;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
    fastcgi_param  CI_DEFAULT_APP  applications/app_one;
    include fastcgi_params;
  }
}

Similarly, the www.ci-app-two.com domain points to app_two:

server {
  listen {YOUR_IP}:80;
  server_name  www.ci-app-two.com;
  root   /var/www/html;
  index index.html index.php;

  location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
    access_log off;
    expires max;
  }

  location / {
     # Check if a file or directory index file exists, else route it to index.php.
     try_files $uri $uri/ /index.php;
  }

  location ~ \.php$ {
    root   /var/www/html;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
    fastcgi_param  CI_DEFAULT_APP  applications/app_two;
    include fastcgi_params;
  }
}

Of course, you could go ahead now and test your changes to see if it really works or not! Don’t hesitate to shoot me any queries if you face any issues.

And that was the pretty simple way in which you can set up multiple applications in the CodeIgniter framework using a single codebase.

Conclusion

Today, we went through an interesting aspect of the CodeIgniter framework that allows you to manage multiple applications using a single codebase. The obvious benefits of that are easy upgrading and maintenance of your existing codebase.

CodeIgniter is a powerful PHP platform. Whether or not you’re just getting started or you’re starting with the next version, don’t forget to check out what we have available for you, as well.

Share your thoughts if you’ve already implemented something similar or you would have approached it in a slightly different way. Either way, I would love to hear your thoughts!

View Tutorial: How to Manage Multiple Applications in CodeIgniter

How to Create a Space Illustration Using Omber

Final product image
What You’ll Be Creating

If you love gazing into the depths of outer space as much as I do, then buckle in since today we’re going to learn how to create a detailed space illustration with the new Omber software from Wobastic.

Compared to some of the other solutions out there, Omber gives you the possibility of using either an online version or a downloadable one—which is something that I think more developers should be doing—and it’s being distributed completely free of charge.

So whether you decide to go online or local, bring up the software and let’s get started! 

1. How to Set Up a New Project File

As always, let’s
start by setting up a new document. Head over to Options > Page Setup and adjust it as follows:

  • Width: 800
    px
  • Height:
    600 px

Since we want to
be able to see the actual page, be sure to check show page outline and set the Background
Color
to white so that we can have a better view of the shapes that we’ll
be creating.

setting up a new document

2. How to Set Up a Custom Grid

When it comes to grids, the software gives you the option of setting up and using a custom one,
which I really recommend you do, since we want the illustration to be based
on a pixel-perfect workflow.

To do this, simply
go to Options > Grid and instruct
it to use a gridline every 1 pixels,
making sure to enable the snap to grid
option so that the shapes will move using a 1 px increment no matter the direction in which you push them.

setting up a custom grid

3. How to Enable
High-Quality Rendering

When you start a new project, you should always make sure that the HQ Rendering option is turned on, otherwise you might notice that the shapes that you’ve just created are a little bit choppy.

shape created without hq rendering

If this happens, don’t worry and keep calm,
since this is due to the rendering engine that needs to be enabled by going
over to Options > HQ Rendering.
Once you turn it on, all your old and new shapes will instantly become smooth, as you can see for yourself from the reference example.

enabling hq rendering

Before we move on
and start working on the actual illustration, I wanted to point out that most
of the options that we’ve set up until this point will automatically return to their defaults once you close
the software, so remember to go over them each and every time you start working
on a new project.

4. How to Create
the Background

As soon as we’ve finished setting up our new document, we’re going to
kick things off by drawing the wobbly background, so take a quick sip of that hot coffee and let’s get started!

Step 1

Start by working on the larger section, by going over to Shape and then selecting Solid from the top toolbar in order to
create an object with a solid fill. Set the color to purple (#82147f), and then
use the Curve tool to draw a shape
similar to the one from the reference image. Don’t worry if it ends up looking
weird, since we’re going to fine-tune it in the following moments.

drawing the main background section

Step 2

Adjust the shape that we’ve just created by going over to Edit Points and then carefully repositioning
the anchor points and their handles as seen in the reference image.

Depending
on the shape that you’ve drawn, you can add new anchor points using the Add tool, by simply clicking on the
path, or remove the ones you don’t need by clicking on their little square using
the Delete tool.

Take your time, and once you’re done, position
the resulting shape in the center of the underlying page.

adjusting the main background shape

Step 3

This next step is really one of my favorites,
since it demonstrates the amazing capabilities of the software’s gradient
engine. If you’re used to radial or linear gradients, Omber takes
things to a completely new level. It allows you to select any of its
composing anchor points and assign it a different color in order to create an
intricate gradient. 

In my case, I went with a couple of purple tints and shades
as well as orange ones, which gave me a nice smooth, space-like background that
you can see below.

adding the gradient to the main background shape

Step 4

Once you’ve finished working on the larger section, take a couple of
moments and draw the smaller one using the same process as before. Adjust the
resulting shape’s anchor points using the Edit
Points
tool, and then apply a smooth gradient using orange for its left
anchor points and purple for its right ones.

drawing the smaller background shape

Step 5

Next, draw the left gas swirl using white (#FFFFFF) as your fill color, positioning
the resulting shape on the left side of the larger background section.

drawing the left gas section

Step 6

Since we want the shape to be transparent and act as a background
overlay, we’ll have to bring up the Info
panel (Options > Info) and then, using the Edit Points tool, individually select and adjust the Transparency
of each of its composing anchor points.

adjusting the transparency of the left gas section

Step 7

Once you’ve finished working on the left gas section, create the right
one using the same process.

drawing the right gas section

Step 8

Start working on the little background stars by zooming in on the page using the scroll wheel, and then
creating a 6 x 6 px circle with the
color set to a light beige (#F8DBBB), which we will position on the left side
of the larger background section.

adding the first background star

Step 9

Add the remaining stars using some copies, which we will make by
selecting the circle that we’ve just created and then using the Duplicate function found within the top
toolbar. Move around the page by holding down the Space Bar, and then gradually create and reposition the copies until
you’ve populated the background, making sure to leave the center section empty.
Once you’re done, make sure to select and group all of the stars together using the Group
function.

adding the remaining stars to the background

Step 10

Start working on the right comet by drawing its main body (#FFFFFF) using
the Straight line tool. Simply
click on the page to create the start and end points, and then end the line using the End Line function.

drawing the right comet

Step 11

Adjust the line segment that we’ve just created by setting its width to
2 px from within the Info panel (Options > Info > width), setting the color of its left anchor
point to white (#FFFFFF) and its right one to yellow (#FCD85C).

coloring the right comet

Step 12

Select the comet’s right anchor point using the Edit Points tool, and then lower its transparency all the way down to 100% to give it the illusion of movement.

adjusting the transparency of the right comet

Step 13

Create the left comet using a copy (Select
> Duplicate
) of the one that we’ve just finished adjusting, which we
will vertically reflect by selecting the center-right square of its bounding
box and dragging it all the way to the left side until the anchor points swap
places. 

Then repeat the same process, only this time reflect it horizontally, adjusting
its length and then positioning the resulting shape on the opposite side of
the background.

adding the left comet

Step 14

Since we’re pretty much done working on the background, we can select
all its shapes (Control-A)
and group them together (Select >
Group
), before moving on to the next section of our illustration.

grouping the shapes of the background

5. How to Create
the Main Planet

Once we’ve
finished working on the background, we can move on to the center section of the
illustration, where we will gradually create the larger yellow planet.

Step 1

Start by creating the larger outer glow section using a 240 x 240 px yellow circle (#FCD85C), which we will horizontally center align to the
underlying page. To do this, we’re going to do some simple math and remove the width of the planet from that of the
document, and then divide the resulting number by 2 in order to find the X
coordinate. 

So (800 px – 240 px)/2=280 px, which is the value that the X coordinate needs to show in order for
the shape to be perfectly horizontally centered. When it comes to the vertical
alignment, I’ve done the same math (600
px – 240 px)/2=180 px
, but I’ve ended up pushing the shape to the bottom by
an additional 20 px in order for it
to fit inside the background.

creating the larger outer glow

Step 2

Adjust the transparency of the shape that we’ve just created, by setting
its left and top anchor points to 70% and its bottom and right ones to 0%.

adjusting the transparency of the larger outer glow

Step 3

Create the smaller
outer glow using a copy of the resulting shape (Select > Duplicate), which we will resize by selecting the
top-right square of its bounding box and dragging it to the opposite corner,
until you have a 220 x 220 px circle.
Then, center align it to the larger one using the X and Y coordinates.

  • x: (800 px – 220 px)/2=290 px
  • y: (600 px – 220
    px)/2=190 px
    (from which we will remove the additional 20 px)
adding the smaller outer glow

Step 4

Add the main shape
for the actual planet using a 200 x 200
px
yellow circle (#FCD85C), which we will position using the following
coordinates:

  • x: (800 px – 200 px)/2=300 px
  • y: (600 px – 200
    px)/2=200 px
    (from which we will remove the additional 20 px)
creating the main shape for the yellow planet

Step 5

Give the planet a smooth gradient by selecting its bottom and right
anchor points using the Edit Points
tool while holding down the Shift
button to do a multiple selection, and then setting their color to a darker yellow
(#F5A941).

adding the gradient to the yellow planet

Step 6

Start adding details to the planet by creating the larger crater using
a 60 x 40 px ellipse made with the Oval tool, which we will color using a
darker yellow (#F5A941) and then position on its lower-right side.

creating the main shape for the larger crater

Step 7

Give the crater some depth by selecting its bottom and right anchor
points using the Edit Points tool,
and then setting their color to a lighter yellow using the Eye Dropper tool (simply make a quick selection from the left
side of the planet’s larger body).

adding a gradient to the larger crater

Step 8

Create the smaller crater using a duplicate (Select > Duplicate) of the one that we’ve just finished working
on, which we will resize by dragging its bounding box until we have a 30 x 20 px oval. Once you’re done,
position the shape on the lower-left side of the planet, selecting and
grouping all its shapes together using the Group function (Select >
Group
).

adding the smaller crater

6. How to Create
the Background Planet

Next on our interstellar
list is the smaller background planet, which will give some balance to our
composition.

Step 1

Start by creating the belt using a 94
x 40 px Oval
with a 2 px line
width, which we will color using a light blue (#2DA3AF) and then position on the right side of the larger planet.

creating the belt for the background planet

Step 2

Apply a gradient to the belt by selecting each of its anchor points
using the Edit Points tool, and then
adding darker color values as you go round its back section. Since we want
the ellipse to fade towards the rear, we’ll have to add a darker anchor
point and lower the Transparency of
its back anchors to 50% and 34%.

adding a gradient to the belt

Step 3

Create the planet’s main body using a 48 x 48 px circle, which we will color using a light blue
(#31ABB8) and then position over the belt. As long as you have the grid up and running, you should
be able to do it by simply dragging the shape around.

creating the main shape for the background planet

Step 4

Finish off the planet by creating a nice smooth gradient, making the
right side darker in order to give it some depth. Take your time, and once you’re
done, select and group the two shapes together (Select > Group) before moving on to the next section of the
illustration.

adding the gradient to the background planet

7. How to Create
the Satellite

We are now down to
the last section of our illustration, so without wasting more time, let’s get
ready to wrap things up.

Step 1

Create the satellite’s main body using an 8 x 16 px rectangle, which we will color using a light grey
(#DEF0F6) and then position on the left side of the larger crater.

creating the main body for the satellite

Step 2

Create the top and bottom sections using two 4 x 4 px squares (#62808A), which we will position as seen in the
reference image.

adding the top and bottom sections to the satellite

Step 3

Add the two rectangular details to the larger
body using a 4 x 8 px rectangle (#62808A) followed by a smaller 4 x 2 px one (#62808A), which we will space 2 px vertically from one another, positioning them
in the center afterwards. Once you’re done, select and group all five shapes
together (Select > Group), before moving on to the next section.

adding details to the body of the satellite

Step 4

Start working on the antenna assembly by
creating the neck section using a 2 x 4
px
rectangle (#DEF0F6), which we will position on top of the
satellite’s upper section.

adding the neck section for the antenna assembly

Step 5

Add the antenna assembly using a 10 x 10 px circle (#62808A), on top of
which we will add a smaller 6 x 6 px one
(#DEF0F6), followed by a 2 x 2 px one (#62808A). As we did with the previous section, make sure to select and
group all four shapes together using the Select
> Group
function.

adding the antenna to the satellite

Step 6

Start working on the left solar wing by
creating the two arms using a 4 x 2 px rectangle
(#62808A1 px above a thinner 4 x 1 px one
(#62808A), which we will position as seen in the reference image.

adding the arms for the left solar wing

Step 7

Create the main shape for the wing using a 15 x 12 px rectangle, which we will
color using a light grey (#DEF0F6) and then position on the left side
of the extending arms.

adding the main shape for the left solar wing

Step 8

Add the solar cells using four 2 x 8 px rectangles, horizontally
spaced 1 px from one another (#62808A),
which we will position in the center of the wing. Once you’re done, select and
group all of the current section’s shapes (Select > Group) before moving on to the next step.

adding the solar cells to the wing

Step 9

Finish off the satellite by adding the right
wing using a copy (Select > Duplicate)
of the one that we’ve just finished working on, which we will
vertically reflect and then position on the opposite side of the larger body.
Once you’re done, select and group all of the satellite’s shapes (Select > Group) before moving on to
the last step.

adding the right solar wing

Step 10

Finish off the
illustration by adding the subtle shadow cast by the satellite onto the
planet, using a copy of it (Select >
Duplicate
), which we will color using a dark yellow (#EEA822). Adjust the
transparency of the shadow’s shapes by entering their respective
group using the Enter Group option,
and then selecting and lowering some of their anchor points’ (Select > Edit Points).

Then, move the duplicate a few pixels towards the bottom-right corner, making
sure to position it underneath the satellite using the Backward One function (Select
> Backward One
). Once you’re done, select and group the satellite and
its shadow together (Select > Group),
doing the same for the entire illustration before hitting that save button.

finishing off the illustration

It’s a Wrap!

Using some clicks here and there and a few shapes, we’ve managed to create a pretty detailed and vivid space illustration that you can use in any personal project. 

As always, I really hope you’ve managed to follow each and every step and, most importantly, learned something new and useful along the way.

finished project preview
View Tutorial: How to Create a Space Illustration Using Omber

New Course: Introduction to Figma

Have you heard about Figma? It’s a powerful interface design tool that it runs in the browser and includes some awesome collaboration features.

In our new course, Introduction to Figma, you’ll learn the basics of working with Figma, from both a designer’s and a developer’s point of view. Adi Purdila will teach you about designing, prototyping, collaborating, exporting, and more.

Designing in Figma

You can take our new course straight away with a subscription to Envato Elements. For a single low monthly fee, you get access not only to this course, but also to our growing library of over 1,000 video courses and industry-leading eBooks on Envato Tuts+. 

Plus you now get unlimited downloads from the huge Envato Elements library of 400,000+ creative assets. Create with unique fonts, photos, graphics and templates, and deliver better projects faster.

 
View Tutorial: New Course: Introduction to Figma

Create a Vivid Winter Aurora Landscape

In this tutorial I’ll show you how to create a winter night landscape featuring a northern sky. You will learn how to combine different stocks together and blend them correctly to make a cohesive scene. You’ll also learn how to create lighting effect, work with group and more. Preview of Final Results Tutorial Resources Stars […]

The post Create a Vivid Winter Aurora Landscape appeared first on Photoshop Tutorials.

View Tutorial: Create a Vivid Winter Aurora Landscape