Cloning new circles in random places


#1

HI,

I'm looking to draw random circles on different parts of the page/screen. I know how to use to sine/cosine to draw a circle, but am stuck making the circles appear randomly in different areas of the screen.

On top of this, it would be even better if these circles were different sizes.

Any suggestions appreciated

Thanks

Moonster01


#2

Make a clone (however many you want) and set the position random 0-1024 x position and 0-768 Y position on the 'object is cloned' block. And you can use a set size block, saying the size random _ to _ .Hope it helps!


#3

It means that it'll be all random


#4

Make this:
When game starts
Repeat times (however many you want)
Create a Clone of this Object
When object is cloned
Set Position X random 0 to 1024 Y random 0 to 768.
Hope this helps! :slight_smile:
@moonster01


#5

Also, welcome to the forum!


#6

Thank you for your fast reply.

When I use the Sine/cosine function to draw a circle, I 'set position' and 'draw a trail'. If I "set position' on the x and y before a making the circle, the following sine/cosine 'set position' overrides the original position. I have tried inputting a random x and y 'set position' in the sine/cosine function, but this does't work.

Does this make sense??


#7

http://www.tynker.com/ide/?p=57de6f6351684f58488b4570

Copy this code to hopscotch.
ignore the pen up/pen down code.
use leave a trail when th code is pen down


#8

Thank you. I'll give it a go and let know how I go.

Much appreciated!


#9

You don't need to put CoSine in this :wink:


#10

I would've just guessed:

When game starts:

Repeat times ___ :

Create a clone

When object is cloned:

Repeat 360:

Move Forward 1
turn 1


#11

Yes, that makes sense & is because the math in the Cosine/Sine block tell Hopscotch not only to draw a circle but where to draw the circle

Consider a standard Set Position with Cosine & Sine blocks dropped in (looping the Angle from 0 to 360). This is what it means:


So the "X Center" & "Y Center" override any previous position

Of course, as others have said, inside the Draw a Trail block Move Forward 1 will create a circle of the Draw Width. The different being that the cosine/sine method can draw the outline of a circle (depending on the Draw Width) while Move Forward will draw a filled circle.

Having said all that, instead of a background if you want the circles to move, you'll need to use text objects (unicode has an outlined circle).


#13

https://c.gethopscotch.com/p/y8xeumx61

Here is a simple solution without using cos/sine.

I sometimes forget others here can't convert code blocks from Tynker to Hopscotch.

I could have used cos/sine but I'm too tired to think at the moment.