Как создать клон Краски MS с Python и pygame

  • первый метод
@auth
    @forelse($quote->userLike as $like)
            @if($like->pivot->user_id == $id) //passing user  id from controller here
            <li class="list-inline-item">
                <form  method="POST" action="{{route('likequote')}}" class="likequote">
                    @csrf
                    <input type="hidden" class="form-control col-md-4" name="likequote" id="likequote" value='{{$quote->id}}'>
                    <button type="submit" class="btn btn-danger shadow-lg " id="savelike"><i class="fas fa-heart"></button></i>
                </form>
            </li>
            @endif
    @empty
    <li class="list-inline-item">
        <form  method="POST" action="{{route('likequote')}}" class="likequote">
            @csrf
            <input type="hidden" class="form-control col-md-4" name="likequote" id="likequote" value='{{$quote->id}}'>
            <button type="submit" class="btn btn-primary shadow-lg " id="savelike"><i class="fas fa-heart"></button></i>
        </form>
    </li>
    @endforelse
@endauth
  • второй
@auth
    @if(!empty($quote->userLike) && count($quote->userLike)>0)
        @foreach($quote->userLike as $like)
            @if($like->pivot->user_id == $id) //passing user  id from controller here
            <li class="list-inline-item">
                <form  method="POST" action="{{route('likequote')}}" class="likequote">
                    @csrf
                    <input type="hidden" class="form-control col-md-4" name="likequote" id="likequote" value='{{$quote->id}}'>
                    <button type="submit" class="btn btn-danger shadow-lg " id="savelike"><i class="fas fa-heart"></button></i>
                </form>
            </li>
            @endif
        @endforeach 
    @else
    <li class="list-inline-item">
        <form  method="POST" action="{{route('likequote')}}" class="likequote">
            @csrf
            <input type="hidden" class="form-control col-md-4" name="likequote" id="likequote" value='{{$quote->id}}'>
            <button type="submit" class="btn btn-primary shadow-lg " id="savelike"><i class="fas fa-heart"></button></i>
        </form>
    </li>
    @endif  
@endauth
12
задан Emre Erkan 7 December 2011 в 23:44
поделиться

1 ответ

Почему бы не оба?

Нарисуйте круг в каждой конечной точке и строке между двумя.

ОТРЕДАКТИРУЙТЕ rofl, просто не мог остановить меня.

На самом деле Вы не хотите использовать pygame.draw.line потому что это обманывает. Это заполняет строку 1 пиксель шириной или столбец (в зависимости от угла атаки) пикселей. Если Вы действительно идете под примерно перпендикулярным углом, 0 градусов или 90 градусов, это не проблема, но в 45, Вы заметите своего рода эффект стручковой фасоли.

Единственное решение состоит в том, чтобы нарисовать круг на расстоянии каждого пикселя. Здесь...

import pygame, random

screen = pygame.display.set_mode((800,600))

draw_on = False
last_pos = (0, 0)
color = (255, 128, 0)
radius = 10

def roundline(srf, color, start, end, radius=1):
    dx = end[0]-start[0]
    dy = end[1]-start[1]
    distance = max(abs(dx), abs(dy))
    for i in range(distance):
        x = int( start[0]+float(i)/distance*dx)
        y = int( start[1]+float(i)/distance*dy)
        pygame.draw.circle(srf, color, (x, y), radius)

try:
    while True:
        e = pygame.event.wait()
        if e.type == pygame.QUIT:
            raise StopIteration
        if e.type == pygame.MOUSEBUTTONDOWN:
            color = (random.randrange(256), random.randrange(256), random.randrange(256))
            pygame.draw.circle(screen, color, e.pos, radius)
            draw_on = True
        if e.type == pygame.MOUSEBUTTONUP:
            draw_on = False
        if e.type == pygame.MOUSEMOTION:
            if draw_on:
                pygame.draw.circle(screen, color, e.pos, radius)
                roundline(screen, color, e.pos, last_pos,  radius)
            last_pos = e.pos
        pygame.display.flip()

except StopIteration:
    pass

pygame.quit()
15
ответ дан 2 December 2019 в 07:22
поделиться
Другие вопросы по тегам:

Похожие вопросы: