Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. Knowledge Base
  3. Tutorials
  4. 3D - A Carpet (Difficulty: 2)

3D - A Carpet (Difficulty: 2)

Scheduled Pinned Locked Moved Tutorials
1 Posts 1 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CreatiCodeI Offline
    CreatiCodeI Offline
    CreatiCode
    wrote on last edited by admin
    #1

     

    Key Topics Covered

    • Initializing 3D scenes
    • Updating textures
    • Using cylinders
    • Updating scale
    • Updating color
    • The “z-fighting” problem

     
     

    Introduction

    In this tutorial, we’ll build a carpet. Here is a preview:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/882c5a4d-f696-4895-9b5f-68a80c71d6ac.gif" width="440" style="border-radius: 5px; border: 1px solid #29622d;">

     
     

    Step 1 - An “Empty” Scene with 3D Axes

    Please create a new project, remove the dog sprite, and add these blocks in the “Empty1” sprite. You can find the “initialize 3D scene” and the “show 3D axis” blocks in the “3D Scene” category.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/43a6f24e-b195-4762-a219-822a46559d96.png" width="400" style="filter: drop-shadow(0.35rem 0.35rem 0.4rem rgba(0, 0, 0, 0.5));">
     
    As shown, the X-axis points to the right, the Y-axis points forward (into the screen), and the Z-axis points up. You can drag your mouse on the stage to rotate the camera around it:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/dcebc38b-cc87-4eb8-a3f1-6252211315eb.gif" width="460" style="border-radius: 5px; border: 1px solid #29622d;">

     
     

    Step 2 - Add A Cylinder

    Our carpet will be round-shaped, so let’s add a very thin cylinder. You can pick any color or size you like:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/118fddc1-bd97-4efb-9e09-6ca75664bb98.png" width="1000" style="">
     
    Now you should get a round carpet like this:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/757e9ef4-a588-4d78-8944-1068bd9cd875.gif" width="460" style="border-radius: 5px; border: 1px solid #29622d;">

     
     

    Step 3 - Increase the number of “sides”

    You have probably noticed that the edge of the cylinder is not very smooth. This is because we only use 32 side faces, so we can see the edges between them when we zoom in.

    To improve the result, we can increase the number of sides to a larger number, such as 128.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/ce703ab7-fde6-4880-adc1-d01477ca3abe.png" width="1000" style="">
     
    Now the cylinder’s edge looks much smoother:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/a8e12c91-837d-4283-8e1d-61713a9b0931.gif" width="480" style="border-radius: 5px; border: 1px solid #29622d;">

     
     

    Step 4 - Scale the cylinder in the X dimension

    Now we need to change our carpet to an oval shape. We can use the “update scale” block to stretch the cylinder to 150% of its current size along the X dimension.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/5179bbe4-4a60-4f36-a664-0410f09cec98.png" width="600" style="">
     
    Now we get an oval carpet:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/00b2b53e-abc1-4bad-9350-3567ab8e47ef.gif" width="450" style="border-radius: 5px; border: 1px solid #29622d;">

     
     

    Step 5 - Update the Texture

    Our carpet looks like something made of plastic. To give it a more realistic look, we need to update its texture. You can use the “Carpet” texture, or try some other texture you like.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/55da57fe-f0a7-4bb5-b7c1-6e0c5acd2343.png" width="800" style="filter: drop-shadow(0.35rem 0.35rem 0.4rem rgba(0, 0, 0, 0.5));">
     
    Now the carpet looks like a real one:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/7252a5ed-91dc-438c-a2fd-03ffb6926178.gif" width="480" style="border-radius: 5px; border: 1px solid #29622d;">

     
     

    Step 6 - Update the Color

    We lost the original color of the cylinder when we add a texture to it. To get the color back, we can use the “update color” block:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/99378510-741e-4282-aa20-cc3fd823b569.png" width="1000" style="border-radius: 5px; border: 1px solid #29622d;">
     
    This change will give us a colored carpet:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/08b4b0bc-1cb0-46c9-bbeb-1c99f833385f.gif" width="1000" style="border-radius: 5px; border: 1px solid #29622d;">

     
     

    Step 7 - A Second Layer

    Next, let’s add a smaller cylinder with a different color. You can right-click to duplicate the 4 blocks used for the first part, and then change the size and color of it:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/57c90f55-cf68-4b93-86d9-8eaeb11e563e.gif" width="1000" style="border-radius: 5px; border: 1px solid #29622d;">

     
     

    Step 8 - Fix the display issue

    There is a minor issue with our carpet. The inner cylinder does not display clearly. This is because the top faces of the 2 cylinders are overlapping, so the 3D engine tries to show both cylinders at the same time. In case you are curious, this is called the “z-fighting” problem.

    An easy fix is to make the inner cylinder slightly thicker, so that its top face covers the outer cylinder. For example, a height of 4.5 would be enough, and most people would not notice the difference unless they look really closely.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/71dee997-2f1a-4262-ad08-9e5757c46685.gif" width="1000" style="border-radius: 5px; border: 1px solid #29622d;">

     
     

    Step 9 - The “add layer” block

    Before we add more layers to our carpet, it is a good time to “refactor” our program to avoid duplicate blocks.

    As you can observe, there is a clear pattern that every layer would take the same set of 4 blocks, and we need to set different sizes and colors for them. So we can start by making a new block called “add layer”, and make it accept 3 inputs of “size”, “height” and “color”:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/25ca1e07-d34b-4b51-8f2a-981cc144e186.gif" width="1000" style="border-radius: 5px; border: 1px solid #29622d;">
     
    Next, we can move the 4 blocks for one layer into this new block’s definition, and then drag the 3 input blocks to the correct place.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/903e0391-3b05-4012-98ac-cfb6cad8ac45.gif" width="1000" style="border-radius: 5px; border: 1px solid #29622d;">
     
    Lastly, we can start to use this new block to add the 2 layers. Note that for the “color” input, we need to use the color block, which allows you to set the color value using numbers (instead of sliders).

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/08ab2483-6e28-4e9e-8132-6edb6a465cb8.gif" width="1000" style="border-radius: 5px; border: 1px solid #29622d;">

     
     

    Step 10 - Add a Third Layer

    With the new “add layer” block we have made, it is very easy to add another layer that’s smaller and thicker:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/4c010340-2e7a-40ef-8e1e-e80183a3cd99.gif" width="1000" style="border-radius: 5px; border: 1px solid #29622d;">

     
     

    Step 11 - Change the Texture

    It is also very easy to change the carpet. We only need to change the blocks in the “add layer” stack. For example, here is how to create a carpet made of floor tiles.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/1ebc7268-50fb-4ff7-9809-4280d87500f9.gif" width="1000" style="border-radius: 5px; border: 1px solid #29622d;">

     

    Here is the complete program for your reference:

    db252707-85d3-46b8-84a1-865f6fb9811c-image.png

     
     

    Creative Ideas

    There are many ways you can enhance this carpet project. Here are some ideas for your inspiration:

    1. Other Shapes: other shapes can be used for the carpet as well, such as spheres, capsules and tubes.

    2. More layers: you can add many more layers to the carpet, using a repeat-loop or a for-loop.

    3. Pyramid: when you stack many layers of boxes, you will get a pyramid shape.

    1 Reply Last reply
    0
    • CreatiCodeI CreatiCode pinned this topic on

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode