Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 673

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 62k
Author
Asked: November 25, 20242024-11-25T01:04:09+00:00 2024-11-25T01:04:09+00:00

Creating a Word Art text-curving design picker in only 30 lines of pure HTML web component code + 1 extra file (no node or JS!)

  • 62k

Hey all — as I'm back to Modulo.js tutorial writing, I am always looking for more content ideas. Have an idea? Be sure to let me know in the comments!

Previously, I showed how to use the -store= processor to make a reactive shared State store between components, a deep dive into Modulo's Markdown-HTML file format, or, last week, how to make a circular text-art tool. Today, let's make another SVG text design tool, except using <path> instead of <circle>. While slightly more complex, using <path> elements for Text allows for fun and arbitrary text arrangements — and, most importantly, is supported by Chrome!

The final result

Screenshot showing range sliders allowing to adjust the alignment of Modulo Text FX letters, currently aligned to cause them to spill into a wave-like pattern

Try it out now, in less than 30 seconds: 🚀🚀🚀 Want to skip ahead? Scroll to the end and copy the ~30 lines of HTML code into any local HTML file, and then open it in your browser. Modulo has no dependencies and even runs embedded in local HTML files, so it's really that easy!


Starting with SVG and text input

Let's add an SVG along with a text input, bound to the text. Let's use a <Template> and a <State> component parts, as follows:

<Template>   <section>     <p><input [state.bind] name="text" title="Text" maxlength="15" /></p>   </section>   <svg viewBox="0 0 200 100" style="width: 55%; margin-top: 100px">       <path id="curve" fill="transparent" d="M 10,50 C 20,40 40,10 60,40 80,70 100,65 120,90" />       <text><textPath href="#curve">{{ state.text }}</textPath></text>   </svg> </Template> <State     text="Modulo Text FX!" ></State> 
Enter fullscreen mode Exit fullscreen mode

In this snippet, we have a <input> element that's bound to State using [state.bind]. If the State concept is giving you conceptual trouble, consider warming up with this tutorial on creating a font design tool, or the the corresponding section in the interactive Modulo tutorial. If SVG <textPath> elements are confusing you, check out MDN's documentation. After that, we have an <svg> element, containing <path> and <textPath> elements. These are linked together with id="curve", and href="#curve" respectively. The {{ state.text }} links the state to the <textPath> — also in previous tutorial. But unlike the previous tutorial, we'll use a <path> element that takes a d= attribute, which consist of a series of x,y coordinate points for each point (dot) on the curve itself (documented here).

Okay, I realize that's dense code, but bare with me — it's only a few more steps to get the tool working!

Moving the points to State

We currently only have state.text. We need to also store the points themselves, so we can adjust them with sliders. Let's move to state the Array of points:

<State     text="Modulo Text FX!"     points:='[ [ 20,40 ], [40,10], [60,40], [80,70], [100,65], [120,90] ]' ></State> 
Enter fullscreen mode Exit fullscreen mode

The :='[ and ]' syntax is the syntax for creating Arrays in Modulo: If this concept is new to you, consider reading the section on Container types in part 4 of the Modulo.js interactive tutorial. Next, we need to put the points back into our SVG. We can use the |join:' ' filter to combine the points with spaces:

<path id="curve" fill="transparent" d="M 10,50 C {{ state.points|join:' ' }}" /> <text><textPath href="#curve">{{ state.text }}</textPath></text> 
Enter fullscreen mode Exit fullscreen mode

Creating a hard-coded, rotated range input

At this point, we have moved the points into the State variable, but we still don't have range sliders for them! Let's do that next. We'll use a “for-loop” for this, so we can repeat the same range-slider code for every point in our point Array. But before we do that, let's start with a “hardcoded” range-slider, which will only control “Point #2”, just to make sure we can at least control one of them successfully:

<label style="display: inline-block; width: 5%">   <strong>2</strong>   <input [state.bind] name="points.2.1"       style="position: relative; transform: rotate(90deg); left: -60px; top: 60px"       type="range" max="100" min="0" /> </label> 
Enter fullscreen mode Exit fullscreen mode

Let's decipher this: The label and input have style= attributes to space it by 5% width of the page, rotate the input 90 degrees, and move it 60×60 pixels. The name="points.2.1" (equivalent to points[2][1] in other languages) causes the input to control one specific value in the State variable.

Duplicating the input with a for-loop

We've successfully gotten an input to work with a single point (points.2). We could copy and paste this name="points.2.1" code 6 times (once for each point), altering each copy to name="points.3.1", name="points.4.1" etc. This would allow us to control every point. Or, we could save ourselves time, and use the Modulo Template for loop. Let's see how that looks:

{% for index, point in state.points %}     {# ... #} <strong>{{ index }}</strong>     <input [state.bind] name="points.{{ index }}.1" {# ... #} {% endfor %} 
Enter fullscreen mode Exit fullscreen mode

Note the only difference here is the 2 is replaced with {{ index }} — the “index” of the current point we are looping through.

<x-CurvedTextArtTool> – Embeddable results

Add the range smooth-rendering ="input" tweak, explained in this tutorial, and we get the following results. Hope you enjoy this tutorial — follow for more like this!

<!DOCTYPE html> <template Modulo>   <Component name="CurvedTextArtTool">     <Template>       <section>         <p><input [state.bind] name="text" title="Text" maxlength="15" /></p>         {% for index, point in state.points %}           <label style="display: inline-block; width: 5%">             <strong>{{ index }}</strong>             <input [state.bind]="input" name="points.{{ index }}.1"                 style="position: relative; transform: rotate(90deg); left: -60px; top: 60px"                 type="range" max="100" min="0" />           </label>         {% endfor %}       </section>       <svg viewBox="0 0 200 100" style="width: 55%; margin-top: 100px">           <path id="curve" fill="transparent" d="M 10,50 C {{ state.points|join:' ' }}" />           <text><textPath href="#curve">{{ state.text }}</textPath></text>       </svg>     </Template>     <State         text="Modulo Text FX!"         points:='[ [ 20,40 ], [40,10], [60,40], [80,70], [100,65], [120,90] ]'     ></State>   </Component> </template> <script src="https://unpkg.com/mdu.js"></script> <x-CurvedTextArtTool></x-CurvedTextArtTool> 
Enter fullscreen mode Exit fullscreen mode

javascriptprogrammingtutorialwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.