Spraycan Paint Script, surfaces! |
![]() ![]() |
Spraycan Paint Script, surfaces! |
Nov 6 2009, 12:07 PM
Post
#1
|
|
|
GMC Member Group: GMC Member Posts: 180 Joined: 29-July 08 Member No.: 111762 |
Spaycans basically lay down random pixels around the mouse cursor, so that is what YOU do!
Then make a script and call it scr_getrandom and give it this code: CODE length = random(10)//10 is the range, it is in beween this range dir = random(360)//the degrees (up to 360) posx = mouse_x+lengthdir_x(length,dir)//get the position posy = mouse_y+lengthdir_y(length,dir)//get the position Nice! This will make a random dot around the mouse with a range of 10! make an object called obj_spraycan in the create event put: CODE posx=mouse_x//starting x posy=mouse_y//starting y surface = surface_create(window_get_width(),window_get_height())//create the surface surface_set_target(surface)//make sure we are drawing ON the surface and in the step event put: CODE if mouse_check_button(mb_left) { surface_set_target(surface); repeat (2) { scr_getrandom();//get a random position IN A CIRCLE (see the script, thanks to Prenn Saranda) draw_point(posx,posy);//draw the point surface_reset_target();//resetting } } else { surface_reset_target();//reset it } and in the draw event put: CODE draw_surface(surface,0,0); This will create a lovely rich spray around the mouse! You can use any colour, and any range (change the range in the script, first line). I hope this helps people xD EDIT: Oh yes and put obj_spraycan in a room with a white bg ;D This post has been edited by Sonica2: Yesterday, 12:56 PM |
|
|
|
Nov 6 2009, 12:17 PM
Post
#2
|
|
|
GMC Member Group: GMC Member Posts: 180 Joined: 29-July 08 Member No.: 111762 |
I will make it much faster, I just realised it uses millions of instances.
This post has been edited by Sonica2: Nov 20 2009, 08:48 AM |
|
|
|
Nov 6 2009, 12:28 PM
Post
#3
|
|
|
Quite Epic Group: GMC Member Posts: 889 Joined: 5-May 08 From: Ua (eu) Member No.: 106350 |
I would replace the content of first code with repeat(n).
|
|
|
|
Nov 6 2009, 12:30 PM
Post
#4
|
|
|
GMC Member Group: GMC Member Posts: 397 Joined: 2-June 09 From: Australia Member No.: 134268 |
Definitely not efficient. However it is a good place to start.
Another way of accomplishing this which you may find useful. Is to store the x and y coordinates of the spray image in an array. You can then loop through the array and draw them all. That makes it much faster. You can find an example of what I'm talking about here: Download This example uses lines instead, but the key concepts are the same. |
|
|
|
Nov 6 2009, 12:35 PM
Post
#5
|
|
|
Quite Epic Group: GMC Member Posts: 889 Joined: 5-May 08 From: Ua (eu) Member No.: 106350 |
Definitely not efficient. However it is a good place to start. Another way of accomplishing this which you may find useful. Is to store the x and y coordinates of the spray image in an array. You can then loop through the array and draw them all. That makes it much faster. You can find an example of what I'm talking about here: Download This example uses lines instead, but the key concepts are the same. calling draw_point function 480000 times is not a smart plan too, in my opinion. |
|
|
|
Nov 6 2009, 12:48 PM
Post
#6
|
|
|
GMC Member Group: GMC Member Posts: 180 Joined: 29-July 08 Member No.: 111762 |
The more I think about it, the more I think not to keep this topic.....
|
|
|
|
Nov 6 2009, 10:34 PM
Post
#7
|
|
|
Long Live the Sun Group: GMC Member Posts: 43 Joined: 8-January 09 Member No.: 126315 |
Holy !^%*.
CODE // arg0: volume
// arg1: radius repeat argument0 draw_point(mouse_x+random(2*argument1)-argument1,mouse_y+random(2*argument1)-argument1); This post has been edited by LumiéreDuSoleil: Nov 6 2009, 10:37 PM |
|
|
|
Nov 6 2009, 11:40 PM
Post
#8
|
|
|
GMC Member Group: GMC Member Posts: 397 Joined: 2-June 09 From: Australia Member No.: 134268 |
QUOTE calling draw_point function 480000 times is not a smart plan too, in my opinion. It's not that smart, draw_point() is rather slow which is why I suggested he use a sprite and draw it through a loop. Basically anything is faster at this point as there is a large amount of instances and each of them is calling draw_point() which is combining 2 slow methods. This is much slower than either instances with 1x1 sprites (Supports around 11,000 instances on my system) or a drawing loop with draw_point() which supports 6,000 instances on my system.So at this point, mostly anything is an improvement. The more I think about it, the more I think not to keep this topic..... That is not the attitude to have. You should use these ideas to try and make simple yet more efficient example. It will not only improve your skills but may also prove to be useful to the community This post has been edited by Sven: Nov 6 2009, 11:41 PM |
|
|
|
Nov 7 2009, 06:25 AM
Post
#9
|
|
|
GMC Member Group: GMC Member Posts: 1088 Joined: 28-October 06 From: Behind you Member No.: 62579 |
The more I think about it, the more I think not to keep this topic..... That is not the attitude to have. You should use these ideas to try and make simple yet more efficient example. It will not only improve your skills but may also prove to be useful to the community I agree. If anything, this can be useful for something like blood spatter, or a brief moment of confetti. The randomness will make the graphics less monotonous. |
|
|
|
Nov 7 2009, 09:09 AM
Post
#10
|
|
|
GMC Member Group: GMC Member Posts: 180 Joined: 29-July 08 Member No.: 111762 |
Ok people! I am creating better example, so wait fr a bit>>>>
|
|
|
|
Nov 7 2009, 02:50 PM
Post
#11
|
|
|
GMC Member Group: GMC Member Posts: 246 Joined: 1-April 09 Member No.: 130859 |
Why don't we just use surfaces and do something like this:
CODE draw_point(mouse_x+choose(random(-10),random(10)),mouse_y+choose(random(-10),random(10))); It doesn't have to be in the draw event since we're using a surface =D This post has been edited by NYS: Nov 7 2009, 02:51 PM |
|
|
|
Nov 8 2009, 12:36 PM
Post
#12
|
|
|
GMC Member Group: GMC Member Posts: 637 Joined: 12-July 07 From: Denmark, Tåsinge Member No.: 83371 |
Hey, I have another thing to add to this topic
if the position is chosen with: CODE posx = mouse_x+random(r)-(2r) (or posx = mouse_x+choose(random(-r),random(r))) Like it is done in this topic, the spraycan will spray squared. To change this, use something like:posy = mouse_y+random(r)-(2r) (or posy = mouse_y+choose(random(-r),random(r))) (were r should be the max radius) CODE length = random(r) This will make it spray in a circle instead dir = random(360) posx = mouse_x+lengthdir_x(length,dir) posy = mouse_y+lengthdir_y(length,dir) Of course, if you want it to be squared, or I am wrong, ignore my post |
|
|
|
Nov 17 2009, 04:39 PM
Post
#13
|
|
|
GMC Member Group: GMC Member Posts: 180 Joined: 29-July 08 Member No.: 111762 |
No, circle is good
|
|
|
|
Nov 19 2009, 04:56 PM
Post
#14
|
|
|
GMC Member Group: GMC Member Posts: 180 Joined: 29-July 08 Member No.: 111762 |
NEW EXAMPLE!
This post has been edited by Sonica2: Nov 19 2009, 05:33 PM |
|
|
|
Yesterday, 12:10 PM
Post
#15
|
|
|
GMC Member Group: GMC Member Posts: 180 Joined: 29-July 08 Member No.: 111762 |
Please People! It uses surfaces now!
|
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 22nd November 2009 - 01:20 PM |