How-To Draw lines using tilt

howtos

#1

This is how to create a simple but interesting project that lets you draw a line by tilting your device in the direction you want to draw. There is only one piece of coding/rules that go into this so it is quite simple! You can change this code so it might draw the line in different colours, tilting or button controls etc.

  1. Start with adding a character or object to the project and set the invisibility of the object to 100. Add a rule for when the project is started, and then a repeat forever block. Once you have added the repeat forever block, add a Set Speed to block, and set to 1000 (or your choice of how fast you want your line to move/draw).

What this is going to do so far is that when the project is started (play button pressed), the object will repeat the set speed to 1000 block forever.


2.
Now we are going to get into choosing the colour, width and how far it moves forward. Start by adding the Leave a Trail block into the repeat forever block. This goes in after the set speed block, but won't matter which order it is in. Set the colour of your block and the width you would like your line to be (I have mine set to random colour and a width of 10, so it will randomly change colour while I am tilting/drawing the line). Set the move forward block to 10 (or how much you want the line to draw before it changes its direction when you tilt your device).

3. Last part of this rule (Yay!), and also the trickiest. We are now going to add the tilting code so when you tilt your device, the line will draw in the direction that you are tilting in. Start by adding the block 'Set angle from bottom of device in degrees', which is under the movement catagory. Now tap on the empty section, and add the ___ + ___ purple block. With this you will want to start of with adding the tilt left % value, which is under 'iPad'. Then add the number 1 to the end. So it should look like 'Set angle from bottom of device in degrees tilt left % + 1'. Now add the block 'change X by', and enter the division purple box. Add the tilt right % value and divide that by 1.
Now do the exact same thing for the change Y by block, but instead of the tilt right % value, it is the tilt up % one.
This will make the line move (the invisible object) move in the direction you are tilting.

4. Whew, that was a tricky but simple code. Now press play and if you have followed the instructions correctly (or the pictures), the line should draw in the direction you are tilting your device in. Maybe you could change the move forward to something small, or how much the tilt % is divided by.

  • ColeDJ/BestesColesNZ

#2

Awesome tip! This is a really helpful explanation—I love the screenshots and annotations :grin:


#3

This is so cool and so easy to read nice work! :grinning:


#4

hello! (this topic is so old)


#5

Stop, please. I don't know why you'd go to old topics just to do this...


#6

cuz I want to bring back old topics to life!!!!
@CreativeCoder


#7

Yes, but it's not really helping at all.


#8

oh.