Discuss Scratch

Altion
Scratcher
100+ posts

Square Pen

I'm making a pixel art creator and I need to draw square 20x20. However, I don't want a rounded square. For reasons, I cannot use the color effect or costumes. What is a quick and efficient way to draw a square with sharp edges?

Scratch On
ALTION

Check out my OS COLLAB: https://scratch.mit.edu/projects/171698206/ !!!!
Despicable_Dad
Scratcher
500+ posts

Square Pen

I assume you mean a solid square.

Have a look at my attempt here: https://scratch.mit.edu/projects/142321002/

It's more complicated that it should in theory be :-/
The basic idea was to draw a 20x20 square with a line thickness of 1, then shift up and across by 1 pixel and draw another square 2 pixels smaller than the first one. And so on, to the middle.

Unfortunately, Scratch wasn't playing fair and always left a fine pale diagonal line unshaded. So the bottom bit *under* the repeat loop is just a brute force way of covering up that anomaly.

Hope this helps.

P.S. It's fast enough to use for your project, I think. This version https://scratch.mit.edu/projects/142321708/ timed it at under 1.5 seconds to draw 1000 squares.

Last edited by Despicable_Dad (Jan. 28, 2017 04:45:44)





I'm a Scratch Wiki contributor, and always keen to know which bits of the wiki are unclear. If I can, I'll try to improve things; otherwise, I'll make sure it's brought to the attention of someone who actually knows what they're talking about.
if <not <touching color [#3d4fe4] ?>> then
return true anyway cos computers are vague, innit
change [scratchFoibles v] by (1)
end
if <[a] = [A]> then
think [What???]
change [scratchFoibles v] by (1)
end



Altion
Scratcher
100+ posts

Square Pen

Despicable_Dad wrote:

I assume you mean a solid square.

Have a look at my attempt here: https://scratch.mit.edu/projects/142321002/

It's more complicated that it should in theory be :-/
The basic idea was to draw a 20x20 square with a line thickness of 1, then shift up and across by 1 pixel and draw another square 2 pixels smaller than the first one. And so on, to the middle.

Unfortunately, Scratch wasn't playing fair and always left a fine pale diagonal line unshaded. So the bottom bit *under* the repeat loop is just a brute force way of covering up that anomaly.

Hope this helps.

P.S. It's fast enough to use for your project, I think. This version https://scratch.mit.edu/projects/142321708/ timed it at under 1.5 seconds to draw 1000 squares.
Thanks! I just saw this and I attempted this. https://scratch.mit.edu/projects/142364346/ where it draws it down one row and then goes back. I'm about to see which one is faster.

Scratch On
ALTION

Check out my OS COLLAB: https://scratch.mit.edu/projects/171698206/ !!!!
dvargasews
Scratcher
500+ posts

Square Pen

Try this:
define Draw square with side length (length) around origin with roundedness (pensize)
pen up
set pen size to (pensize)
go to x: (length) y: (length)
pen down
go to x: ((0)-(length)) y: (length)
go to x: ((0)-(length)) y: ((0)-(length))
go to x: (length) y: ((0)-(length))
go to x: (length) y: (length)
pen up
if <((8)*((length)*(length))) > (pensize)> then
Draw square with side length ((length)-(([sqrt v] of (pensize))/(2))) around origin with roundedness ((4)*(pensize))
end
This is what you would need to use for a 20×20 square:
Draw square with side length (20) around origin with roundedness (1)::custom//The roundedness is the size of a pixel and therefore not noticeable.

Please read my signature! It might explain some lingo that I used in my post or comment. However, not all of it shows, so you have to highlight the entire bottom of the post, from “Please read my signature!” to where it says report, and copy and paste in into a new sheet or tab or whatever.
I can't decide my signature between:
1. I'm a grammar stickler, and my pet peeve is when people use good as an adverb.
2. I have lots of [creativity]original ideas[/creativity]. [creativity]This[/creativity] is one of those ideas.
3. If I used this symbol: ⸮ in my comment, please look it up before doing anything else.
4. {Minot, North Dakota/Donald Trump parodies} “WE'RE GONNA BUILD A DAM AND MAKE CANADA PAY FOR IT!” “When Canada sends its water, they’re not sending their best drinking water…They’re bringing sleet. They’re bringing floods. The water's toxic.” (It's just a joke that I came up with.)
5. One should make his/her signature text small; that way (s)he can cram more text into the signature.
6. New [scratchblocks] idea each week! (Thanks to Bright-Idea (Read her signature.) for inspiration/the general idea.) Here's the archive:
Note: I stopped this because of signature character limits.
Week of 1-23-2017: Hat-caps tinyurl.com/htauyu2
Week of 1-16-2017: Country-colored scratchblocks tinyurl.com/z8lz6c4
Week of 1-9-2017: Drop-down booleans tinyurl.com/j5d3k6l
Week of 1-2-2017: Block->string inputs and more truth values tinyurl.com/jqu7avs

Th3_C0d3r
Scratcher
100+ posts

Square Pen

Here's my take on it —> https://scratch.mit.edu/projects/142305870/#editor

-Scratch On!

define Help
repeat until <Universe ends>
if <<(Answer) = (Truth)> and <I get it>> then
broadcast [Thank helper v]
set [Mood v] to (Happy)
else
broadcast [Send more help v]
Ed4S_Keller
Scratcher
3 posts

Square Pen

Ed4S_Keller wrote:

Try this:
define Draw square with side length (length) around origin with roundedness (pensize)
pen up
set pen size to (pensize)
go to x: (length) y: (length)
pen down
go to x: ((0)-(length)) y: (length)
go to x: ((0)-(length)) y: ((0)-(length))
go to x: (length) y: ((0)-(length))
go to x: (length) y: (length)
pen up
if <((8)*((length)*(length))) > (pensize)> then
Draw square with side length ((length)-(([sqrt v] of (pensize))/(2))) around origin with roundedness ((4)*(pensize))
end
This is what you would need to use for a 20×20 square:

Last edited by Ed4S_Keller (Aug. 20, 2018 08:08:37)

deck26
Scratcher
1000+ posts

Square Pen

Ed4S_Keller wrote:

dvargasews wrote:

Try this:
define Draw square with side length (length) around origin with roundedness (pensize)
pen up
set pen size to (pensize)
go to x: (length) y: (length)
pen down
go to x: ((0)-(length)) y: (length)
go to x: ((0)-(length)) y: ((0)-(length))
go to x: (length) y: ((0)-(length))
go to x: (length) y: (length)
pen up
if <((8)*((length)*(length))) > (pensize)> then
Draw square with side length ((length)-(([sqrt v] of (pensize))/(2))) around origin with roundedness ((4)*(pensize))
end
This is what you would need to use for a 20×20 square:

Please don't necropost. All you've done is copy an earlier post and brought this topic back to the top.

Last edited by deck26 (Aug. 20, 2018 08:46:02)

Ed4S_Keller
Scratcher
3 posts

Square Pen

Ed4S_Keller wrote:

dvargasews wrote:

Try this:
define Draw square with side length (length) around origin with roundedness (pensize)
pen up
set pen size to (pensize)
go to x: (length) y: (length)
pen down
go to x: ((0)-(length)) y: (length)
go to x: ((0)-(length)) y: ((0)-(length))
go to x: (length) y: ((0)-(length))
go to x: (length) y: (length)
pen up
if <((8)*((length)*(length))) > (pensize)> then
Draw square with side length ((length)-(([sqrt v] of (pensize))/(2))) around origin with roundedness ((4)*(pensize))
end
This is what you would need to use for a 20×20 square:
[/quote]
deck26
Scratcher
1000+ posts

Square Pen

@Ed4S_Keller - please stop necroposting

Powered by DjangoBB